linux/tools/perf/scripts/python
Chris Phlipot 3521f3bc9d perf script: Update export-to-postgresql to support callchain export
Update the export-to-postgresql.py to support the newly introduced
callchain export.

callchains are added into the existing call_paths table and can now
be associated with samples when the "callpaths" commandline option
is used with the script.

Ex.:

  $ perf script -s export-to-postgresql.py example_db all callchains

Includes the following changes to enable callchain export via the python export
APIs:

- Add the "callchains" commandline option, which is used to enable
  callchain export by setting the perf_db_export_callchains global
- Add perf_db_export_callchains checks for call_path table creation
  and population.
- Add call_path_id to samples_table to conform with the new API

example usage and output using a small test app:

  test_app.c:

	volatile int x = 0;
	void inc_x_loop()
	{
		int i;
		for(i=0; i<100000000; i++)
			x++;
	}

	void a()
	{
		inc_x_loop();
	}

	void b()
	{
		inc_x_loop();
	}

	int main()
	{
		a();
		b();
		return 0;
	}

example usage:

  $ gcc -g -O0 test_app.c
  $ perf record --call-graph=dwarf ./a.out
  [ perf record: Woken up 77 times to write data ]
  [ perf record: Captured and wrote 19.373 MB perf.data (2404 samples) ]

  $ perf script -s scripts/python/export-to-postgresql.py
	example_db all callchains

  $ psql example_db

  example_db=#
  SELECT
  (SELECT name FROM symbols WHERE id = cps.symbol_id) as symbol,
  (SELECT name FROM symbols WHERE id =
	(SELECT symbol_id from call_paths where id = cps.parent_id))
	as parent_symbol,
  sum(period) as event_count
  FROM samples join call_paths as cps on call_path_id = cps.id
  GROUP BY cps.id,evsel_id
  ORDER BY event_count DESC
  LIMIT 5;

        symbol      |      parent_symbol       | event_count
  ------------------+--------------------------+-------------
   inc_x_loop       | a                        |   734250982
   inc_x_loop       | b                        |   731028057
   unknown          | unknown                  |     1335858
   task_tick_fair   | scheduler_tick           |     1238842
   update_wall_time | tick_do_update_jiffies64 |      650373
  (5 rows)

The above data shows total "self time" in cycles for each call path that was
sampled. It is intended to demonstrate how it accounts separately for the two
ways to reach the "inc_x_loop" function(via "a" and "b").  Recursive common
table expressions can be used as well to get cumulative time spent in a
function as well, but that is beyond the scope of this basic example.

Signed-off-by: Chris Phlipot <cphlipot0@gmail.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1461831551-12213-7-git-send-email-cphlipot0@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-06 13:00:55 -03:00
..
bin perf scripts python: Add new compaction-times script 2015-08-28 14:53:40 -03:00
Perf-Trace-Util perf python scripting: Append examples to err msg about audit-libs-python 2016-02-12 11:30:27 -03:00
call-graph-from-postgresql.py perf tools: Add example call-graph script 2015-08-21 12:32:40 -03:00
check-perf-trace.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00
compaction-times.py perf scripts python: Add new compaction-times script 2015-08-28 14:53:40 -03:00
event_analyzing_sample.py perf script python: Correct handler check and spelling errors 2012-08-09 13:26:19 -03:00
export-to-postgresql.py perf script: Update export-to-postgresql to support callchain export 2016-05-06 13:00:55 -03:00
failed-syscalls-by-pid.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00
futex-contention.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00
net_dropmonitor.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00
netdev-times.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00
sched-migration.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00
sctop.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00
stat-cpi.py perf script: Add stat-cpi.py script 2016-01-06 20:11:16 -03:00
syscall-counts-by-pid.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00
syscall-counts.py perf script: Add callchain to generic and tracepoint events 2014-07-16 17:57:33 -03:00