~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 # Util.py - Python extension for perf script, miscellaneous utility code
  2 #
  3 # Copyright (C) 2010 by Tom Zanussi <tzanussi@gmail.com>
  4 #
  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
  7 # Foundation.
  8 from __future__ import print_function
  9 
 10 import errno, os
 11 
 12 FUTEX_WAIT = 0
 13 FUTEX_WAKE = 1
 14 FUTEX_PRIVATE_FLAG = 128
 15 FUTEX_CLOCK_REALTIME = 256
 16 FUTEX_CMD_MASK = ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
 17 
 18 NSECS_PER_SEC    = 1000000000
 19 
 20 def avg(total, n):
 21     return total / n
 22 
 23 def nsecs(secs, nsecs):
 24     return secs * NSECS_PER_SEC + nsecs
 25 
 26 def nsecs_secs(nsecs):
 27     return nsecs / NSECS_PER_SEC
 28 
 29 def nsecs_nsecs(nsecs):
 30     return nsecs % NSECS_PER_SEC
 31 
 32 def nsecs_str(nsecs):
 33     str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
 34     return str
 35 
 36 def add_stats(dict, key, value):
 37         if key not in dict:
 38                 dict[key] = (value, value, value, 1)
 39         else:
 40                 min, max, avg, count = dict[key]
 41                 if value < min:
 42                         min = value
 43                 if value > max:
 44                         max = value
 45                 avg = (avg + value) / 2
 46                 dict[key] = (min, max, avg, count + 1)
 47 
 48 def clear_term():
 49     print("\x1b[H\x1b[2J")
 50 
 51 audit_package_warned = False
 52 
 53 try:
 54         import audit
 55         machine_to_id = {
 56                 'x86_64': audit.MACH_86_64,
 57                 'aarch64': audit.MACH_AARCH64,
 58                 'alpha' : audit.MACH_ALPHA,
 59                 'ia64'  : audit.MACH_IA64,
 60                 'ppc'   : audit.MACH_PPC,
 61                 'ppc64' : audit.MACH_PPC64,
 62                 'ppc64le' : audit.MACH_PPC64LE,
 63                 's390'  : audit.MACH_S390,
 64                 's390x' : audit.MACH_S390X,
 65                 'i386'  : audit.MACH_X86,
 66                 'i586'  : audit.MACH_X86,
 67                 'i686'  : audit.MACH_X86,
 68         }
 69         try:
 70                 machine_to_id['armeb'] = audit.MACH_ARMEB
 71         except:
 72                 pass
 73         machine_id = machine_to_id[os.uname()[4]]
 74 except:
 75         if not audit_package_warned:
 76                 audit_package_warned = True
 77                 print("Install the python-audit package to get syscall names.\n"
 78                     "For example:\n  # apt-get install python3-audit (Ubuntu)"
 79                     "\n  # yum install python3-audit (Fedora)"
 80                     "\n  etc.\n")
 81 
 82 def syscall_name(id):
 83         try:
 84                 return audit.audit_syscall_to_name(id, machine_id)
 85         except:
 86                 return str(id)
 87 
 88 def strerror(nr):
 89         try:
 90                 return errno.errorcode[abs(nr)]
 91         except:
 92                 return "Unknown %d errno" % nr

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php