xref: /linux/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py (revision 5a0e3ad6af8660be21ca98a971cd00f331318c05)
1# Util.py - Python extension for perf trace, 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
9NSECS_PER_SEC    = 1000000000
10
11def avg(total, n):
12    return total / n
13
14def nsecs(secs, nsecs):
15    return secs * NSECS_PER_SEC + nsecs
16
17def nsecs_secs(nsecs):
18    return nsecs / NSECS_PER_SEC
19
20def nsecs_nsecs(nsecs):
21    return nsecs % NSECS_PER_SEC
22
23def nsecs_str(nsecs):
24    str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
25    return str
26