@@ -18,6 +18,7 @@ namespace VirtualClient.Actions
1818 using VirtualClient . Common . Telemetry ;
1919 using VirtualClient . Contracts ;
2020 using VirtualClient . Contracts . Metadata ;
21+ using YamlDotNet . Serialization ;
2122
2223 /// <summary>
2324 /// Executes the OpenSSL workload.
@@ -90,17 +91,50 @@ await this.InitializeWorkloadToolsetsAsync(cancellationToken)
9091 . ConfigureAwait ( false ) ;
9192 }
9293
93- private void CaptureMetrics ( IProcessProxy workloadProcess , string commandArguments , EventContext telemetryContext )
94+ /// <summary>
95+ /// Gets openssl version by running openssl version command.
96+ /// </summary>
97+ private async Task GetOpenSslVersion ( CancellationToken cancellationToken , string toolCommand )
9498 {
95- if ( workloadProcess . ExitCode == 0 )
99+ // The OpenSSL version is not available in the workload output. We need to run a separate command to get the version.
100+ // The command 'openssl version' will return the version of OpenSSL installed on the system.
101+ string opensslVersion = "Unknown" ;
102+ if ( ! cancellationToken . IsCancellationRequested )
96103 {
97- try
104+ this . Logger . LogTraceMessage ( $ "Executing process 'openssl version' at directory '{ this . ExecutablePath } '.") ;
105+ using ( IProcessProxy process = this . systemManagement . ProcessManager . CreateProcess ( this . ExecutablePath , "version" ) )
98106 {
107+ this . SetEnvironmentVariables ( process ) ;
108+ await process . StartAndWaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
109+ process . ThrowIfWorkloadFailed ( ) ;
110+
111+ opensslVersion = process . StandardOutput ? . ToString ( ) . Trim ( ) ?? "Unknown" ;
112+ if ( string . IsNullOrWhiteSpace ( opensslVersion ) )
113+ {
114+ opensslVersion = "Unknown" ;
115+ }
116+
117+ this . MetadataContract . Add ( "OpenSSLVersion" , opensslVersion , MetadataContractCategory . Dependencies ) ;
118+ this . Logger . LogMessage ( $ "{ nameof ( OpenSslExecutor ) } .GetOpenSslVersion", LogLevel . Information , EventContext . Persisted ( ) . AddContext ( "opensslVersion" , opensslVersion ) ) ;
119+
99120 this . MetadataContract . AddForScenario (
100121 "OpenSSL Speed" ,
101- workloadProcess . FullCommand ( ) ,
102- toolVersion : null ) ;
122+ toolCommand ,
123+ toolVersion : opensslVersion ) ;
124+ }
125+ }
126+
127+ }
103128
129+ private void CaptureMetrics ( IProcessProxy workloadProcess , string commandArguments , EventContext telemetryContext , CancellationToken cancellationToken )
130+ {
131+ if ( workloadProcess . ExitCode == 0 )
132+ {
133+ try
134+ {
135+ // Retrieve OpenSSL version
136+ this . GetOpenSslVersion ( cancellationToken , workloadProcess . FullCommand ( ) ) ;
137+
104138 this . MetadataContract . Apply ( telemetryContext ) ;
105139
106140 OpenSslMetricsParser resultsParser = new OpenSslMetricsParser ( workloadProcess . StandardOutput . ToString ( ) , commandArguments ) ;
@@ -133,7 +167,7 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok
133167
134168 EventContext relatedContext = telemetryContext . Clone ( )
135169 . AddContext ( "executable" , this . ExecutablePath )
136- . AddContext ( "commandArguments" , commandArguments ) ;
170+ . AddContext ( "commandArguments" , commandArguments ) ;
137171
138172 return this . Logger . LogMessageAsync ( $ "{ nameof ( OpenSslExecutor ) } .ExecuteWorkload", relatedContext , async ( ) =>
139173 {
@@ -153,7 +187,7 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok
153187 await this . LogProcessDetailsAsync ( process , telemetryContext , "OpenSSL" , logToFile : true ) ;
154188
155189 process . ThrowIfWorkloadFailed ( ) ;
156- this . CaptureMetrics ( process , commandArguments , telemetryContext ) ;
190+ this . CaptureMetrics ( process , commandArguments , telemetryContext , cancellationToken ) ;
157191 }
158192 }
159193 finally
0 commit comments