perf header: Pack 'struct perf_session_env'

Initial struct:

[acme@ssdandy linux]$ pahole -C perf_session_env ~/bin/perf
struct perf_session_env {
	char *                     hostname;             /*     0     8 */
	char *                     os_release;           /*     8     8 */
	char *                     version;              /*    16     8 */
	char *                     arch;                 /*    24     8 */
	int                        nr_cpus_online;       /*    32     4 */
	int                        nr_cpus_avail;        /*    36     4 */
	char *                     cpu_desc;             /*    40     8 */
	char *                     cpuid;                /*    48     8 */
	long long unsigned int     total_mem;            /*    56     8 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	int                        nr_cmdline;           /*    64     4 */

	/* XXX 4 bytes hole, try to pack */

	char *                     cmdline;              /*    72     8 */
	int                        nr_sibling_cores;     /*    80     4 */

	/* XXX 4 bytes hole, try to pack */

	char *                     sibling_cores;        /*    88     8 */
	int                        nr_sibling_threads;   /*    96     4 */

	/* XXX 4 bytes hole, try to pack */

	char *                     sibling_threads;      /*   104     8 */
	int                        nr_numa_nodes;        /*   112     4 */

	/* XXX 4 bytes hole, try to pack */

	char *                     numa_nodes;           /*   120     8 */
	/* --- cacheline 2 boundary (128 bytes) --- */
	int                        nr_pmu_mappings;      /*   128     4 */

	/* XXX 4 bytes hole, try to pack */

	char *                     pmu_mappings;         /*   136     8 */
	int                        nr_groups;            /*   144     4 */

	/* size: 152, cachelines: 3, members: 20 */
	/* sum members: 128, holes: 5, sum holes: 20 */
	/* padding: 4 */
	/* last cacheline: 24 bytes */
};
[acme@ssdandy linux]$

[acme@ssdandy linux]$ pahole -C perf_session_env --reorganize --show_reorg_steps ~/bin/perf | grep ^/ | grep -v Final
/* Moving 'nr_sibling_cores' from after 'cmdline' to after 'nr_cmdline' */
/* Moving 'nr_numa_nodes' from after 'sibling_threads' to after 'nr_sibling_threads' */
/* Moving 'nr_groups' from after 'pmu_mappings' to after 'nr_pmu_mappings' */
[acme@ssdandy linux]$

Final struct stats:

[acme@ssdandy linux]$ pahole -C perf_session_env --reorganize --show_reorg_steps ~/bin/perf | tail -4
	/* --- cacheline 2 boundary (128 bytes) --- */

	/* size: 128, cachelines: 2, members: 20 */
};   /* saved 24 bytes and 1 cacheline! */
[acme@ssdandy linux]$

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-3d9tshamloinzxcqeb7mtd1n@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
perf trace: Pack 'struct trace'

Initial struct stats:

	/* size: 368, cachelines: 6, members: 24 */
	/* sum members: 353, holes: 3, sum holes: 15 */
	/* last cacheline: 48 bytes */

After reorg:

[acme@ssdandy linux]$ pahole -C trace ~/bin/trace | tail -4
	/* size: 360, cachelines: 6, members: 24 */
	/* padding: 7 */
	/* last cacheline: 40 bytes */
};
[acme@ssdandy linux]$

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-6jimc80yu89qkx6zb8465s6t@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
perf tools: Insert filtered entries to hists also

Currently if a sample was filtered by command line option, it just
dropped.  But this affects final output in that the percentage can be
different since the filtered entries were not included to the total.

For example, if an original output looked like below:

  $ perf report --stdio -s comm

  # Overhead  Command
  # ........  .......
  #
      74.19%      cc1
       7.61%      gcc
       6.11%       as
       4.35%       sh
       4.14%     make
       1.13%   fixdep

If we gave a filter, the output changed like below:

  $ perf report --stdio -s comm -c gcc,as

  # Overhead  Command
  # ........  .......
  #
      55.49%      gcc
      44.51%       as

But user might want to see this:

  $ perf report --stdio -s comm -c gcc,as

  # Overhead  Command
  # ........  .......
  #
       7.61%      gcc
       6.11%       as

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf tools: Do not update total period of a hists when filtering

When filtering by thread, dso or symbol on TUI it also update total
period so that the output shows different result than no filter - the
percentage changed to relative to filtered entries only.  Sometimes
(always?)  this is not desired since users might expect same results
with filter.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf tools: Remove symbol_conf.use_callchain check

The machine__resolve_callchain() is called only if symbol_conf.
use_callchain is set so no need to check it again.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf tools: Introduce struct hist_entry_iter

There're some duplicate code when adding hist entries.  They are
different in that some have branch info or mem info but generally do
same thing.  So introduce new struct hist_entry_iter and add callbacks
to customize each case in general way.

The new perf_evsel__add_entry() function will look like:

  iter->prepare_entry();
  iter->add_single_entry();

  while (iter->next_entry())
    iter->add_next_entry();

  iter->finish_entry();

This will help further work like the cumulative callchain patchset.

Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf hists: Convert hist entry functions to use struct he_stat

hist_entry__add_cpumode_period() and hist_entry__decay() are dealing
with hist_entry's stat fields only.  So make them use the struct
directly.

Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf hists: Add support for accumulated stat of hist entry

Maintain accumulated stat information in hist_entry->stat_acc if
symbol_conf.cumulate_callchain is set.  Fields in ->stat_acc have same
vaules initially, and will be updated as callchain is processed later.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf hists: Check if accumulated when adding a hist entry

To support callchain accumulation, @entry should be recognized if it's
accumulated or not when add_hist_entry() called.  The period of an
accumulated entry should be added to ->stat_acc but not ->stat. Add
@sample_self arg for that.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf hists: Accumulate hist entry stat based on the callchain

Call __hists__add_entry() for each callchain node to get an
accumulated stat for an entry.  Introduce new cumulative_iter ops to
process them properly.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf tools: Update cpumode for each cumulative entry

The cpumode and level in struct addr_localtion was set for a sample
and but updated as cumulative callchains were added.  This led to have
non-matching symbol and cpumode in the output.

Update it accordingly based on the fact whether the map is a part of
the kernel or not.  This is a reverse of what thread__find_addr_map()
does.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf report: Cache cumulative callchains

It is possble that a callchain has cycles or recursive calls.  In that
case it'll end up having entries more than 100% overhead in the
output.  In order to prevent such entries, cache each callchain node
and skip if same entry already cumulated.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf callchain: Add callchain_cursor_snapshot()

The callchain_cursor_snapshot() is for saving current status of the
callchain.  It'll be used to accumulate callchain information for each node.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf tools: Save callchain info for each cumulative entry

When accumulating callchain entry, also save current snapshot of the
chain so that it can show the rest of the chain.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf hists: Sort hist entries by accumulated period

When callchain accumulation is requested, we need to sort the entries
by accumulated period value.  When accumulated periods of two entries
are same (i.e. single path callchain) put the caller above since
accumulation tends to put callers on higher position for obvious
reason.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf ui/hist: Add support to accumulated hist stat

Print accumulated stat of a hist entry if requested.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf ui/browser: Add support to accumulated hist stat

Print accumulated stat of a hist entry if requested.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf ui/gtk: Add support to accumulated hist stat

Print accumulated stat of a hist entry if requested.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf tools: Apply percent-limit to cumulative percentage

If -g cumulative option is given, it needs to show entries which don't
have self overhead.  So apply percent-limit to accumulated overhead
percentage in this case.

Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
perf tools: Add more hpp helper functions

Sometimes it needs to disable some columns at runtime.  Add help
functions to support that.

Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>