1 # Util.py - Python extension for perf trace, miscellaneous utility code
3 # Copyright (C) 2010 by Tom Zanussi <tzanussi@gmail.com>
5 # This software may be distributed under the terms of the GNU General
6 # Public License ("GPL") version 2 as published by the Free Software
13 FUTEX_PRIVATE_FLAG
= 128
14 FUTEX_CLOCK_REALTIME
= 256
15 FUTEX_CMD_MASK
= ~
(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME
)
17 NSECS_PER_SEC
= 1000000000
22 def nsecs(secs
, nsecs
):
23 return secs
* NSECS_PER_SEC
+ nsecs
25 def nsecs_secs(nsecs
):
26 return nsecs
/ NSECS_PER_SEC
28 def nsecs_nsecs(nsecs
):
29 return nsecs
% NSECS_PER_SEC
32 str = "%5u.%09u" % (nsecs_secs(nsecs
), nsecs_nsecs(nsecs
)),
35 def add_stats(dict, key
, value
):
36 if not dict.has_key(key
):
37 dict[key
] = (value
, value
, value
, 1)
39 min, max, avg
, count
= dict[key
]
44 avg
= (avg
+ value
) / 2
45 dict[key
] = (min, max, avg
, count
+ 1)
48 print("\x1b[H\x1b[2J")
50 audit_package_warned
= False
55 'x86_64': audit
.MACH_86_64
,
56 'alpha' : audit
.MACH_ALPHA
,
57 'ia64' : audit
.MACH_IA64
,
58 'ppc' : audit
.MACH_PPC
,
59 'ppc64' : audit
.MACH_PPC64
,
60 's390' : audit
.MACH_S390
,
61 's390x' : audit
.MACH_S390X
,
62 'i386' : audit
.MACH_X86
,
63 'i586' : audit
.MACH_X86
,
64 'i686' : audit
.MACH_X86
,
67 machine_to_id
['armeb'] = audit
.MACH_ARMEB
70 machine_id
= machine_to_id
[os
.uname()[4]]
72 if not audit_package_warned
:
73 audit_package_warned
= True
74 print "Install the audit-libs-python package to get syscall names"
78 return audit
.audit_syscall_to_name(id, machine_id
)
84 return errno
.errorcode
[abs(nr
)]
86 return "Unknown %d errno" % nr