Util.py 686 B

12345678910111213141516171819202122232425262728
  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. NSECS_PER_SEC = 1000000000
  9. def avg(total, n):
  10. return total / n
  11. def nsecs(secs, nsecs):
  12. return secs * NSECS_PER_SEC + nsecs
  13. def nsecs_secs(nsecs):
  14. return nsecs / NSECS_PER_SEC
  15. def nsecs_nsecs(nsecs):
  16. return nsecs % NSECS_PER_SEC
  17. def nsecs_str(nsecs):
  18. str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
  19. return str
  20. def clear_term():
  21. print("\x1b[H\x1b[2J")