Skip to content

Commit ca05bbb

Browse files
Fix formatting issue
1 parent c547514 commit ca05bbb

File tree

1 file changed

+69
-16
lines changed

1 file changed

+69
-16
lines changed

python/kvikio/examples/kvikio_stat.py

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
22
# See file LICENSE for terms.
33

4-
import sqlite3
5-
import pandas as pd
6-
import numpy as np
7-
import subprocess
84
import argparse
9-
import pathlib
105
import os
6+
import pathlib
7+
import sqlite3
8+
import subprocess
9+
10+
import numpy as np
11+
import pandas as pd
1112

1213

1314
class Analyzer:
15+
"""_summary_
16+
"""
17+
1418
def __init__(self, args: argparse.Namespace):
19+
"""_summary_
20+
21+
:param args: _description_
22+
:type args: argparse.Namespace
23+
"""
1524
self.nsys_report_path = args.nsys_report_path
1625

1726
self.sql_path = None
@@ -28,9 +37,12 @@ def __init__(self, args: argparse.Namespace):
2837
self.nsys_binary = args.nsys_binary
2938

3039
def _export_report_to_sqlite(self):
40+
"""_summary_
41+
"""
3142
full_cmd_str = (
3243
f"{self.nsys_binary} export --type=sqlite --lazy=false "
33-
+ f"--force-overwrite=true --output={self.sql_path} {self.nsys_report_path} "
44+
+ f"--force-overwrite=true --output={self.sql_path} "
45+
+ f"{self.nsys_report_path} "
3446
+ "--tables=StringIds,NVTX_EVENTS"
3547
)
3648
full_cmd_list = full_cmd_str.split()
@@ -40,15 +52,17 @@ def _export_report_to_sqlite(self):
4052
def _initialize_bins(self):
4153
"""Create bins ranging from 0 B to 512 PiB"""
4254

43-
tmp = np.logspace(start=0, stop=59, num=60, base=2,
44-
dtype=np.float64) # 2^0 2^1 ... 2^59
55+
tmp = np.logspace(
56+
start=0, stop=59, num=60, base=2, dtype=np.float64
57+
) # 2^0 2^1 ... 2^59
4558
self.bin_full = np.insert(tmp, 0, 0.0) # 0 2^0 2^1 ... 2^59
4659
self.bin_full_in_MiB = self.bin_full / 1024.0 / 1024.0
4760

4861
def _sql_query(self, filter_string: str) -> pd.DataFrame:
4962
"""Perform SQL query.
50-
The SQLite schema in nsys is not forward compatible, and may change completely in a new release.
51-
Refer to https://docs.nvidia.com/nsight-systems/UserGuide/index.html?highlight=schema#sqlite-schema-reference
63+
The SQLite schema in nsys is not forward compatible, and may change completely
64+
in a new release. Refer to
65+
https://docs.nvidia.com/nsight-systems/UserGuide/index.html?highlight=schema#sqlite-schema-reference
5266
5367
:param filter_string: NVTX annotation string serving as a filter for the query.
5468
:type filter_string: str
@@ -85,6 +99,13 @@ def _sql_query(self, filter_string: str) -> pd.DataFrame:
8599
return df
86100

87101
def _generate_hist(self, df: pd.DataFrame) -> tuple[np.ndarray, np.ndarray]:
102+
"""_summary_
103+
104+
:param df: _description_
105+
:type df: pd.DataFrame
106+
:return: _description_
107+
:rtype: tuple[np.ndarray, np.ndarray]
108+
"""
88109
my_series = df["ioSize"]
89110

90111
# Determine the appropriate bins for the histogram
@@ -101,6 +122,14 @@ def _generate_hist(self, df: pd.DataFrame) -> tuple[np.ndarray, np.ndarray]:
101122
return np.histogram(my_series, tight_bin_edges)
102123

103124
def _get_compact_filesize(self, file_size_inB: np.float64) -> str:
125+
"""_summary_
126+
127+
:param file_size_inB: _description_
128+
:type file_size_inB: np.float64
129+
:raises Exception: _description_
130+
:return: _description_
131+
:rtype: str
132+
"""
104133
KiB = 1024.0
105134
MiB = 1024.0 * KiB
106135
GiB = 1024.0 * MiB
@@ -124,6 +153,15 @@ def _get_compact_filesize(self, file_size_inB: np.float64) -> str:
124153
raise Exception("Invalid value for file_size.")
125154

126155
def _print(self, title, hist, bin_edges):
156+
"""_summary_
157+
158+
:param title: _description_
159+
:type title: _type_
160+
:param hist: _description_
161+
:type hist: _type_
162+
:param bin_edges: _description_
163+
:type bin_edges: _type_
164+
"""
127165
print(f"\n{title}")
128166
print(" Bins ...... Count")
129167
for idx in range(len(hist)):
@@ -141,6 +179,11 @@ def _print(self, title, hist, bin_edges):
141179
)
142180

143181
def _process(self, filter_string: str):
182+
"""_summary_
183+
184+
:param filter_string: _description_
185+
:type filter_string: str
186+
"""
144187
df = self._sql_query(filter_string)
145188
if df.empty:
146189
return
@@ -149,6 +192,8 @@ def _process(self, filter_string: str):
149192
self._print(filter_string, hist, bin_edges)
150193

151194
def run(self):
195+
"""_summary_
196+
"""
152197
self._initialize_bins()
153198

154199
self._export_report_to_sqlite()
@@ -173,19 +218,27 @@ def run(self):
173218

174219
if __name__ == "__main__":
175220
parser = argparse.ArgumentParser(
176-
prog="kvikio_stat", description="Generate I/O size histogram from Nsight System report"
221+
prog="kvikio_stat",
222+
description="Generate I/O size histogram from Nsight System report",
223+
)
224+
parser.add_argument(
225+
"--nsys-report-path",
226+
required=True,
227+
help="The path of the Nsight System report.",
228+
type=str,
177229
)
178-
parser.add_argument("--nsys-report-path", required=True,
179-
help="The path of the Nsight System report.", type=str)
180230
parser.add_argument(
181231
"--sql-path",
182232
help="The path of the SQL database exported from the Nsight System report. "
183-
+ "If unspecified, the current working directory is used to store the SQL database, "
184-
+ "and the file name is derived from the Nsight System report.",
233+
+ "If unspecified, the current working directory is used to store the SQL "
234+
+ "database, and the file name is derived from the Nsight System report.",
185235
type=str,
186236
)
187237
parser.add_argument(
188-
"--nsys-binary", help='The path of the Nsight System CLI program. If unspecified, "nsys" is used.', type=str
238+
"--nsys-binary",
239+
help='The path of the Nsight System CLI program. If unspecified, "nsys" is '
240+
+ "used.",
241+
type=str,
189242
)
190243
args = parser.parse_args()
191244

0 commit comments

Comments
 (0)