lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 25 Feb 2010 02:37:23 +0100
From:	Frederic Weisbecker <fweisbec@...il.com>
To:	Tom Zanussi <tzanussi@...il.com>
Cc:	linux-kernel@...r.kernel.org, mingo@...e.hu, rostedt@...dmis.org,
	k-keiichi@...jp.nec.com
Subject: Re: [PATCH 12/12] perf trace/scripting: add perf-trace-python
	Documentation

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)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ