-
Notifications
You must be signed in to change notification settings - Fork 3
/
inspector
executable file
·103 lines (82 loc) · 2.76 KB
/
inspector
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
###################################################
# Load Inspector
# Author: Rahul Bera ([email protected])
###################################################
import argparse
import os
import sys
def add_arguments(parser):
parser.add_argument(
"-o",
"--output",
type=str,
default="inspector",
help="Output file name",
)
parser.add_argument(
"--dump-loads",
type=bool,
default=False,
help="Dump stable load IPs in a file",
)
parser.add_argument(
"--start-icount",
type=int,
default=False,
help="Start profiling when instruction count hits the given value",
)
parser.add_argument(
"--instr-length",
type=int,
default=0,
help="End profiling after the given instructions have committed",
)
parser.add_argument(
"--post-process",
type=bool,
default=False,
help="Post-process the stats into charts",
)
#########################
# MAIN
#########################
parser = argparse.ArgumentParser()
add_arguments(parser)
if "-h" in sys.argv or "--help" in sys.argv:
parser.print_help()
exit()
loc = sys.argv.index("--")
target_exe_knobs = sys.argv[loc:]
args = parser.parse_args(args=sys.argv[1:loc])
if "SDE_BUILD_KIT" not in os.environ:
print("env[SDE_BUILD_KIT] is not set. Have you sourced setvars.sh?")
exit(1)
if "INSPECTOR_HOME" not in os.environ:
print("env[INSPECTOR_HOME] is not set. Have you sourced setvars.sh?")
exit(1)
base_command = (os.environ['SDE_BUILD_KIT'] + "/sde64"
+ " " + "-future -t64"
+ " " + os.environ['INSPECTOR_HOME'] + "/src/obj-intel64/inspector-tool.so"
)
if args.output:
base_command += " -statf " + args.output + ".stats.txt"
if args.dump_loads:
base_command += " -dsl 1"
if args.output:
base_command += " -slf " + args.output + ".ips.txt"
if args.start_icount:
base_command += " -control start:icount:" + str(args.start_icount) + ":global"
if args.instr_length:
end_icount = int(args.start_icount) + int(args.instr_length)
base_command += " -control stop:icount:" + str(end_icount) + ":global"
if args.start_icount or args.instr_length:
base_command += " -controller_log 1"
final_command = base_command + " -- " + ' '.join(target_exe_knobs[1:])
print(f'Executing command: {final_command}')
os.system(final_command)
if args.post_process:
print("Starting post-processing...")
postprocess_command = "python " + os.environ['INSPECTOR_HOME'] + "/tools/postprocess.py -i " + args.output + ".stats.txt" + " -o " + args.output + ".postprocess.png"
print("Command: {}".format(postprocess_command))
os.system(postprocess_command)