From patchwork Thu Sep 22 01:09:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 115875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E7E6CB6F83 for ; Thu, 22 Sep 2011 11:10:01 +1000 (EST) Received: (qmail 1548 invoked by alias); 22 Sep 2011 01:09:57 -0000 Received: (qmail 1538 invoked by uid 22791); 22 Sep 2011 01:09:55 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 22 Sep 2011 01:09:41 +0000 Received: from hpaq2.eem.corp.google.com (hpaq2.eem.corp.google.com [172.25.149.2]) by smtp-out.google.com with ESMTP id p8M19d9h022819 for ; Wed, 21 Sep 2011 18:09:40 -0700 Received: from gwaa12 (gwaa12.prod.google.com [10.200.27.12]) by hpaq2.eem.corp.google.com with ESMTP id p8M19XHB013214 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Wed, 21 Sep 2011 18:09:38 -0700 Received: by gwaa12 with SMTP id a12so3343497gwa.28 for ; Wed, 21 Sep 2011 18:09:38 -0700 (PDT) Received: by 10.150.170.10 with SMTP id s10mr1684835ybe.171.1316653778319; Wed, 21 Sep 2011 18:09:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.170.10 with SMTP id s10mr1684830ybe.171.1316653778159; Wed, 21 Sep 2011 18:09:38 -0700 (PDT) Received: by 10.151.41.15 with HTTP; Wed, 21 Sep 2011 18:09:38 -0700 (PDT) Date: Thu, 22 Sep 2011 09:09:38 +0800 Message-ID: Subject: [PATCH]: Dump the "degree of overlap" to compare static profile with instrumentation profile From: Dehao Chen To: gcc-patches@gcc.gnu.org X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello! During performance tuning, it's useful to know if the static profile is accurate. This patch compares static profiles to instrumentation profiles, and uses "degree of overlap" to measure its accuracy. Degree of overlap is a number between 0 and 1, representing the correlation between two profiles, and 1 means two profiles are identical. This number is dumped if the instrumentation based profile is available and -fdump-ipa-profile is specified. Ok for mainline? Thanks, Dehao 2011-09-20 Dehao Chen * profile.c (compute_branch_probabilities): Compute and dump the overlap between the static estimation and the instrumentation profile. (OVERLAP_BASE): New macro. (compute_frequency_overlap): New function Index: gcc/profile.c =================================================================== --- gcc/profile.c (revision 179073) +++ gcc/profile.c (working copy) @@ -437,6 +437,39 @@ read_profile_edge_counts (gcov_type *exe return num_edges; } +#define OVERLAP_BASE 10000 + +/* Compare the static estimated profile to the actual profile, and + return the "degree of overlap" measure between them. + + Degree of overlap is a number between 0 and OVERLAP_BASE. It is + the sum of each basic block's minimum relative weights between + two profiles. And overlap of OVERLAP_BASE means two profiles are + identical. */ + +static int +compute_frequency_overlap (void) +{ + gcov_type count_total = 0, freq_total = 0; + int overlap = 0; + basic_block bb; + + FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb) + { + count_total += bb->count; + freq_total += bb->frequency; + } + + if (count_total == 0 || freq_total == 0) + return 0; + + FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb) + overlap += MIN (bb->count * OVERLAP_BASE / count_total, + bb->frequency * OVERLAP_BASE / freq_total); + + return overlap; +} + /* Compute the branch probabilities for the various branches. Annotate them accordingly. @@ -607,7 +640,13 @@ compute_branch_probabilities (unsigned c } } if (dump_file) - dump_flow_info (dump_file, dump_flags); + { + int overlap = compute_frequency_overlap (); + dump_flow_info (dump_file, dump_flags); + fprintf (dump_file, "Static profile overlap: %d.%d%%\n", + overlap / (OVERLAP_BASE / 100), + overlap % (OVERLAP_BASE / 100)); + } total_num_passes += passes; if (dump_file)