]> git.proxmox.com Git - qemu.git/commit
simpletrace: Make simpletrace.py a Python module
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Tue, 22 Feb 2011 13:59:41 +0000 (13:59 +0000)
committerAurelien Jarno <aurelien@aurel32.net>
Sun, 6 Mar 2011 18:06:33 +0000 (19:06 +0100)
commit59da66849215eccf1dce2154c84f217a3c39678b
treecdb2e7a8c9af492e64ebfef23f2ff6d6d368c0a6
parent0c1592d93585ddce572a71a77534ca765c5f5d34
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>
scripts/simpletrace.py