All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Kan Liang <kan.liang@intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 06/19] perf diff: Support for different binaries
Date: Fri, 27 Feb 2015 16:22:56 -0300	[thread overview]
Message-ID: <1425064989-26440-7-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1425064989-26440-1-git-send-email-acme@kernel.org>

From: Kan Liang <kan.liang@intel.com>

Currently, the perf diff only works with same binaries. That's because
it compares the symbol start address. It doesn't work if the perf.data
comes from different binaries. This patch matches the symbol names.

Actually, perf diff once intended to compare the symbol names.  The
commit as below can look for a pair by name.

604c5c92972d (perf diff: Change the default sort order to "dso,symbol")
However, at that time, perf diff used a global list of dsos. That means
the binaries which has same name can only be loaded once. That's a
problem for comparing different binaries.

For example, we have an old binary and an updated binary. They very
likely have same name and most of the functions, so only dsos from old
binary will be loaded. When processing the data from updated binary,
perf still use the symbol information from old binary. That's wrong.

Then the commit as below used IP to replace symbol name.
9c443dfdd31e ("perf diff: Fix support for all --sort combinations")
>From that time, perf diff starts to compare the symbol address.

The global dsos is discarded from a patch in 2010.
a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance
from host")
However, at that time, perf diff already compared by address. So perf
diff cannot work for different binaries as well.

This patch actually rolls back the perf diff to original design. The
document is also changed, so everybody knows the original design is to
compare the symbol names.

Here are some examples:

The only difference between example_v1.c and example_v2.c is the
location of f2 and f3. There is no change in behavior, but the previous
perf diff display the wrong differential profile.

example_v1.c
noinline void f3(void)
{
        volatile int i;
        for (i = 0; i < 10000;) {

                if(i%2)
                        i++;
                else
                        i++;
        }
}

noinline void f2(void)
{
        volatile int a = 100, b, c;
        for (b = 0; b < 10000; b++)
                c = a * b;

}

noinline void f1(void)
{
                f2();
                f3();
}

int main()
{
        int i;
        for (i = 0; i < 100000; i++)
                f1();
}

example_v2.c
noinline void f2(void)
{
        volatile int a = 100, b, c;
        for (b = 0; b < 10000; b++)
                c = a * b;
}

noinline void f3(void)
{
        volatile int i;
        for (i = 0; i < 10000;) {
                if(i%2)
                        i++;
                else
                        i++;
        }
}

noinline void f1(void)
{
                f2();
                f3();
}

int main()
{
        int i;
        for (i = 0; i < 100000; i++)
                f1();
}

[lk@localhost perf_diff]$ gcc example_v1.c -o example
[lk@localhost perf_diff]$ perf record -o example_v1.data ./example
[ perf record: Woken up 4 times to write data ]
[ perf record: Captured and wrote 0.813 MB example_v1.data (~35522 samples) ]

[lk@localhost perf_diff]$ gcc example_v2.c -o example
[lk@localhost perf_diff]$ perf record -o example_v2.data ./example
[ perf record: Woken up 4 times to write data ]
[ perf record: Captured and wrote 0.824 MB example_v2.data (~36015 samples) ]

Old perf diff result:

[lk@localhost perf_diff]$ perf diff example_v1.data example_v2.data
 Event 'cycles'
 Baseline    Delta  Shared Object     Symbol
 ........  .......  ................  ...............................

                     [kernel.vmlinux]  [k] __perf_event_task_sched_out
     0.00%           [kernel.vmlinux]  [k] apic_timer_interrupt
                     [kernel.vmlinux]  [k] idle_cpu
                     [kernel.vmlinux]  [k] intel_pstate_timer_func
                     [kernel.vmlinux]  [k] native_read_msr_safe
     0.00%           [kernel.vmlinux]  [k] native_read_tsc
     0.00%           [kernel.vmlinux]  [k] native_write_msr_safe
                     [kernel.vmlinux]  [k] ntp_tick_length
     0.00%           [kernel.vmlinux]  [k] rb_erase
     0.00%           [kernel.vmlinux]  [k] tick_sched_timer
     0.00%           [kernel.vmlinux]  [k] unmap_single_vma
     0.00%           [kernel.vmlinux]  [k] update_wall_time
     0.00%           example           [.] f1
    46.24%           example           [.] f2
    53.71%   -7.55%  example           [.] f3
            +53.81%  example           [.] f3
     0.02%           example           [.] main

New perf diff result:

[lk@localhost perf_diff]$ perf diff example_v1.data example_v2.data
                     [kernel.vmlinux]  [k] __perf_event_task_sched_out
     0.00%           [kernel.vmlinux]  [k] apic_timer_interrupt
                     [kernel.vmlinux]  [k] idle_cpu
                     [kernel.vmlinux]  [k] intel_pstate_timer_func
                     [kernel.vmlinux]  [k] native_read_msr_safe
     0.00%           [kernel.vmlinux]  [k] native_read_tsc
     0.00%           [kernel.vmlinux]  [k] native_write_msr_safe
                     [kernel.vmlinux]  [k] ntp_tick_length
     0.00%           [kernel.vmlinux]  [k] rb_erase
     0.00%           [kernel.vmlinux]  [k] tick_sched_timer
     0.00%           [kernel.vmlinux]  [k] unmap_single_vma
     0.00%           [kernel.vmlinux]  [k] update_wall_time
     0.00%           example           [.] f1
    46.24%   -0.08%  example           [.] f2
    53.71%   +0.11%  example           [.] f3
     0.02%           example           [.] main

Signed-off-by: Kan Liang <kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1423460384-11645-1-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-diff.txt | 5 +++++
 tools/perf/util/sort.c                 | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/tools/perf/Documentation/perf-diff.txt b/tools/perf/Documentation/perf-diff.txt
index e463caa3eb49..518266192d67 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -20,6 +20,11 @@ If no parameters are passed it will assume perf.data.old and perf.data.
 The differential profile is displayed only for events matching both
 specified perf.data files.
 
+If no parameters are passed the samples will be sorted by dso and symbol.
+As the perf.data files could come from different binaries, the symbols addresses
+could vary. So perf diff is based on the comparison of the files and
+symbols name.
+
 OPTIONS
 -------
 -D::
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 7a39c1ed8d37..4593f36ecc4c 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1463,6 +1463,15 @@ int sort_dimension__add(const char *tok)
 			sort__has_parent = 1;
 		} else if (sd->entry == &sort_sym) {
 			sort__has_sym = 1;
+			/*
+			 * perf diff displays the performance difference amongst
+			 * two or more perf.data files. Those files could come
+			 * from different binaries. So we should not compare
+			 * their ips, but the name of symbol.
+			 */
+			if (sort__mode == SORT_MODE__DIFF)
+				sd->entry->se_collapse = sort__sym_sort;
+
 		} else if (sd->entry == &sort_dso) {
 			sort__has_dso = 1;
 		}
-- 
1.9.3


  parent reply	other threads:[~2015-02-27 19:23 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 19:22 [GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 01/19] perf trace: Fix SIGBUS failures due to misaligned accesses Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 02/19] perf probe: Check kprobes blacklist when adding new events Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 03/19] perf probe: Fix get_real_path to free allocated memory in error path Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 04/19] perf probe: Handle strdup() failure Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 05/19] perf buildid-cache: Add new buildid cache if update target is not cached Arnaldo Carvalho de Melo
2015-02-27 19:22 ` Arnaldo Carvalho de Melo [this message]
2015-02-27 19:22 ` [PATCH 07/19] perf probe: Fix a precedence bug Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 08/19] perf data: Fix sentinel setting for data_cmds array Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 09/19] perf list: Sort the output of 'perf list' to view more clearly Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 10/19] perf list: Allow listing events with 'tracepoint' prefix Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 11/19] perf list: Avoid confusion of perf output and the next command prompt Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 12/19] perf tools: Remove the '--(null)' long_name for --list-opts Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 13/19] perf list: Clean up the printing functions of hardware/software events Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 14/19] perf list: Extend raw-dump to certain kind of events Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 15/19] perf tools: Fix the bash completion problem of 'perf --*' Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 16/19] perf buildid-cache: Add --purge FILE to remove all caches of FILE Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 17/19] perf buildid-cache: Use pr_debug instead of verbose && pr_info Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 18/19] perf buildid-cache: Show usage with incorrect params Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 19/19] perf report: Fix branch stack mode cannot be set Arnaldo Carvalho de Melo
2015-02-28  7:49 ` [PATCH] perf tools: Fix pthread_attr_setaffinity_np() feature detection on Ubuntu systems Ingo Molnar
2015-02-28 22:57   ` Jiri Olsa
2015-03-01 16:11     ` Ingo Molnar
2015-02-28  8:12 ` [PATCH] perf tools: Add PERF-FEATURES to the .gitignore file Ingo Molnar
2015-02-28  8:17   ` [PATCH] perf tools: Remove annoying extra message from the features build Ingo Molnar
2015-03-03  6:24     ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  8:33   ` [PATCH] perf tools: Improve Python feature detection messages Ingo Molnar
2015-03-02 15:10     ` Arnaldo Carvalho de Melo
2015-03-03 13:01       ` Ingo Molnar
2015-03-03  6:24     ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  8:39   ` [PATCH] perf tools: Improve libperl detection message Ingo Molnar
2015-03-03  6:24     ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  8:41   ` [PATCH] perf tools: Improve libbfd " Ingo Molnar
2015-02-28  8:46     ` [PATCH v2] " Ingo Molnar
2015-03-03  6:24       ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  9:16     ` [PATCH] perf tools: Improve feature test debuggability Ingo Molnar
2015-03-03  6:25       ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  9:18   ` [PATCH] perf tools: Improve 'libbabel' feature check failure message Ingo Molnar
2015-03-02 15:19     ` Arnaldo Carvalho de Melo
2015-03-03 13:02       ` Ingo Molnar
2015-03-03  6:25     ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-03-03  6:23   ` [tip:perf/core] perf tools: Add PERF-FEATURES to the .gitignore file tip-bot for Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425064989-26440-7-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.