1 # Util.py - Python extension for perf script, 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
8 from __future__
import print_function
14 FUTEX_PRIVATE_FLAG
= 128
15 FUTEX_CLOCK_REALTIME
= 256
16 FUTEX_CMD_MASK
= ~
(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME
)
18 NSECS_PER_SEC
= 1000000000
23 def nsecs(secs
, nsecs
):
24 return secs
* NSECS_PER_SEC
+ nsecs
26 def nsecs_secs(nsecs
):
27 return nsecs
/ NSECS_PER_SEC
29 def nsecs_nsecs(nsecs
):
30 return nsecs
% NSECS_PER_SEC
33 str = "%5u.%09u" % (nsecs_secs(nsecs
), nsecs_nsecs(nsecs
)),
36 def add_stats(dict, key
, value
):
38 dict[key
] = (value
, value
, value
, 1)
40 min, max, avg
, count
= dict[key
]
45 avg
= (avg
+ value
) / 2
46 dict[key
] = (min, max, avg
, count
+ 1)
49 print("\x1b[H\x1b[2J")
51 audit_package_warned
= False
56 'x86_64': audit
.MACH_86_64
,
57 'alpha' : audit
.MACH_ALPHA
,
58 'ia64' : audit
.MACH_IA64
,
59 'ppc' : audit
.MACH_PPC
,
60 'ppc64' : audit
.MACH_PPC64
,
61 'ppc64le' : audit
.MACH_PPC64LE
,
62 's390' : audit
.MACH_S390
,
63 's390x' : audit
.MACH_S390X
,
64 'i386' : audit
.MACH_X86
,
65 'i586' : audit
.MACH_X86
,
66 'i686' : audit
.MACH_X86
,
69 machine_to_id
['armeb'] = audit
.MACH_ARMEB
72 machine_id
= machine_to_id
[os
.uname()[4]]
74 if not audit_package_warned
:
75 audit_package_warned
= True
76 print("Install the audit-libs-python package to get syscall names.\n"
77 "For example:\n # apt-get install python-audit (Ubuntu)"
78 "\n # yum install audit-libs-python (Fedora)"
83 return audit
.audit_syscall_to_name(id, machine_id
)
89 return errno
.errorcode
[abs(nr
)]
91 return "Unknown %d errno" % nr