-
Notifications
You must be signed in to change notification settings - Fork 5
/
NV2ALog.py
51 lines (41 loc) · 1.8 KB
/
NV2ALog.py
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
"""Manages the nv2a log file."""
# pylint: disable=invalid-name
# pylint: disable=consider-using-f-string
Nv2aLogMethodDetails = False
class NV2ALog:
"""Manages the nv2a log file."""
def __init__(self, path):
self.path = path
with open(self.path, "w", encoding="utf8") as logfile:
logfile.write("pgraph method log from nv2a-trace.py\n\n")
def log(self, message):
"""Append the given string to the nv2a log."""
with open(self.path, "a", encoding="utf8") as logfile:
logfile.write(message)
def log_method(self, method_info, data, pre_info, post_info):
"""Append a line describing the given pgraph call to the nv2a log."""
with open(self.path, "a", encoding="utf8") as logfile:
if data is not None:
data_str = "0x%X" % data
else:
data_str = "<NO_DATA>"
logfile.write(
"nv2a_pgraph_method %d: 0x%x -> 0x%x %s\n"
% (
method_info["subchannel"],
method_info["object"],
method_info["method"],
data_str,
)
)
if Nv2aLogMethodDetails:
logfile.write("Method info:\n")
logfile.write("Address: 0x%X\n" % method_info["address"])
logfile.write("Method: 0x%X\n" % method_info["method"])
logfile.write("Nonincreasing: %d\n" % method_info["nonincreasing"])
logfile.write("Subchannel: 0x%X\n" % method_info["subchannel"])
logfile.write("data:\n")
logfile.write(str(data))
logfile.write("\n\n")
logfile.write("pre_info: %s\n" % pre_info)
logfile.write("post_info: %s\n" % post_info)