Stefan Schuermans commited on 2020-05-23 16:11:51
Showing 9 changed files, with 86 additions and 42 deletions.
... | ... |
@@ -0,0 +1,56 @@ |
1 |
+""" |
|
2 |
+Command line interface of UProcTrace: "upt-tool". |
|
3 |
+""" |
|
4 |
+ |
|
5 |
+import argparse |
|
6 |
+import sys |
|
7 |
+import uproctrace.dump |
|
8 |
+import uproctrace.processes |
|
9 |
+ |
|
10 |
+ |
|
11 |
+def dump(args): |
|
12 |
+ """ |
|
13 |
+ Dump all events in trace file to standard output. |
|
14 |
+ """ |
|
15 |
+ with open(args.trace, 'rb') as proto_file: |
|
16 |
+ while uproctrace.dump.dump_event(proto_file, sys.stdout): |
|
17 |
+ pass |
|
18 |
+ |
|
19 |
+ |
|
20 |
+def parse(args): |
|
21 |
+ """ |
|
22 |
+ Parse all events in trace file. |
|
23 |
+ """ |
|
24 |
+ with open(args.trace, 'rb') as proto_file: |
|
25 |
+ uproctrace.processes.Processes(proto_file) |
|
26 |
+ |
|
27 |
+ |
|
28 |
+def parse_args(): |
|
29 |
+ """ |
|
30 |
+ Parse command line arguments. |
|
31 |
+ """ |
|
32 |
+ # set up main parser |
|
33 |
+ parser = argparse.ArgumentParser(description='uproctrace tool') |
|
34 |
+ parser.add_argument('trace', help='trace file') |
|
35 |
+ subparsers = parser.add_subparsers() |
|
36 |
+ # dump |
|
37 |
+ dump_parser = subparsers.add_parser('dump') |
|
38 |
+ dump_parser.set_defaults(func=dump) |
|
39 |
+ # parse |
|
40 |
+ parse_parser = subparsers.add_parser('parse') |
|
41 |
+ parse_parser.set_defaults(func=parse) |
|
42 |
+ # parse |
|
43 |
+ args = parser.parse_args() |
|
44 |
+ if not hasattr(args, 'func'): |
|
45 |
+ print('error: no sub-command specified', file=sys.stderr) |
|
46 |
+ sys.exit(3) |
|
47 |
+ return args |
|
48 |
+ |
|
49 |
+ |
|
50 |
+def main(): |
|
51 |
+ """ |
|
52 |
+ upt-tool main function. |
|
53 |
+ Parse command line arguments and execute selected action. |
|
54 |
+ """ |
|
55 |
+ args = parse_args() |
|
56 |
+ args.func(args) |
... | ... |
@@ -19,6 +19,8 @@ upt-trace out.proto "$SCRIPT_DIR/traceme.bash" |
19 | 19 |
|
20 | 20 |
ls -l out.proto |
21 | 21 |
|
22 |
-upt-dump out.proto | tee out.dump |
|
22 |
+upt-tool out.proto dump | tee out.dump |
|
23 | 23 |
grep '^ *event *{ *$' out.dump | wc -l | tee out.event_cnt |
24 | 24 |
grep '^6$' out.event_cnt |
25 |
+ |
|
26 |
+upt-tool out.proto parse |
... | ... |
@@ -20,7 +20,9 @@ upt-trace out.proto "$SCRIPT_DIR/run_build.bash" "$SOURCE_DIR" |
20 | 20 |
|
21 | 21 |
ls -l out.proto |
22 | 22 |
|
23 |
-upt-dump out.proto | tee out.dump |
|
23 |
+upt-tool out.proto dump | tee out.dump |
|
24 | 24 |
grep -A 1 '^ *cmdline {$' out.dump | grep '^ *s: "mkdir"$' |
25 | 25 |
grep '^ *s: "proc_begin.c"$' out.dump |
26 | 26 |
grep '^ *s: "libuptpl.so"$' out.dump |
27 |
+ |
|
28 |
+upt-tool out.proto parse |
... | ... |
@@ -1,16 +0,0 @@ |
1 |
-add_custom_command( |
|
2 |
- OUTPUT |
|
3 |
- ${CMAKE_BINARY_DIR}/bin/upt-dump |
|
4 |
- DEPENDS |
|
5 |
- ${CMAKE_CURRENT_SOURCE_DIR}/upt-dump.py |
|
6 |
- COMMAND |
|
7 |
- cp -a ${CMAKE_CURRENT_SOURCE_DIR}/upt-dump.py |
|
8 |
- ${CMAKE_BINARY_DIR}/bin/upt-dump |
|
9 |
-) |
|
10 |
- |
|
11 |
-add_custom_target( |
|
12 |
- upt-dump |
|
13 |
- ALL |
|
14 |
- DEPENDS |
|
15 |
- ${CMAKE_BINARY_DIR}/bin/upt-dump |
|
16 |
-) |
... | ... |
@@ -1,23 +0,0 @@ |
1 |
-#! /usr/bin/env python3 |
|
2 |
- |
|
3 |
-import argparse |
|
4 |
-import sys |
|
5 |
-import uproctrace.dump |
|
6 |
- |
|
7 |
- |
|
8 |
-def parse_args(): |
|
9 |
- parser = argparse.ArgumentParser(description='dump uproctrace trace') |
|
10 |
- parser.add_argument('trace', help='trace file') |
|
11 |
- args = parser.parse_args() |
|
12 |
- return args |
|
13 |
- |
|
14 |
- |
|
15 |
-def main(): |
|
16 |
- args = parse_args() |
|
17 |
- with open(args.trace, 'rb') as f: |
|
18 |
- while uproctrace.dump.dump_event(f, sys.stdout): |
|
19 |
- pass |
|
20 |
- |
|
21 |
- |
|
22 |
-if __name__ == '__main__': |
|
23 |
- main() |
... | ... |
@@ -0,0 +1,16 @@ |
1 |
+add_custom_command( |
|
2 |
+ OUTPUT |
|
3 |
+ ${CMAKE_BINARY_DIR}/bin/upt-tool |
|
4 |
+ DEPENDS |
|
5 |
+ ${CMAKE_CURRENT_SOURCE_DIR}/upt-tool.py |
|
6 |
+ COMMAND |
|
7 |
+ cp -a ${CMAKE_CURRENT_SOURCE_DIR}/upt-tool.py |
|
8 |
+ ${CMAKE_BINARY_DIR}/bin/upt-tool |
|
9 |
+) |
|
10 |
+ |
|
11 |
+add_custom_target( |
|
12 |
+ upt-tool |
|
13 |
+ ALL |
|
14 |
+ DEPENDS |
|
15 |
+ ${CMAKE_BINARY_DIR}/bin/upt-tool |
|
16 |
+) |