Skip to content

Commit

Permalink
Add metric verbosity and allow to print critical metrics on console (#…
Browse files Browse the repository at this point in the history
…412)

* Add metric verbosity and allow to print critical metrics on console

* Add metric filter for verbosity

* add doc

* more doc

* pr comment

* up version

* Convert loglevel to int
  • Loading branch information
yangpanMS authored Dec 15, 2024
1 parent cc8d7d7 commit 976d8d7
Show file tree
Hide file tree
Showing 30 changed files with 477 additions and 215 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.16.11
1.16.12
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public void DiskSpdParserVerifyForCoreCountGreaterThan64WhichAddsProcessorGroupi
var parser = new DiskSpdMetricsParser(results, "diskspd.exe -b8K -r8K -t32 -o16 -w100 -d900 -Suw -W30 -D -L -Rtext D:\\diskspd-test.dat");

IList<Metric> metrics = parser.Parse();
metrics.LogConsole("test");

// cpu metrics
MetricAssert.Exists(metrics, "cpu usage 0", 92.79, "percentage");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.IO;
using System.Reflection;
using global::VirtualClient.Contracts;
using NUnit.Framework;
using VirtualClient;

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace VirtualClient.Actions
{
[TestFixture]
Expand All @@ -24,6 +24,7 @@ public void SpecCpuParserVerifyMetricsFpRate()
string outputPath = Path.Combine(workingDirectory, "Examples", "SpecCpu", "SpecCpuFpRateExample.txt");
this.rawText = File.ReadAllText(outputPath);
this.testParser = new SpecCpuMetricsParser(this.rawText);

IList<Metric> metrics = this.testParser.Parse();

Assert.AreEqual(28, metrics.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class BombardierMetricsParser : MetricsParser
{
private const string RequestPerSecond = "Reqs/sec";
private const string Microsecond = "microsecond";
private List<Metric> metrics;

/// <summary>
/// Constructor for <see cref="BombardierMetricsParser"/>
Expand All @@ -26,34 +27,32 @@ public BombardierMetricsParser(string rawText)
{
}

private List<Metric> Metrics { get; set; }

/// <inheritdoc/>
public override IList<Metric> Parse()
{
this.Preprocess();
this.Metrics = new List<Metric>();
this.metrics = new List<Metric>();

Root root = JsonSerializer.Deserialize<Root>(this.PreprocessedText);
this.Metrics.Add(new Metric("Latency Max", root.Result.Latency.Max, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.Metrics.Add(new Metric("Latency Average", root.Result.Latency.Mean, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.Metrics.Add(new Metric("Latency Stddev", root.Result.Latency.Stddev, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.Metrics.Add(new Metric("Latency P50", root.Result.Latency.Percentiles.P50, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.Metrics.Add(new Metric("Latency P75", root.Result.Latency.Percentiles.P75, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.Metrics.Add(new Metric("Latency P90", root.Result.Latency.Percentiles.P90, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.Metrics.Add(new Metric("Latency P95", root.Result.Latency.Percentiles.P95, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.Metrics.Add(new Metric("Latency P99", root.Result.Latency.Percentiles.P99, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));

this.Metrics.Add(new Metric("RequestPerSecond Max", root.Result.Rps.Max, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.Metrics.Add(new Metric("RequestPerSecond Average", root.Result.Rps.Mean, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.Metrics.Add(new Metric("RequestPerSecond Stddev", root.Result.Rps.Stddev, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.Metrics.Add(new Metric("RequestPerSecond P50", root.Result.Rps.Percentiles.P50, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.Metrics.Add(new Metric("RequestPerSecond P75", root.Result.Rps.Percentiles.P75, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.Metrics.Add(new Metric("RequestPerSecond P90", root.Result.Rps.Percentiles.P90, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.Metrics.Add(new Metric("RequestPerSecond P95", root.Result.Rps.Percentiles.P95, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.Metrics.Add(new Metric("RequestPerSecond P99", root.Result.Rps.Percentiles.P99, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));

return this.Metrics;
this.metrics.Add(new Metric("Latency Max", root.Result.Latency.Max, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.metrics.Add(new Metric("Latency Average", root.Result.Latency.Mean, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.metrics.Add(new Metric("Latency Stddev", root.Result.Latency.Stddev, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.metrics.Add(new Metric("Latency P50", root.Result.Latency.Percentiles.P50, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.metrics.Add(new Metric("Latency P75", root.Result.Latency.Percentiles.P75, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.metrics.Add(new Metric("Latency P90", root.Result.Latency.Percentiles.P90, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.metrics.Add(new Metric("Latency P95", root.Result.Latency.Percentiles.P95, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));
this.metrics.Add(new Metric("Latency P99", root.Result.Latency.Percentiles.P99, BombardierMetricsParser.Microsecond, MetricRelativity.LowerIsBetter));

this.metrics.Add(new Metric("RequestPerSecond Max", root.Result.Rps.Max, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.metrics.Add(new Metric("RequestPerSecond Average", root.Result.Rps.Mean, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.metrics.Add(new Metric("RequestPerSecond Stddev", root.Result.Rps.Stddev, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.metrics.Add(new Metric("RequestPerSecond P50", root.Result.Rps.Percentiles.P50, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.metrics.Add(new Metric("RequestPerSecond P75", root.Result.Rps.Percentiles.P75, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.metrics.Add(new Metric("RequestPerSecond P90", root.Result.Rps.Percentiles.P90, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.metrics.Add(new Metric("RequestPerSecond P95", root.Result.Rps.Percentiles.P95, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));
this.metrics.Add(new Metric("RequestPerSecond P99", root.Result.Rps.Percentiles.P99, BombardierMetricsParser.RequestPerSecond, MetricRelativity.HigherIsBetter));

return this.metrics;
}

private class Latency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace VirtualClient.Actions
/// </summary>
public class CtsTrafficMetricsParser : MetricsParser
{
private List<Metric> metrics;

/// <summary>
/// Constructor for <see cref="CtsTrafficMetricsParser"/>
/// </summary>
Expand All @@ -23,15 +25,13 @@ public CtsTrafficMetricsParser(string rawText)
{
}

private List<Metric> Metrics { get; set; }

/// <inheritdoc/>
public override IList<Metric> Parse()
{
try
{
this.Preprocess();
this.Metrics = new List<Metric>();
this.metrics = new List<Metric>();
MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(this.PreprocessedText));
using (var reader = new StreamReader(mStrm))
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public override IList<Metric> Parse()
}
}

return this.Metrics;
return this.metrics;
}
catch (Exception exc)
{
Expand All @@ -80,7 +80,7 @@ private void AddMetric(Metric metric)
{
try
{
this.Metrics.Add(metric);
this.metrics.Add(metric);
}
catch
{
Expand Down
26 changes: 13 additions & 13 deletions src/VirtualClient/VirtualClient.Actions/DCGMI/DCGMIResultsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ public class DCGMIResultsParser : MetricsParser
/// <summary>
/// Separate the column values by 2 or more spaces.
/// </summary>
private static readonly Regex DataTableDelimiter = new Regex(@"(\s){2,}", RegexOptions.ExplicitCapture);
private static readonly Regex DataTableDelimiter = new Regex(@"(\s){2,}", RegexOptions.ExplicitCapture);

private List<Metric> metrics;

/// <summary>
/// Constructor for <see cref="DCGMIResultsParser"/>
Expand Down Expand Up @@ -166,47 +168,45 @@ public DCGMIResultsParser(string rawText, string subsystem)

private string Subsystem { get; set; }

private List<Metric> Metrics { get; set; }

/// <inheritdoc/>
public override IList<Metric> Parse()
{
this.Preprocess();
this.Metrics = new List<Metric>();
this.metrics = new List<Metric>();
if (this.Subsystem == DCGMIResultsParser.Diagnostics)
{
this.Metrics = this.ParseDiagnosticsResults();
this.metrics = this.ParseDiagnosticsResults();
}
else if (this.Subsystem == DCGMIResultsParser.Discovery)
{
this.Metrics = this.ParseDiscoveryResults();
this.metrics = this.ParseDiscoveryResults();
}
else if (this.Subsystem == DCGMIResultsParser.FieldGroup)
{
this.Metrics = this.ParseFieldGroupResults();
this.metrics = this.ParseFieldGroupResults();
}
else if (this.Subsystem == DCGMIResultsParser.Group)
{
this.Metrics = this.ParseGroupResults();
this.metrics = this.ParseGroupResults();
}
else if (this.Subsystem == DCGMIResultsParser.Health)
{
this.Metrics = this.ParseHealthResults();
this.metrics = this.ParseHealthResults();
}
else if (this.Subsystem == DCGMIResultsParser.Modules)
{
this.Metrics = this.ParseModulesResults();
this.metrics = this.ParseModulesResults();
}
else if (this.Subsystem == DCGMIResultsParser.CUDATestGenerator)
{
this.Metrics = this.ParseCUDATestGeneratorResults();
this.metrics = this.ParseCUDATestGeneratorResults();
}
else if (this.Subsystem == DCGMIResultsParser.CUDATestGeneratorDmon)
{
this.Metrics = this.ParseCUDATestGeneratorDmonResults();
this.metrics = this.ParseCUDATestGeneratorDmonResults();
}

return this.Metrics;
return this.metrics;
}

private List<Metric> ParseDiagnosticsResults()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ namespace VirtualClient.Actions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using VirtualClient.Common;
using VirtualClient.Common.Extensions;
using VirtualClient.Common.Platform;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;
using VirtualClient.Contracts.Metadata;
Expand Down Expand Up @@ -349,7 +347,15 @@ private void CaptureMetrics(DiskWorkloadProcess workload, EventContext telemetry
this.MetadataContract.Apply(telemetryContext);

string result = workload.StandardOutput.ToString();
IList<Metric> metrics = new DiskSpdMetricsParser(result, this.CommandLine).Parse();
DiskSpdMetricsParser parser = new DiskSpdMetricsParser(result, this.CommandLine);
IList<Metric> metrics = parser.Parse();

if (this.MetricFilters?.Any() == true)
{
metrics = metrics.FilterBy(this.MetricFilters).ToList();
}

metrics.LogConsole(this.MetricScenario ?? this.Scenario);

this.Logger.LogMetrics(
"DiskSpd",
Expand Down
Loading

0 comments on commit 976d8d7

Please sign in to comment.