linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Milian Wolff <milian.wolff@kdab.com>
To: namhyung@kernel.org
Cc: linux-perf-users@vger.kernel.org
Subject: Re: Accessing sample data (like period) for trace events from python scripts
Date: Wed, 17 Aug 2016 10:48:31 +0200	[thread overview]
Message-ID: <8086607.n4B18LBsdA@milian-kdab2> (raw)
In-Reply-To: <20160817030553.GB8981@sejong>

[-- Attachment #1: Type: text/plain, Size: 1338 bytes --]

On Wednesday, August 17, 2016 12:05:53 PM CEST Namhyung Kim wrote:
> Hi Milian,
> 
> On Tue, Aug 16, 2016 at 08:42:01PM +0200, Milian Wolff wrote:
> > Hey all,
> > 
> > It doesn't seem to be possible to access the period, tid and various other
> > sample fields from a python (and perl?) script using `perf script`. My
> > use-
> > case would be analyzing a perf data file created by perf inject
> > --sched-stat.
> 
> I think you can access param_dict["sample"]["period"].

No, that is not possible, but would be a viable solution as well.

~~~~~~~~~~~~~~~~~~
/tmp$ cat perf-script.py

import os
import sys

sys.path.append(os.environ['PERF_EXEC_PATH'] + \
        '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')

from perf_trace_context import *
from Core import *

def trace_unhandled(event_name, context, event_fields_dict):
        print event_fields_dict['sample']['period']

/tmp$ perf script -s perf-script.py
Traceback (most recent call last):
  File "perf-script.py", line 11, in trace_unhandled
    print event_fields_dict['sample']['period']
KeyError: 'sample'
Fatal Python error: problem in Python trace event handler
Aborted (core dumped)
~~~~~~~~~~~~~~~~~~

Cheers
-- 
Milian Wolff | milian.wolff@kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5903 bytes --]

  reply	other threads:[~2016-08-17  8:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-16 18:42 Accessing sample data (like period) for trace events from python scripts Milian Wolff
2016-08-17  3:05 ` Namhyung Kim
2016-08-17  8:48   ` Milian Wolff [this message]
2016-08-19  1:35     ` Namhyung Kim
2016-08-19  1:51       ` Namhyung Kim
2016-08-20 20:30         ` Milian Wolff
2016-08-23  2:42           ` Namhyung Kim
2016-08-23 19:48             ` Milian Wolff

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=8086607.n4B18LBsdA@milian-kdab2 \
    --to=milian.wolff@kdab.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).