1. 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
  2. 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
  3. 29 9月, 2015 1 次提交
  4. 03 9月, 2015 1 次提交
  5. 14 5月, 2015 1 次提交
  6. 03 4月, 2015 3 次提交
  7. 24 3月, 2015 1 次提交
  8. 22 1月, 2015 1 次提交
  9. 07 11月, 2014 1 次提交
  10. 04 11月, 2014 3 次提交
  11. 29 10月, 2014 2 次提交
  12. 15 10月, 2014 1 次提交
  13. 23 8月, 2014 1 次提交
  14. 14 8月, 2014 1 次提交
  15. 17 7月, 2014 4 次提交
  16. 27 6月, 2014 2 次提交
  17. 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
  18. 08 6月, 2014 1 次提交
  19. 27 12月, 2013 1 次提交
  20. 20 12月, 2013 2 次提交
  21. 04 11月, 2013 1 次提交
  22. 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
  23. 22 7月, 2013 1 次提交
  24. 25 1月, 2013 1 次提交
  25. 08 10月, 2012 1 次提交
  26. 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
  27. 10 8月, 2012 1 次提交
  28. 08 8月, 2012 3 次提交