Skip to content

Commit afb131f

Browse files
committed
used black to reformat python files
1 parent 7bc41d8 commit afb131f

File tree

5 files changed

+218
-199
lines changed

5 files changed

+218
-199
lines changed

source/utils/profiler/scripts/common.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
import parseMe
33
import os
44

5+
56
def saveMe(figName):
6-
parentDir=os.path.dirname(figName)
7+
parentDir = os.path.dirname(figName)
78

89
plt.tight_layout()
9-
#print (figName)
10-
if (os.path.isdir(parentDir)):
10+
# print (figName)
11+
if os.path.isdir(parentDir):
1112
plt.savefig(figName)
1213
else:
13-
if (len(parentDir) > 1):
14-
print ("Missing directory! Can not save plot to dir:", parentDir)
14+
if len(parentDir) > 1:
15+
print("Missing directory! Can not save plot to dir:", parentDir)
1516
else:
16-
plt.savefig(figName)
17-
17+
plt.savefig(figName)
18+
1819
showFig = parseMe.command_options[parseMe.TAGS["showfig"]]
19-
if (showFig):
20+
if showFig:
2021
plt.show()
21-
22-
23-
24-
25-

source/utils/profiler/scripts/parseMe.py

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,61 @@
22

33
import argparse, textwrap
44
import os
5-
parser = argparse.ArgumentParser(description="ADIOS json file parser step 2 (step 1 is use compare.sh to collect properties from json)")
6-
7-
TAGS={
8-
"input_dir": "dataDir", ## key name for input direcory is "dataDir"
9-
"rank": "whichRank", ##
10-
"out": "plotPrefix", ##
11-
"showfig": "showFig", ##
12-
"attr": "jsonAttr", ## key refer to specific json attr
13-
"zero": "zeroIf", ## key refer to a min number to be treated as 0. Spot the first rank with this value, and only plot up to this rank.
14-
"level": "levelAxis"
15-
}
16-
17-
TAGS_DEFAULT={
18-
"input_dir": "outs/", ## key name for input direcory defaults to "outs/"
19-
"rank": 0, ##
20-
"out": "plot", ##
21-
"showfig": 'False', ##
22-
"attr": "ES", ## default json attr to look at is ES
23-
"zero": "0.000001", ## ignore if smaller than
24-
"level": 'False' ## whether left/right axises (if both exist) should display same range
25-
}
26-
27-
parser.add_argument("ioTypes",
28-
nargs="+",
29-
help="A list of known adios types in the output directory.\n"
30-
"Will be accessed as ["+TAGS["input_dir"]+"]/[ioType]_<secs/nCalls>_[profileTag]"
31-
"e.g. outs/flatten_nCalls_ES")
32-
33-
helpWithDefaults=""
5+
6+
parser = argparse.ArgumentParser(
7+
description="ADIOS json file parser step 2 (step 1 is use compare.sh to collect properties from json)"
8+
)
9+
10+
TAGS = {
11+
"input_dir": "dataDir", ## key name for input direcory is "dataDir"
12+
"rank": "whichRank", ##
13+
"out": "plotPrefix", ##
14+
"showfig": "showFig", ##
15+
"attr": "jsonAttr", ## key refer to specific json attr
16+
"zero": "zeroIf", ## key refer to a min number to be treated as 0. Spot the first rank with this value, and only plot up to this rank.
17+
"level": "levelAxis",
18+
}
19+
20+
TAGS_DEFAULT = {
21+
"input_dir": "outs/", ## key name for input direcory defaults to "outs/"
22+
"rank": 0, ##
23+
"out": "plot", ##
24+
"showfig": "False", ##
25+
"attr": "ES", ## default json attr to look at is ES
26+
"zero": "0.000001", ## ignore if smaller than
27+
"level": "False", ## whether left/right axises (if both exist) should display same range
28+
}
29+
30+
parser.add_argument(
31+
"ioTypes",
32+
nargs="+",
33+
help="A list of known adios types in the output directory.\n"
34+
"Will be accessed as [" + TAGS["input_dir"] + "]/[ioType]_<secs/nCalls>_[profileTag]"
35+
"e.g. outs/flatten_nCalls_ES",
36+
)
37+
38+
helpWithDefaults = ""
3439
for k in TAGS:
35-
helpWithDefaults += TAGS[k] + "(default: "+ str(TAGS_DEFAULT[k])+") "
36-
37-
parser.add_argument("--set",
38-
metavar="key=value",
39-
nargs='+',
40-
help="Accepted options:\n" + helpWithDefaults
41-
)
40+
helpWithDefaults += TAGS[k] + "(default: " + str(TAGS_DEFAULT[k]) + ") "
41+
42+
parser.add_argument(
43+
"--set", metavar="key=value", nargs="+", help="Accepted options:\n" + helpWithDefaults
44+
)
4245
args = parser.parse_args()
4346

44-
#print (args.set)
45-
#print (args.file_key)
47+
# print (args.set)
48+
# print (args.file_key)
49+
4650

4751
def parse_var(s):
4852
"""
4953
Parse a key, value pair, separated by '=' into a tuple
5054
"""
51-
items = s.split('=')
52-
key = items[0].strip() # we remove blanks around keys, as is logical
55+
items = s.split("=")
56+
key = items[0].strip() # we remove blanks around keys, as is logical
5357
if len(items) > 1:
5458
# rejoin the rest:
55-
value = '='.join(items[1:])
59+
value = "=".join(items[1:])
5660
return (key, value)
5761

5862

@@ -68,21 +72,22 @@ def parse_vars(items):
6872
d[key] = value
6973
return d
7074

75+
7176
# parse the key-value pairs
7277

7378
command_options = parse_vars(args.set)
7479

7580
for k in TAGS:
7681
if TAGS[k] not in command_options:
77-
command_options[TAGS[k]] = TAGS_DEFAULT[k]
78-
79-
if (not command_options[TAGS["input_dir"]].endswith("/")):
80-
command_options[TAGS["input_dir"]]+="/"
82+
command_options[TAGS[k]] = TAGS_DEFAULT[k]
83+
84+
if not command_options[TAGS["input_dir"]].endswith("/"):
85+
command_options[TAGS["input_dir"]] += "/"
8186
if not os.path.isdir(command_options[TAGS["input_dir"]]):
8287
parser.error(f"Input directory '{command_options[TAGS['input_dir']]}' does not exist")
8388

84-
#command_options[TAGS["rank"]] = int(command_options[TAGS["rank"]])
85-
#command_options[TAGS["zero"]] = float(command_options[TAGS["zero"]])
89+
# command_options[TAGS["rank"]] = int(command_options[TAGS["rank"]])
90+
# command_options[TAGS["zero"]] = float(command_options[TAGS["zero"]])
8691
try:
8792
command_options[TAGS["rank"]] = int(command_options[TAGS["rank"]])
8893
if command_options[TAGS["rank"]] < 0:
@@ -97,7 +102,7 @@ def parse_vars(items):
97102
except ValueError:
98103
parser.error(f"Zero threshold must be a number, got '{command_options[TAGS['zero']]}'")
99104

100-
105+
101106
# Safely convert levelAxis to boolean
102107
level_val = command_options[TAGS["level"]].lower()
103108
if level_val not in ("true", "false"):
@@ -110,12 +115,12 @@ def parse_vars(items):
110115
parser.error(f"showFig must be 'True' or 'False', got '{command_options[TAGS['level']]}'")
111116
command_options[TAGS["showfig"]] = showFig_val == "true"
112117

113-
#command_options[TAGS["level"]] = eval(command_options[TAGS["level"]])
118+
# command_options[TAGS["level"]] = eval(command_options[TAGS["level"]])
114119

115-
#valid_keys = set(TAGS.values())
116-
#for key in command_options:
120+
# valid_keys = set(TAGS.values())
121+
# for key in command_options:
117122
# if key not in valid_keys:
118123
# parser.warn(f"Invalid option key: '{key}'. Valid keys are: {', '.join(valid_keys)}")
119124
#### allow extra options ####
120125

121-
#print (command_options)
126+
# print (command_options)

source/utils/profiler/scripts/plotCall.py

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,76 +7,84 @@
77
import os
88
import common
99
import parseMe
10+
1011
# Sample data
1112

13+
1214
def plotBars(ax, ticklabels, summary, timeDesc=""):
13-
barWidth=0.3
15+
barWidth = 0.3
1416
dataSize = len(summary[parseMe.args.ioTypes[0]])
1517
br = {0: np.arange(dataSize)}
1618
for i in range(1, dataSize):
17-
br[i] = [x + barWidth for x in br[i-1]]
19+
br[i] = [x + barWidth for x in br[i - 1]]
1820

1921
for i, which in enumerate(parseMe.args.ioTypes):
2022
ax.bar(br[i], summary[which], 0.3, label=which)
21-
22-
ax.set_ylabel('NumCalls')
23-
ax.set_title('ADIOS numCalls:'+timeDesc)
23+
24+
ax.set_ylabel("NumCalls")
25+
ax.set_title("ADIOS numCalls:" + timeDesc)
2426

2527
ax.set_xticks([r + barWidth for r in range(dataSize)], ticklabels)
26-
28+
2729
# Add legend
2830
ax.legend()
2931

32+
3033
def summarizeFile(inputFile):
3134
try:
32-
with open(inputFile, 'r') as f:
33-
data = csv.reader(f, delimiter=",", quotechar='|')
35+
with open(inputFile, "r") as f:
36+
data = csv.reader(f, delimiter=",", quotechar="|")
3437
data1 = [float(row[0]) for row in data if row] # Handle empty rows
3538
return int(data1[0]) if data1 else 0 ## num of calls are the same for all ranks
3639
except (FileNotFoundError, IndexError, ValueError) as e:
3740
print(f"Warning: Could not process {inputFile}: {e}")
3841
return 0
3942

40-
if __name__ == "__main__":
43+
44+
if __name__ == "__main__":
4145
print("Script name:", sys.argv[0])
4246
if len(sys.argv) < 2:
43-
print("Need Arguments for files" )
47+
print("Need Arguments for files")
4448
sys.exit()
4549

46-
found_async = [item for item in parseMe.args.ioTypes if 'async' in item.lower()]
47-
48-
if (found_async):
49-
keywords = ['PP', 'PDW', 'ES', 'BS_WaitOnAsync', 'DC_WaitOnAsync1', 'DC_WaitOnAsync2']
50-
ticklabels= ['PP', 'PDW', 'ES', 'BS\nWaitOn\nAsync', 'DC\nWaitOn\nAsync1', 'DC\nWaitOn\nAsync2']
50+
found_async = [item for item in parseMe.args.ioTypes if "async" in item.lower()]
51+
52+
if found_async:
53+
keywords = ["PP", "PDW", "ES", "BS_WaitOnAsync", "DC_WaitOnAsync1", "DC_WaitOnAsync2"]
54+
ticklabels = [
55+
"PP",
56+
"PDW",
57+
"ES",
58+
"BS\nWaitOn\nAsync",
59+
"DC\nWaitOn\nAsync1",
60+
"DC\nWaitOn\nAsync2",
61+
]
5162
else:
52-
keywords = ['PP', 'PDW', 'ES']
53-
ticklabels= ['PP', 'PDW', 'ES']
54-
63+
keywords = ["PP", "PDW", "ES"]
64+
ticklabels = ["PP", "PDW", "ES"]
65+
5566
summary = {key: [] for key in parseMe.args.ioTypes}
56-
#barLabels = list(parseMe.args.ioTypes)
57-
67+
# barLabels = list(parseMe.args.ioTypes)
68+
5869
fig, ax1 = plt.subplots()
5970

6071
for which in parseMe.args.ioTypes:
6172
for key in keywords:
62-
inputFile=parseMe.command_options[parseMe.TAGS["input_dir"]]+which+"_nCalls_"+key
63-
if (os.path.exists(inputFile)):
64-
summary[which].append( summarizeFile(inputFile) )
73+
inputFile = (
74+
parseMe.command_options[parseMe.TAGS["input_dir"]] + which + "_nCalls_" + key
75+
)
76+
if os.path.exists(inputFile):
77+
summary[which].append(summarizeFile(inputFile))
6578
else:
66-
summary[which].append( 0 )
79+
summary[which].append(0)
6780

68-
if (len(summary[parseMe.args.ioTypes[0]]) == 0):
69-
print ("Nothing to plot")
81+
if len(summary[parseMe.args.ioTypes[0]]) == 0:
82+
print("Nothing to plot")
7083
sys.exit()
7184

7285
plotBars(ax1, ticklabels, summary)
7386
plt.legend()
7487

7588
# Show plot
76-
figName = parseMe.command_options[parseMe.TAGS["out"]] +"_nCalls"
89+
figName = parseMe.command_options[parseMe.TAGS["out"]] + "_nCalls"
7790
common.saveMe(figName)
78-
79-
80-
81-
82-

0 commit comments

Comments
 (0)