1. 07 5月, 2016 2 次提交
    • C
      perf script: Expose usage of the callchain db export via the python api · 2c15f5eb
      Chris Phlipot 提交于
      This change allows python scripts to be able to utilize the recent
      changes to the db export api allowing the export of call_paths derived
      from sampled callchains. These call paths are also now associated with
      the samples from which they were derived.
      
      - This feature is enabled by setting "perf_db_export_callchains" to true
      
      - When enabled, samples that have callchain information will have the
        callchains exported via call_path_table
      
      - The call_path_id field is added to sample_table to enable association of
        samples with the corresponding callchain stored in the call paths
        table. A call_path_id of 0 will be exported if there is no
        corresponding callchain.
      
      - When "perf_db_export_callchains" and "perf_db_export_calls" are both
        set to True, the call path root data structure will be shared. This
        prevents duplicating of data and call path ids that would result from
        building two separate call path trees in memory.
      
      - The call_return_processor structure definition was relocated to the header
        file to make its contents visible to db-export.c. This enables the
        sharing of call path trees between the two features, as mentioned
        above.
      
      This change is visible to python scripts using the python db export api.
      
      The change is backwards compatible with scripts written against the
      previous API, assuming that the scripts model the sample_table function
      after the one in export-to-postgresql.py script by allowing for
      additional arguments to be added in the future. ie. using *x as the
      final argument of the sample_table function.
      Signed-off-by: NChris Phlipot <cphlipot0@gmail.com>
      Acked-by: NAdrian 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-6-git-send-email-cphlipot0@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      2c15f5eb
    • C
      perf tools: Refactor code to move call path handling out of thread-stack · 451db126
      Chris Phlipot 提交于
      Move the call path handling code out of thread-stack.c and
      thread-stack.h to allow other components that are not part of
      thread-stack to create call paths.
      
      Summary:
      
      - Create call-path.c and call-path.h and add them to the build.
      
      - Move all call path related code out of thread-stack.c and thread-stack.h
        and into call-path.c and call-path.h.
      
      - A small subset of structures and functions are now visible through
        call-path.h, which is required for thread-stack.c to continue to
        compile.
      
      This change is a prerequisite for subsequent patches in this change set
      and by itself contains no user-visible changes.
      Signed-off-by: NChris Phlipot <cphlipot0@gmail.com>
      Acked-by: NAdrian 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-3-git-send-email-cphlipot0@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      451db126
  2. 15 4月, 2016 1 次提交
    • A
      perf callchain: Start moving away from global per thread cursors · 91d7b2de
      Arnaldo Carvalho de Melo 提交于
      The recent perf_evsel__fprintf_callchain() move to evsel.c added several
      new symbol requirements to the python binding, for instance:
      
        # perf test -v python
        16: Try 'import perf' in python, checking link problems      :
        --- start ---
        test child forked, pid 18030
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        ImportError: /tmp/build/perf/python/perf.so: undefined symbol:
        callchain_cursor
        test child finished with -1
        ---- end ----
        Try 'import perf' in python, checking link problems: FAILED!
        #
      
      This would require linking against callchain.c to access to the global
      callchain_cursor variables.
      
      Since lots of functions already receive as a parameter a
      callchain_cursor struct pointer, make that be the case for some more
      function so that we can start phasing out usage of yet another global
      variable.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/n/tip-djko3097eyg2rn66v2qcqfvn@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      91d7b2de
  3. 03 3月, 2016 1 次提交
  4. 25 2月, 2016 1 次提交
    • T
      perf script: Exception handling when the print fmt is empty · 8579aca3
      Taeung Song 提交于
      After collecting samples for events 'syscalls:', perf-script with python
      script doesn't occasionally work generating a segmentation fault.
      
      The reason is that the print fmt is empty and a value of
      event->print_fmt.args is NULL, so dereferencing the null pointer results
      in a segmentation fault i.e.:
      
          # perf record -e syscalls:*
          # perf script -g python
          # perf script -s perf-script.py
      
          in trace_begin
          syscalls__sys_enter_brk  3 79841.832099154  3777 test.sh  syscall_nr=12, brk=0
      
          ... (omitted) ...
      
          Segmentation fault (core dumped)
      
      For example, a format of sys_enter_getuid() hasn't
      print fmt as below.
      
          # cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_getuid/format
          name: sys_enter_getuid
          ID: 188
          format:
                  field:unsigned short common_type;         offset:0; size:2; signed:0;
                  field:unsigned char common_flags;         offset:2; size:1; signed:0;
                  field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
                  field:int common_pid;                     offset:4; size:4; signed:1;
                  field:int syscall_nr;                     offset:8; size:4; signed:1;
      
          print fmt: ""
      
      So add exception handling to avoid this problem.
      Signed-off-by: NTaeung Song <treeze.taeung@gmail.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/r/1456413179-12331-1-git-send-email-treeze.taeung@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8579aca3
  5. 07 1月, 2016 1 次提交
    • J
      perf script: Add python support for stat events · aef90263
      Jiri Olsa 提交于
      Add support to get stat events data in perf python scripts.
      
      The python script shall implement the following new interface to process
      stat data:
      
        def stat__<event_name>_[<modifier>](cpu, thread, time, val, ena, run):
      
          - is called for every stat event for given counter,
            if user monitors 'cycles,instructions:u" following
            callbacks should be defined:
      
            def stat__cycles(cpu, thread, time, val, ena, run):
            def stat__instructions_u(cpu, thread, time, val, ena, run):
      
        def stat__interval(time):
      
          - is called for every interval with its time,
            in non interval mode it's called after last
            stat event with total measured time in ns
      
      The rest of the current interface stays untouched..
      
      Please check example CPI metrics script in following patch
      with command line examples in changelogs.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NKan Liang <kan.liang@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1452028152-26762-8-git-send-email-jolsa@kernel.org
      [ Rename 'time' parameters to 'tstamp', to fix the build in older distros ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      aef90263
  6. 29 9月, 2015 1 次提交
  7. 03 9月, 2015 1 次提交
  8. 14 5月, 2015 1 次提交
  9. 03 4月, 2015 3 次提交
  10. 24 3月, 2015 1 次提交
  11. 22 1月, 2015 1 次提交
  12. 07 11月, 2014 1 次提交
  13. 04 11月, 2014 3 次提交
  14. 29 10月, 2014 2 次提交
  15. 15 10月, 2014 1 次提交
  16. 23 8月, 2014 1 次提交
  17. 14 8月, 2014 1 次提交
  18. 17 7月, 2014 4 次提交
  19. 27 6月, 2014 2 次提交
  20. 09 6月, 2014 1 次提交
    • N
      perf script/python: Print array argument as string · e646fe73
      Namhyung Kim 提交于
      With the Sebastian's change of handling num array argument (of raw
      syscall enter), the script still failed to work like this:
      
        $ perf record -e raw_syscalls:* sleep 1
        $ perf script -g python
        $ perf script -s perf-script.py
        ...
        Traceback (most recent call last):
          File "perf-script.py", line 42, in raw_syscalls__sys_enter
            (id, args),
        TypeError: %u format: a number is required, not list
        Fatal Python error: problem in Python trace event handler
        Aborted (core dumped)
      
      This is because the generated script tries to print the array arg as
      unsigned integer (%u).  Since the python seems to convert arguments to
      strings by default, just using %s solved the problem for me.
      Signed-off-by: NNamhyung Kim <namhyung@kernel.org>
      Cc: Tom Zanussi <tzanussi@gmail.com>
      Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
      Link: http://lkml.kernel.org/r/1401338695-18837-1-git-send-email-namhyung@kernel.orgSigned-off-by: NJiri Olsa <jolsa@kernel.org>
      e646fe73
  21. 08 6月, 2014 1 次提交
  22. 27 12月, 2013 1 次提交
  23. 20 12月, 2013 2 次提交
  24. 04 11月, 2013 1 次提交
  25. 24 10月, 2013 1 次提交
    • J
      perf script python: Fix mem leak due to missing Py_DECREFs on dict entries · c0268e8d
      Joseph Schuchart 提交于
      We are using the Python scripting interface in perf to extract kernel
      events relevant for performance analysis of HPC codes. We noticed that
      the "perf script" call allocates a significant amount of memory (in the
      order of several 100 MiB) during it's run, e.g. 125 MiB for a 25 MiB
      input file:
      
        $> perf record -o perf.data -a -R -g fp \
             -e power:cpu_frequency -e sched:sched_switch \
             -e sched:sched_migrate_task -e sched:sched_process_exit \
             -e sched:sched_process_fork -e sched:sched_process_exec \
             -e cycles  -m 4096 --freq 4000
        $> /usr/bin/time perf script -i perf.data -s dummy_script.py
        0.84user 0.13system 0:01.92elapsed 51%CPU (0avgtext+0avgdata
        125532maxresident)k
        73072inputs+0outputs (57major+33086minor)pagefaults 0swaps
      
      Upon further investigation using the valgrind massif tool, we noticed
      that Python objects that are created in trace-event-python.c via
      PyString_FromString*() (and their Integer and Long counterparts) are
      never free'd.
      
      The reason for this seem to be missing Py_DECREF calls on the objects
      that are returned by these functions and stored in the Python
      dictionaries. The Python dictionaries do not steal references (as
      opposed to Python tuples and lists) but instead add their own reference.
      
      Hence, the reference that is returned by these object creation functions
      is never released and the memory is leaked. (see [1,2])
      
      The attached patch fixes this by wrapping all relevant calls to
      PyDict_SetItemString() and decrementing the reference counter
      immediately after the Python function call.
      
      This reduces the allocated memory to a reasonable amount:
      
        $> /usr/bin/time perf script -i perf.data -s dummy_script.py
        0.73user 0.05system 0:00.79elapsed 99%CPU (0avgtext+0avgdata
        49132maxresident)k
        0inputs+0outputs (0major+14045minor)pagefaults 0swaps
      
      For comparison, with a 120 MiB input file the memory consumption
      reported by time drops from almost 600 MiB to 146 MiB.
      
      The patch has been tested using Linux 3.8.2 with Python 2.7.4 and Linux
      3.11.6 with Python 2.7.5.
      
      Please let me know if you need any further information.
      
      [1] http://docs.python.org/2/c-api/tuple.html#PyTuple_SetItem
      [2] http://docs.python.org/2/c-api/dict.html#PyDict_SetItemStringSigned-off-by: NJoseph Schuchart <joseph.schuchart@tu-dresden.de>
      Reviewed-by: NTom Zanussi <tom.zanussi@linux.intel.com>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Tom Zanussi <tom.zanussi@linux.intel.com>
      Link: http://lkml.kernel.org/r/1381468543-25334-4-git-send-email-namhyung@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c0268e8d
  26. 22 7月, 2013 1 次提交
  27. 25 1月, 2013 1 次提交
  28. 08 10月, 2012 1 次提交
  29. 11 9月, 2012 1 次提交
    • I
      perf tools: Use __maybe_used for unused variables · 1d037ca1
      Irina Tirdea 提交于
      perf defines both __used and __unused variables to use for marking
      unused variables. The variable __used is defined to
      __attribute__((__unused__)), which contradicts the kernel definition to
      __attribute__((__used__)) for new gcc versions. On Android, __used is
      also defined in system headers and this leads to warnings like: warning:
      '__used__' attribute ignored
      
      __unused is not defined in the kernel and is not a standard definition.
      If __unused is included everywhere instead of __used, this leads to
      conflicts with glibc headers, since glibc has a variables with this name
      in its headers.
      
      The best approach is to use __maybe_unused, the definition used in the
      kernel for __attribute__((unused)). In this way there is only one
      definition in perf sources (instead of 2 definitions that point to the
      same thing: __used and __unused) and it works on both Linux and Android.
      This patch simply replaces all instances of __used and __unused with
      __maybe_unused.
      Signed-off-by: NIrina Tirdea <irina.tirdea@intel.com>
      Acked-by: NPekka Enberg <penberg@kernel.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Namhyung Kim <namhyung.kim@lge.com>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Link: http://lkml.kernel.org/r/1347315303-29906-7-git-send-email-irina.tirdea@intel.com
      [ committer note: fixed up conflict with a116e05d in builtin-sched.c ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1d037ca1