simpletrace: Make simpletrace.py a Python module

The simpletrace.py script pretty-prints a binary trace file.  Most of
the code can be reused by trace file analysis scripts, so turn it into a
module.

Here is an example script that uses the new simpletrace module:

  #!/usr/bin/env python
  # Print virtqueue elements that were never returned to the guest.

  import simpletrace

  class VirtqueueRequestTracker(simpletrace.Analyzer):
      def __init__(self):
          self.elems = set()

      def virtqueue_pop(self, vq, elem, in_num, out_num):
          self.elems.add(elem)

      def virtqueue_fill(self, vq, elem, length, idx):
          self.elems.remove(elem)

      def end(self):
          for elem in self.elems:
              print hex(elem)

  simpletrace.run(VirtqueueRequestTracker())

The simpletrace API is based around the Analyzer class.  Users implement
an analyzer subclass and add methods for trace events they want to
process.  A catchall() method is invoked for trace events which do not
have dedicated methods.  Finally, there are also begin() and end()
methods like in sed that can be used to perform setup or print
statistics at the end.

A binary trace file is processed either with:

  simpletrace.run(analyzer) # uses command-line args

or with:

  simpletrace.process('path/to/trace-events',
                      'path/to/trace-file',
                      analyzer)

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
1 file changed
tree: cdb2e7a8c9af492e64ebfef23f2ff6d6d368c0a6
  1. audio/
  2. block/
  3. bsd-user/
  4. darwin-user/
  5. default-configs/
  6. docs/
  7. fpu/
  8. fsdev/
  9. gdb-xml/
  10. hw/
  11. linux-user/
  12. net/
  13. pc-bios/
  14. QMP/
  15. roms/
  16. scripts/
  17. slirp/
  18. sysconfigs/
  19. target-alpha/
  20. target-arm/
  21. target-cris/
  22. target-i386/
  23. target-m68k/
  24. target-microblaze/
  25. target-mips/
  26. target-ppc/
  27. target-s390x/
  28. target-sh4/
  29. target-sparc/
  30. tcg/
  31. tests/
  32. ui/
  33. .gitignore
  34. .gitmodules
  35. a.out.h
  36. acl.c
  37. acl.h
  38. aes.c
  39. aes.h
  40. aio.c
  41. alpha-dis.c
  42. alpha.ld
  43. arch_init.c
  44. arch_init.h
  45. arm-dis.c
  46. arm-semi.c
  47. arm.ld
  48. async.c
  49. balloon.c
  50. balloon.h
  51. bitmap.c
  52. bitmap.h
  53. bitops.c
  54. bitops.h
  55. block-migration.c
  56. block-migration.h
  57. block.c
  58. block.h
  59. block_int.h
  60. blockdev.c
  61. blockdev.h
  62. bswap.h
  63. bt-host.c
  64. bt-host.h
  65. bt-vhci.c
  66. buffered_file.c
  67. buffered_file.h
  68. cache-utils.c
  69. cache-utils.h
  70. Changelog
  71. check-qdict.c
  72. check-qfloat.c
  73. check-qint.c
  74. check-qjson.c
  75. check-qlist.c
  76. check-qstring.c
  77. cmd.c
  78. cmd.h
  79. CODING_STYLE
  80. compatfd.c
  81. compatfd.h
  82. config.h
  83. configure
  84. console.c
  85. console.h
  86. COPYING
  87. COPYING.LIB
  88. cpu-all.h
  89. cpu-common.h
  90. cpu-defs.h
  91. cpu-exec.c
  92. cpus.c
  93. cpus.h
  94. cris-dis.c
  95. cursor.c
  96. cursor_hidden.xpm
  97. cursor_left_ptr.xpm
  98. cutils.c
  99. def-helper.h
  100. device_tree.c
  101. device_tree.h
  102. dis-asm.h
  103. disas.c
  104. disas.h
  105. dma-helpers.c
  106. dma.h
  107. dyngen-exec.h
  108. elf.h
  109. envlist.c
  110. envlist.h
  111. exec-all.h
  112. exec.c
  113. gdbstub.c
  114. gdbstub.h
  115. gen-icount.h
  116. HACKING
  117. hmp-commands.hx
  118. host-utils.c
  119. host-utils.h
  120. hpet.h
  121. hppa-dis.c
  122. hppa.ld
  123. i386-dis.c
  124. i386.ld
  125. ia64-dis.c
  126. ia64.ld
  127. input.c
  128. ioport-user.c
  129. ioport.c
  130. ioport.h
  131. iorange.h
  132. iov.c
  133. iov.h
  134. json-lexer.c
  135. json-lexer.h
  136. json-parser.c
  137. json-parser.h
  138. json-streamer.c
  139. json-streamer.h
  140. kvm-all.c
  141. kvm-stub.c
  142. kvm.h
  143. libfdt_env.h
  144. LICENSE
  145. linux-aio.c
  146. m68k-dis.c
  147. m68k-semi.c
  148. m68k.ld
  149. MAINTAINERS
  150. Makefile
  151. Makefile.dis
  152. Makefile.hw
  153. Makefile.objs
  154. Makefile.target
  155. Makefile.user
  156. microblaze-dis.c
  157. migration-exec.c
  158. migration-fd.c
  159. migration-tcp.c
  160. migration-unix.c
  161. migration.c
  162. migration.h
  163. mips-dis.c
  164. mips.ld
  165. module.c
  166. module.h
  167. monitor.c
  168. monitor.h
  169. nbd.c
  170. nbd.h
  171. net-checksum.c
  172. net.c
  173. net.h
  174. notify.c
  175. notify.h
  176. os-posix.c
  177. os-win32.c
  178. osdep.c
  179. osdep.h
  180. oslib-posix.c
  181. oslib-win32.c
  182. path.c
  183. pci-ids.txt
  184. pflib.c
  185. pflib.h
  186. poison.h
  187. posix-aio-compat.c
  188. ppc-dis.c
  189. ppc.ld
  190. ppc64.ld
  191. qbool.c
  192. qbool.h
  193. qdict-test-data.txt
  194. qdict.c
  195. qdict.h
  196. qemu-aio.h
  197. qemu-barrier.h
  198. qemu-char.c
  199. qemu-char.h
  200. qemu-common.h
  201. qemu-config.c
  202. qemu-config.h
  203. qemu-doc.texi
  204. qemu-error.c
  205. qemu-error.h
  206. qemu-img-cmds.hx
  207. qemu-img.c
  208. qemu-img.texi
  209. qemu-io.c
  210. qemu-lock.h
  211. qemu-log.h
  212. qemu-malloc.c
  213. qemu-nbd.c
  214. qemu-nbd.texi
  215. qemu-objects.h
  216. qemu-option.c
  217. qemu-option.h
  218. qemu-options.h
  219. qemu-options.hx
  220. qemu-os-posix.h
  221. qemu-os-win32.h
  222. qemu-queue.h
  223. qemu-sockets.c
  224. qemu-tech.texi
  225. qemu-thread.c
  226. qemu-thread.h
  227. qemu-timer-common.c
  228. qemu-timer.c
  229. qemu-timer.h
  230. qemu-tool.c
  231. qemu-x509.h
  232. qemu.sasl
  233. qemu_socket.h
  234. qerror.c
  235. qerror.h
  236. qfloat.c
  237. qfloat.h
  238. qint.c
  239. qint.h
  240. qjson.c
  241. qjson.h
  242. qlist.c
  243. qlist.h
  244. qmp-commands.hx
  245. qobject.h
  246. qstring.c
  247. qstring.h
  248. range.h
  249. readline.c
  250. readline.h
  251. README
  252. rules.mak
  253. rwhandler.c
  254. rwhandler.h
  255. s390-dis.c
  256. s390.ld
  257. savevm.c
  258. sh4-dis.c
  259. simpletrace.c
  260. simpletrace.h
  261. softmmu-semi.h
  262. softmmu_defs.h
  263. softmmu_exec.h
  264. softmmu_header.h
  265. softmmu_template.h
  266. sparc-dis.c
  267. sparc.ld
  268. sparc64.ld
  269. spice-qemu-char.c
  270. sysemu.h
  271. targphys.h
  272. tcg-runtime.c
  273. thunk.c
  274. thunk.h
  275. TODO
  276. trace-events
  277. translate-all.c
  278. uboot_image.h
  279. usb-bsd.c
  280. usb-linux.c
  281. usb-stub.c
  282. VERSION
  283. version.rc
  284. vgafont.h
  285. vl.c
  286. x86_64.ld