Descriptor of a structure in the binary trace log.
| 454 | |
| 455 | |
| 456 | class Descriptor(object): |
| 457 | """Descriptor of a structure in the binary trace log.""" |
| 458 | |
| 459 | CTYPE_MAP = { |
| 460 | "u16": ctypes.c_uint16, |
| 461 | "u32": ctypes.c_uint32, |
| 462 | "u64": ctypes.c_uint64 |
| 463 | } |
| 464 | |
| 465 | def __init__(self, fields): |
| 466 | class TraceItem(ctypes.Structure): |
| 467 | _fields_ = Descriptor.CtypesFields(fields) |
| 468 | |
| 469 | def __str__(self): |
| 470 | return ", ".join("%s: %s" % (field, self.__getattribute__(field)) |
| 471 | for field, _ in TraceItem._fields_) |
| 472 | |
| 473 | self.ctype = TraceItem |
| 474 | |
| 475 | def Read(self, trace, offset): |
| 476 | return self.ctype.from_buffer(trace, offset) |
| 477 | |
| 478 | @staticmethod |
| 479 | def CtypesFields(fields): |
| 480 | return [(field, Descriptor.CTYPE_MAP[format]) for (field, format) in fields] |
| 481 | |
| 482 | |
| 483 | # Please see http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=tree;f=tools/perf |
no outgoing calls
no test coverage detected