]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/python | |
2 | # | |
3 | # This script scans the trace.codes file, containing a mapping of event id to | |
4 | # event name for all events, and writes to stdout a C declaration for a table | |
5 | # named kd_events[] or these mappings. | |
6 | # Required to generate a header file used by DEVELOPMENT and DEBUG kernels. | |
7 | # | |
8 | ||
9 | import sys | |
10 | import re | |
11 | ||
12 | # we expect one arg specifying the path to the trace.codes file | |
13 | if (len(sys.argv) < 2): | |
14 | exit(1) | |
15 | trace_code_file = sys.argv[1] | |
16 | ||
17 | # regular expression pattern to match <hex_id> <string> | |
18 | id_name_pattern = re.compile('0x([0-9a-fA-F]+)\s+([^\s]*)') | |
19 | code_table = [] | |
20 | ||
21 | # scan file to generate internal table | |
22 | with open(trace_code_file, 'rt') as codes: | |
23 | for line in codes: | |
24 | m = id_name_pattern.match(line) | |
25 | if m: | |
26 | code_table += [(int(m.group(1),base=16), m.group(2))] | |
27 | ||
28 | # emit typedef: | |
29 | print "typedef struct {" | |
30 | print " uint32_t id;" | |
31 | print " const char *name;" | |
32 | print "} kd_event_t;" | |
33 | # emit structure declaration and sorted initialization: | |
34 | print "kd_event_t kd_events[] = {" | |
35 | for mapping in sorted(code_table, key=lambda x: x[0]): | |
36 | print " {0x%x, \"%s\"}," % mapping | |
37 | print "};" | |
38 |