@@ -244,65 +244,68 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok
244
244
}
245
245
}
246
246
247
- // Run Workload
248
247
DateTime startTime = DateTime . UtcNow ;
249
- foreach ( string definition in this . Definitions )
248
+ using ( BackgroundOperations profiling = BackgroundOperations . BeginProfiling ( this , cancellationToken ) )
250
249
{
251
- this . OutFileName = $ "{ DateTimeOffset . Now . ToUnixTimeSeconds ( ) } .out";
252
-
253
- // Workload execution
254
- string arguments = this . GenerateCommandArguments ( definition ) ;
255
- string commandArguments = $ "{ baseArg } { this . ExecutablePath } { arguments } ";
256
-
257
- using ( IProcessProxy process = this . systemManagement . ProcessManager . CreateProcess ( psexec , commandArguments , this . psexecDir ) )
250
+ // Run Workload
251
+ foreach ( string definition in this . Definitions )
258
252
{
259
- this . CleanupTasks . Add ( ( ) => process . SafeKill ( ) ) ;
253
+ this . OutFileName = $ "{ DateTimeOffset . Now . ToUnixTimeSeconds ( ) } .out";
254
+
255
+ // Workload execution
256
+ string arguments = this . GenerateCommandArguments ( definition ) ;
257
+ string commandArguments = $ "{ baseArg } { this . ExecutablePath } { arguments } ";
260
258
261
- try
259
+ using ( IProcessProxy process = this . systemManagement . ProcessManager . CreateProcess ( psexec , commandArguments , this . psexecDir ) )
262
260
{
263
- await process . StartAndWaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
261
+ this . CleanupTasks . Add ( ( ) => process . SafeKill ( ) ) ;
264
262
265
- if ( ! cancellationToken . IsCancellationRequested )
263
+ try
266
264
{
267
- await this . LogProcessDetailsAsync ( process , telemetryContext ) ;
268
- process . ThrowIfErrored < WorkloadException > ( ProcessProxy . DefaultSuccessCodes , errorReason : ErrorReason . WorkloadFailed ) ;
265
+ await process . StartAndWaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
266
+
267
+ if ( ! cancellationToken . IsCancellationRequested )
268
+ {
269
+ await this . LogProcessDetailsAsync ( process , telemetryContext ) ;
270
+ process . ThrowIfErrored < WorkloadException > ( ProcessProxy . DefaultSuccessCodes , errorReason : ErrorReason . WorkloadFailed ) ;
269
271
272
+ }
270
273
}
271
- }
272
- finally
273
- {
274
- if ( ! process . HasExited )
274
+ finally
275
275
{
276
- process . Kill ( ) ;
276
+ if ( ! process . HasExited )
277
+ {
278
+ process . Kill ( ) ;
279
+ }
277
280
}
278
281
}
279
- }
280
282
281
- // Result Preparation
282
- string commandArguments2 = $ "{ baseArg } { this . ExecutablePath } --in={ this . OutFileName } --export=result.xml";
283
- using ( IProcessProxy process = this . systemManagement . ProcessManager . CreateProcess ( psexec , commandArguments2 , this . psexecDir ) )
284
- {
285
- this . CleanupTasks . Add ( ( ) => process . SafeKill ( ) ) ;
286
-
287
- try
283
+ // Result Preparation
284
+ string commandArguments2 = $ "{ baseArg } { this . ExecutablePath } --in={ this . OutFileName } --export=result.xml";
285
+ using ( IProcessProxy process = this . systemManagement . ProcessManager . CreateProcess ( psexec , commandArguments2 , this . psexecDir ) )
288
286
{
289
- await process . StartAndWaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
287
+ this . CleanupTasks . Add ( ( ) => process . SafeKill ( ) ) ;
290
288
291
- if ( ! cancellationToken . IsCancellationRequested )
289
+ try
292
290
{
293
- await this . LogProcessDetailsAsync ( process , telemetryContext ) ;
294
- process . ThrowIfErrored < WorkloadException > ( ProcessProxy . DefaultSuccessCodes , errorReason : ErrorReason . WorkloadFailed ) ;
295
- foreach ( Metric metric in this . CaptureResults ( process , commandArguments , definition , telemetryContext ) )
291
+ await process . StartAndWaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
292
+
293
+ if ( ! cancellationToken . IsCancellationRequested )
296
294
{
297
- metrics . Add ( metric ) ;
295
+ await this . LogProcessDetailsAsync ( process , telemetryContext ) ;
296
+ process . ThrowIfErrored < WorkloadException > ( ProcessProxy . DefaultSuccessCodes , errorReason : ErrorReason . WorkloadFailed ) ;
297
+ foreach ( Metric metric in this . CaptureResults ( process , commandArguments , definition , telemetryContext ) )
298
+ {
299
+ metrics . Add ( metric ) ;
300
+ }
298
301
}
299
302
}
300
- }
301
- finally
302
- {
303
- if ( ! process . HasExited )
303
+ finally
304
304
{
305
- process . Kill ( ) ;
305
+ if ( ! process . HasExited )
306
+ {
307
+ process . Kill ( ) ;
308
+ }
306
309
}
307
310
}
308
311
}
0 commit comments