Skip to content

Commit 00adf15

Browse files
Added support for uploading specviewperf logs to blob storage (#187)
* added specview perf to main.csproj * updated the default viewset parameter * added support for uploading log files * bumped up vc version * removed upload file feature from unit tests * removed extra whitespaces --------- Signed-off-by: James Li <[email protected]>
1 parent 75be809 commit 00adf15

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

.pipelines/azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pool:
1818
vmImage: windows-latest
1919

2020
variables:
21-
VcVersion : 1.11.3
21+
VcVersion : 1.11.4
2222
ROOT: $(Build.SourcesDirectory)
2323
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
2424
ENABLE_PRS_DELAYSIGN: 1

src/VirtualClient/VirtualClient.Actions.UnitTests/SPEC/SpecViewExecutorTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ private async Task SpecViewExecutorExecutesWorkloadAsExpected(PlatformID platfor
123123
return this.mockFixture.Process;
124124
};
125125

126+
// Remove any mock blob managers so that we do not evaluate the code paths that
127+
// upload log files by default.
128+
this.mockFixture.Dependencies.RemoveAll<IEnumerable<IBlobManager>>();
129+
this.mockFixture.ProcessManager.OnGetProcess = (id) => null;
130+
126131
await executor.ExecuteAsync(EventContext.None, CancellationToken.None);
127132
}
128133

src/VirtualClient/VirtualClient.Actions/SPECview/SpecViewExecutor.cs

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace VirtualClient.Actions
99
using System.IO.Abstractions;
1010
using System.Linq;
1111
using System.Runtime.InteropServices;
12+
using System.Text;
1213
using System.Text.RegularExpressions;
1314
using System.Threading;
1415
using System.Threading.Tasks;
@@ -29,8 +30,11 @@ namespace VirtualClient.Actions
2930
public class SpecViewExecutor : VirtualClientComponent
3031
{
3132
private const string VisualStudioCRuntimePackageName = "visualstudiocruntime";
33+
private const string RenamePrefix = "hist_";
34+
3235
private IFileSystem fileSystem;
3336
private ISystemManagement systemManagement;
37+
private string historyResultsPath;
3438

3539
/// <summary>
3640
/// Constructor for <see cref="SpecViewExecutor"/>
@@ -62,7 +66,8 @@ public string Viewset
6266
{
6367
get
6468
{
65-
return this.Parameters.GetValue<string>(nameof(SpecViewExecutor.Viewset));
69+
// Remove whitespaces in the argument (e.g. "3dsmax, catia" -> "3dsmax,catia")
70+
return this.Parameters.GetValue<string>(nameof(SpecViewExecutor.Viewset)).Replace(" ", string.Empty);
6671
}
6772
}
6873

@@ -113,8 +118,34 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel
113118
process.ThrowIfWorkloadFailed();
114119
this.CaptureMetrics(process, commandArguments, relatedContext);
115120
}
116-
}
117-
121+
}
122+
123+
if (this.TryGetContentStoreManager(out IBlobManager blobManager))
124+
{
125+
// specview logs are distributed in subdirectories corresponding to the viewsets
126+
string[] viewsetArray = this.Viewset.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
127+
string specviewOriginalLogPath;
128+
string specviewRenamedLogPath;
129+
List<Task> tasks = new List<Task>();
130+
foreach (string viewset in viewsetArray)
131+
{
132+
// log file is inside a folder that starts with the viewset name e.g. 3dsmax-07
133+
string? viewsetLogDir = this.fileSystem.Directory.GetDirectories(this.historyResultsPath, $"{viewset}*", SearchOption.TopDirectoryOnly).FirstOrDefault();
134+
if (viewsetLogDir == null)
135+
{
136+
throw new WorkloadResultsException(
137+
$"The expected SPECviewperf viewset log directory was not found in '{this.historyResultsPath}'.",
138+
ErrorReason.WorkloadResultsNotFound);
139+
}
140+
141+
specviewOriginalLogPath = this.PlatformSpecifics.Combine(viewsetLogDir, "log.txt");
142+
specviewRenamedLogPath = this.PlatformSpecifics.Combine(viewsetLogDir, viewset + "-" + Path.GetFileName(specviewOriginalLogPath));
143+
this.fileSystem.Directory.Move(specviewOriginalLogPath, specviewRenamedLogPath);
144+
tasks.Add(this.UploadSpecviewLogAsync(blobManager, specviewRenamedLogPath, DateTime.UtcNow, cancellationToken));
145+
}
146+
147+
await Task.WhenAll(tasks);
148+
}
118149
}
119150

120151
/// <summary>
@@ -180,8 +211,8 @@ private void CaptureMetrics(IProcessProxy workloadProcess, string commandArgumen
180211
telemetryContext);
181212

182213
// rename the result file to avoid confusions on future runs
183-
string historyResultsDir = this.PlatformSpecifics.Combine(this.Package.Path, "hist_" + Path.GetFileName(resultsFileDir));
184-
this.fileSystem.Directory.Move(resultsFileDir, historyResultsDir);
214+
this.historyResultsPath = this.PlatformSpecifics.Combine(this.Package.Path, RenamePrefix + Path.GetFileName(resultsFileDir));
215+
this.fileSystem.Directory.Move(resultsFileDir, this.historyResultsPath);
185216
}
186217
catch (SchemaException exc)
187218
{
@@ -223,5 +254,24 @@ private async Task SetUpEnvironmentVariable()
223254
string visualStudioCRuntimeDllPath = this.PlatformSpecifics.ToPlatformSpecificPath(visualStudioCRuntimePackage, this.Platform, this.CpuArchitecture).Path;
224255
this.SetEnvironmentVariable(EnvironmentVariable.PATH, visualStudioCRuntimeDllPath, EnvironmentVariableTarget.Machine, append: true);
225256
}
257+
258+
private Task UploadSpecviewLogAsync(IBlobManager blobManager, string specviewLogPath, DateTime logTime, CancellationToken cancellationToken)
259+
{
260+
// Example Blob Store Structure:
261+
// 9ed58814-435b-4900-8eb2-af86393e0059/my-vc/specview/specviewperf/2023-10-11T22-07-41-73235Z-log.txt
262+
FileUploadDescriptor descriptor = this.CreateFileUploadDescriptor(
263+
new FileContext(
264+
this.fileSystem.FileInfo.New(specviewLogPath),
265+
HttpContentType.PlainText,
266+
Encoding.UTF8.WebName,
267+
this.ExperimentId,
268+
this.AgentId,
269+
"specview",
270+
this.Scenario,
271+
null,
272+
this.Roles?.FirstOrDefault()));
273+
274+
return this.UploadFileAsync(blobManager, this.fileSystem, descriptor, cancellationToken, deleteFile: false);
275+
}
226276
}
227277
}

0 commit comments

Comments
 (0)