public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Tom Zanussi <tzanussi@gmail.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, rostedt@goodmis.org,
	k-keiichi@bx.jp.nec.com
Subject: Re: [PATCH 12/12] perf trace/scripting: add perf-trace-python Documentation
Date: Thu, 25 Feb 2010 02:37:23 +0100	[thread overview]
Message-ID: <20100225013720.GB7491@nowhere> (raw)
In-Reply-To: <1264580883-15324-13-git-send-email-tzanussi@gmail.com>

On Wed, Jan 27, 2010 at 02:28:03AM -0600, Tom Zanussi wrote:
> +from perf_trace_context import *
> +from Core import *
> +
> +def trace_end():
> +	print "in trace_end"
> +
> +def raw_syscalls__sys_enter(event_name, context, common_cpu,
> +	common_secs, common_nsecs, common_pid, common_comm,
> +	id, args):
> +----
> +
> +In trace_end(), we'll simply print the results, but first we need to
> +generate some results to print.  To do that we need to have our
> +sys_enter() handler do the necessary tallying until all events have
> +been counted.  A hash table indexed by syscall id is a good way to
> +store that information; every time the sys_enter() handler is called,
> +we simply increment a count associated with that hash entry indexed by
> +that syscall id:
> +
> +----
> +  syscalls = autodict()
> +
> +  try:
> +    syscalls[id] += 1
> +  except TypeError:
> +    syscalls[id] = 1
> +----
> +
> +The syscalls 'autodict' object is a special kind of Python dictionary
> +(implemented in Core.py) that implements Perl's 'autovivifying' hashes
> +in Python i.e. with autovivifying hashes, you can assign nested hash
> +values without having to go to the trouble of creating intermediate
> +levels if they don't exist e.g syscalls[comm][pid][id] = 1 will create
> +the intermediate hash levels and finally assign the value 1 to the
> +hash entry for 'id' (because the value being assigned isn't a hash
> +object itself, the initial value is assigned in the TypeError
> +exception.  Well, there may be a better way to do this in Python but
> +that's what works for now).


That's smart. I wish python had a native type for that.

And looking how you made it easily....

def autodict():
    return defaultdict(autodict)


  reply	other threads:[~2010-02-25  1:37 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-27  8:27 [PATCH 00/12] perf trace: Python scripting support Tom Zanussi
2010-01-27  8:27 ` [PATCH 01/12] perf trace/scripting: Fix supported language listing option Tom Zanussi
2010-02-25 10:06   ` [tip:perf/core] perf/scripts: " tip-bot for Tom Zanussi
2010-01-27  8:27 ` [PATCH 02/12] perf trace/scripting: fix bug in Util.pm Tom Zanussi
2010-02-25 10:06   ` [tip:perf/core] perf/scripts: Fix " tip-bot for Tom Zanussi
2010-01-27  8:27 ` [PATCH 03/12] perf trace/scripting: move common code out of Perl-specific files Tom Zanussi
2010-02-25 10:07   ` [tip:perf/core] perf/scripts: Move " tip-bot for Tom Zanussi
2010-01-27  8:27 ` [PATCH 04/12] perf trace/scripting: move Perl scripting files to scripting-engines dir Tom Zanussi
2010-02-25 10:07   ` [tip:perf/core] perf/scripts: Move " tip-bot for Tom Zanussi
2010-01-27  8:27 ` [PATCH 05/12] perf trace/scripting: remove check-perf-trace from listed scripts Tom Zanussi
2010-02-22  1:51   ` Frederic Weisbecker
2010-02-25 10:07   ` [tip:perf/core] perf/scripts: Remove " tip-bot for Tom Zanussi
2010-02-25 10:07   ` [tip:perf/core] perf/scripts: Add Python scripting engine tip-bot for Tom Zanussi
2010-01-27  8:27 ` [PATCH 06/12] perf trace/scripting: add " Tom Zanussi
2010-02-22  2:27   ` Frederic Weisbecker
2010-02-22  7:12     ` Tom Zanussi
2010-02-25 10:08       ` [tip:perf/core] perf/scripts: Remove unnecessary PyTuple resizes tip-bot for Tom Zanussi
2010-01-27  8:27 ` [PATCH 07/12] perf trace/scripting: add syscall tracing scripts Tom Zanussi
2010-02-25 10:08   ` [tip:perf/core] perf/scripts: Add " tip-bot for Tom Zanussi
2010-01-27  8:27 ` [PATCH 08/12] perf: export some syscall metadata Tom Zanussi
2010-02-23 21:44   ` Frederic Weisbecker
2010-02-24  6:00     ` Tom Zanussi
2010-02-25  1:52       ` Frederic Weisbecker
2010-02-25  6:09         ` Tom Zanussi
2010-02-25  2:43       ` Frederic Weisbecker
2010-02-25  6:51         ` Tom Zanussi
2010-03-27  0:37           ` Frederic Weisbecker
2010-03-28  5:18             ` Tom Zanussi
2010-01-27  8:28 ` [PATCH 09/12] perf tools: save syscall map Tom Zanussi
2010-01-27  8:28 ` [PATCH 10/12] perf trace/scripting: make the syscall map available as a Python dict Tom Zanussi
2010-01-27  8:28 ` [PATCH 11/12] perf trace/scripting: make the syscall map available as a Perl hash Tom Zanussi
2010-01-27  8:28 ` [PATCH 12/12] perf trace/scripting: add perf-trace-python Documentation Tom Zanussi
2010-02-25  1:37   ` Frederic Weisbecker [this message]
2010-02-25  6:06     ` Tom Zanussi
2010-02-25 10:08   ` [tip:perf/core] perf/scripts: Add " tip-bot for Tom Zanussi
2010-02-19 21:37 ` [PATCH 00/12] perf trace: Python scripting support Frederic Weisbecker
2010-02-20 21:51   ` Tom Zanussi
2010-02-23 17:31     ` Frederic Weisbecker

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=20100225013720.GB7491@nowhere \
    --to=fweisbec@gmail.com \
    --cc=k-keiichi@bx.jp.nec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=tzanussi@gmail.com \
    /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