MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / parse_nvtx_pushpop_trace_json

Function parse_nvtx_pushpop_trace_json

bench/python/benchmark.py:76–143  ·  view source on GitHub ↗

Parses the nvtx_pushpop_trace JSON generated by NSYS and returns a dictionary keyed by process_id, thread_id and range_id. The values are various fields important to the benchmarking process. :param json_path: Full path to the nvtx_pushpop_trace.json file.

(json_path)

Source from the content-addressed store, hash-verified

74
75
76def parse_nvtx_pushpop_trace_json(json_path):
77 """
78 Parses the nvtx_pushpop_trace JSON generated by NSYS and returns a dictionary
79 keyed by process_id, thread_id and range_id. The values are various fields
80 important to the benchmarking process.
81 :param json_path: Full path to the nvtx_pushpop_trace.json file.
82 """
83 #
84 # The nvtx_pushpop_trace JSON has the following structure. It is a list of
85 # dictionaries.
86 # e.g.
87 # [ {
88 # "Start (ns)": 2372801266,
89 # "End (ns)" : 13528369268,
90 # ...
91 # },
92 # ...
93 # ]
94 #
95 # We will store the parsed data in the range_info dictionary. The overall
96 # structure of the dictionary is:
97 # range_info = {
98 # process_id : {
99 # thread_id : {
100 # range_id : NvtxRange(flat_name, parent_range_id, duration_ms)
101 # }
102 # }
103 # }
104 #
105 #
106 range_info = {}
107
108 # Check if the file was empty or not. Empty file means no ops were recorded.
109 if os.stat(json_path).st_size == 0:
110 return range_info
111
112 # Read the JSON.
113 with open(json_path, "r") as f:
114 json_data = json.loads(f.read())
115
116 for row in json_data:
117 # Grab the necessary values from the JSON file.
118 flat_name = row["Name"]
119 start_ns = float(row["Start (ns)"])
120 end_ns = float(row["End (ns)"])
121 range_id = row["RangeId"]
122 parent_range_id = row["ParentId"]
123 process_id = row["PID"]
124 thread_id = row["TID"]
125
126 # Process a bit. Conversion from nano to milliseconds.
127 start_ms = round(start_ns / 10**6, 4)
128 end_ms = round(end_ns / 10**6, 4)
129 parent_range_id = None if parent_range_id == "None" else parent_range_id
130
131 # Save it in our dictionary at the process id and thread id level.
132 if process_id not in range_info:
133 range_info[process_id] = {}

Callers 1

benchmark_scriptFunction · 0.85

Calls 3

roundFunction · 0.85
NvtxRangeTimeInfoClass · 0.85
NvtxRangeClass · 0.85

Tested by

no test coverage detected