Skip to content

Commit ade6b71

Browse files
committed
ENH: MeasureStartupTimes: Add --display-slicer-output option
git-svn-id: http://svn.slicer.org/Slicer4/trunk@25132 3bd1e089-480b-0410-8dfb-8563597acbee
1 parent a3f8090 commit ade6b71

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

Applications/SlicerApp/Testing/Python/MeasureStartupTimes.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ def TemporaryPythonScript(code, *args, **kwargs):
4242
print("Written script %s [%s]" % (script.name, code))
4343
return script
4444

45-
def collect_startup_times_normal(output_file, drop_cache=False):
45+
def collect_startup_times_normal(output_file, drop_cache=False, display_output=False):
4646
results= {}
4747
test = []
4848
(duration, result) = runSlicerAndExitWithTime(slicer_executable, test, drop_cache=drop_cache)
49+
(returnCode, stdout, stderr) = result
50+
if display_output:
51+
if stdout: print("STDOUT [%s]\n" % stdout)
52+
if stderr and returnCode == EXIT_SUCCESS: print("STDERR [%s]\n" % stderr)
4953
results[" ".join(test)] = duration
5054
with open(output_file, 'w') as file:
5155
file.write(json.dumps(results, indent=4))
5256

53-
def collect_startup_times_overall(output_file, drop_cache=False):
57+
def collect_startup_times_overall(output_file, drop_cache=False, display_output=False):
5458

5559
tests = [
5660
[],
@@ -72,6 +76,11 @@ def collect_startup_times_overall(output_file, drop_cache=False):
7276
(duration, result) = runSlicerAndExitWithTime(slicer_executable, test, drop_cache=drop_cache)
7377
results[" ".join(test)] = duration
7478

79+
(returnCode, stdout, stderr) = result
80+
if display_output:
81+
if stdout: print("STDOUT [%s]\n" % stdout)
82+
if stderr and returnCode == EXIT_SUCCESS: print("STDERR [%s]\n" % stderr)
83+
7584
with open(output_file, 'w') as file:
7685
file.write(json.dumps(results, indent=4))
7786

@@ -116,7 +125,7 @@ def collect_modules(output_file='Modules.json'):
116125

117126
return read_modules(output_file)
118127

119-
def collect_startup_times_including_one_module(output_file, drop_cache=False):
128+
def collect_startup_times_including_one_module(output_file, drop_cache=False, display_output=False):
120129
modules = collect_modules()
121130
# Collect startup times disabling each module one by one
122131
moduleTimes = {}
@@ -127,6 +136,9 @@ def collect_startup_times_including_one_module(output_file, drop_cache=False):
127136
test = ['--testing', '--modules-to-ignore', ",".join(modules_minus_one)]
128137
(duration, result) = runSlicerAndExitWithTime(slicer_executable, test, drop_cache=drop_cache)
129138
(returnCode, stdout, stderr) = result
139+
if display_output:
140+
if stdout: print("STDOUT [%s]\n" % stdout)
141+
if stderr and returnCode == EXIT_SUCCESS: print("STDERR [%s]\n" % stderr)
130142
if returnCode != EXIT_SUCCESS:
131143
# XXX Ignore module with dependencies
132144
duration = None
@@ -137,7 +149,7 @@ def collect_startup_times_including_one_module(output_file, drop_cache=False):
137149
with open(output_file, 'w') as file:
138150
file.write(json.dumps(moduleTimes, indent=4))
139151

140-
def collect_startup_times_excluding_one_module(output_file, drop_cache=False):
152+
def collect_startup_times_excluding_one_module(output_file, drop_cache=False, display_output=False):
141153
modules = collect_modules()
142154
# Collect startup times disabling each module one by one
143155
moduleTimes = {}
@@ -148,6 +160,9 @@ def collect_startup_times_excluding_one_module(output_file, drop_cache=False):
148160
print("[%d/%d]" % (idx, len(modules)))
149161
(duration, result) = runSlicerAndExitWithTime(slicer_executable, ['--testing', '--modules-to-ignore', moduleName], drop_cache=drop_cache)
150162
(returnCode, stdout, stderr) = result
163+
if display_output:
164+
if stdout: print("STDOUT [%s]\n" % stdout)
165+
if stderr and returnCode == EXIT_SUCCESS: print("STDERR [%s]\n" % stderr)
151166
if returnCode != EXIT_SUCCESS:
152167
# XXX Ignore module with dependencies
153168
duration = None
@@ -158,7 +173,7 @@ def collect_startup_times_excluding_one_module(output_file, drop_cache=False):
158173
with open(output_file, 'w') as file:
159174
file.write(json.dumps(moduleTimes, indent=4))
160175

161-
def collect_startup_times_modules_to_load(output_file, modules_to_load, drop_cache=False):
176+
def collect_startup_times_modules_to_load(output_file, modules_to_load, drop_cache=False, display_output=False):
162177
modules = collect_modules()
163178
modulesToIgnore = list(modules.keys())
164179
for moduleName in modules_to_load.split(","):
@@ -167,6 +182,10 @@ def collect_startup_times_modules_to_load(output_file, modules_to_load, drop_cac
167182

168183
test = ['--testing', '--modules-to-ignore', ",".join(modulesToIgnore)]
169184
(duration, result) = runSlicerAndExitWithTime(slicer_executable, test, drop_cache=drop_cache)
185+
(returnCode, stdout, stderr) = result
186+
if display_output:
187+
if stdout: print("STDOUT [%s]\n" % stdout)
188+
if stderr and returnCode == EXIT_SUCCESS: print("STDERR [%s]\n" % stderr)
170189

171190
results= {}
172191
results[" ".join(modulesToIgnore)] = duration
@@ -186,6 +205,7 @@ def collect_startup_times_modules_to_load(output_file, modules_to_load, drop_cac
186205
parser.add_argument("-n", "--repeat", default=1, type=int)
187206
parser.add_argument("--drop-cache", action="store_true")
188207
parser.add_argument("--reuse-module-list", action="store_true")
208+
parser.add_argument("--display-slicer-output", action="store_true")
189209
parser.add_argument("/path/to/Slicer")
190210
args = parser.parse_args()
191211

@@ -202,21 +222,29 @@ def collect_startup_times_modules_to_load(output_file, modules_to_load, drop_cac
202222
print("Loading existing module listing")
203223
collect_modules = read_modules
204224

225+
common_kwargs = {
226+
'display_output': args.display_slicer_output,
227+
'drop_cache': args.drop_cache
228+
}
229+
205230
# Since the "normal" experiment is included in the "overall" one,
206231
# it is not executed by default.
207232
if args.normal:
208-
collect_startup_times_normal("StartupTimesNormal.json", drop_cache=args.drop_cache)
233+
collect_startup_times_normal("StartupTimesNormal.json", **common_kwargs)
209234

210235
# Since the "modules-to-load" experiment requires user input and is provided
211236
# for convenience, it is not executed by default.
212237
if args.modules_to_load:
213-
collect_startup_times_modules_to_load("StartupTimesSelectedModules.json", args.modules_to_load, drop_cache=args.drop_cache)
238+
collect_startup_times_modules_to_load(
239+
"StartupTimesSelectedModules.json", args.modules_to_load, **common_kwargs)
214240

215241
if all or args.overall:
216-
collect_startup_times_overall("StartupTimes.json", drop_cache=args.drop_cache)
242+
collect_startup_times_overall("StartupTimes.json", **common_kwargs)
217243

218244
if all or args.excluding_one_module:
219-
collect_startup_times_excluding_one_module("StartupTimesExcludingOneModule.json", drop_cache=args.drop_cache)
245+
collect_startup_times_excluding_one_module(
246+
"StartupTimesExcludingOneModule.json", **common_kwargs)
220247

221248
if all or args.including_one_module:
222-
collect_startup_times_including_one_module("StartupTimesIncludingOneModule.json", drop_cache=args.drop_cache)
249+
collect_startup_times_including_one_module(
250+
"StartupTimesIncludingOneModule.json", **common_kwargs)

0 commit comments

Comments
 (0)