Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debug Mode #58

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.1.18</Version>
<Version>0.1.19</Version>
<Authors>Tony Redondo, Grégory Léocadie</Authors>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
2 changes: 1 addition & 1 deletion src/TimeItSharp.Common/Assertors/DefaultAssertor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override AssertResponse ExecutionAssertion(in AssertionData data)
_sbuilder.Clear();
_consecutiveErrorCount++;

if (Options.Configuration.ProcessFailedDataPoints)
if (Options.Configuration.ProcessFailedDataPoints || Options.Configuration.DebugMode)
{
return new AssertResponse(
status: Status.Failed,
Expand Down
10 changes: 10 additions & 0 deletions src/TimeItSharp.Common/Configuration/Builder/ConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ public ConfigBuilder ShowStdOutForFirstRun()
return this;
}

/// <summary>
/// Sets timeit to run in debug mode
/// </summary>
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithDebugMode()
{
_configuration.DebugMode = true;
return this;
}

#region WithExporter

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/TimeItSharp.Common/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class Config : ProcessData
[JsonPropertyName("showStdOutForFirstRun")]
public bool ShowStdOutForFirstRun { get; set; }

[JsonPropertyName("debugMode")]
public bool DebugMode { get; set; }

public Config()
{
FilePath = string.Empty;
Expand All @@ -71,6 +74,7 @@ public Config()
Services = new();
ProcessFailedDataPoints = false;
ShowStdOutForFirstRun = false;
DebugMode = false;
}

public static Config LoadConfiguration(string filePath)
Expand Down Expand Up @@ -128,5 +132,6 @@ public static Config LoadConfiguration(string filePath)
Tags = new Dictionary<string, object>(Tags),
ProcessFailedDataPoints = ProcessFailedDataPoints,
ShowStdOutForFirstRun = ShowStdOutForFirstRun,
DebugMode = DebugMode,
};
}
32 changes: 29 additions & 3 deletions src/TimeItSharp.Common/ScenarioProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ await RunScenarioAsync(repeat.Count, index, scenario, TimeItPhase.ExtraRun, fals
lastStandardOutput = item.StandardOutput;
}

if (item.Status == Status.Passed || _configuration.ProcessFailedDataPoints || !anyPassedDataPoint)
if (item.Status == Status.Passed ||
_configuration.ProcessFailedDataPoints ||
_configuration.DebugMode ||
!anyPassedDataPoint)
{
#if NET7_0_OR_GREATER
durations.Add(item.Duration.TotalNanoseconds);
Expand Down Expand Up @@ -426,6 +429,10 @@ private async Task<List<DataPoint>> RunScenarioAsync(int count, int index, Scena

dataPoints.Add(currentRun);
AnsiConsole.Markup(currentRun.Status == Status.Failed ? "[red]x[/]" : "[green].[/]");
if (_configuration.DebugMode)
{
AnsiConsole.WriteLine();
}

if (checkShouldContinue && !currentRun.ShouldContinue)
{
Expand Down Expand Up @@ -481,9 +488,24 @@ private async Task<DataPoint> RunCommandAsync(int index, Scenario scenario, Time
cmd = cmd.WithArguments(cmdArguments);
}

if (executionId == 0 && _configuration.ShowStdOutForFirstRun)
if ((executionId == 0 && _configuration.ShowStdOutForFirstRun) || _configuration.DebugMode)
{
AnsiConsole.WriteLine();
if (_configuration.DebugMode)
{
AnsiConsole.Markup(" [aqua]{0}. Running:[/] ", executionId + 1);
}
else
{
AnsiConsole.Markup(" [aqua]Running:[/] ");
}
AnsiConsole.WriteLine("{0} {1}", cmdString, cmdArguments);
if (!string.IsNullOrWhiteSpace(workingDirectory))
{
AnsiConsole.Markup(" [aqua]Working Folder:[/] ");
AnsiConsole.WriteLine(workingDirectory);
}

AnsiConsole.WriteLine(new string('-', 80));
cmd = cmd.WithStandardOutputPipe(PipeTarget.Merge(cmd.StandardOutputPipe,
PipeTarget.ToStream(Console.OpenStandardOutput())));
Expand Down Expand Up @@ -735,10 +757,14 @@ mainEndDate is not null &&

_callbacksTriggers.ExecutionEnd(dataPoint, phase);

if (executionId == 0 && _configuration.ShowStdOutForFirstRun)
if ((executionId == 0 && _configuration.ShowStdOutForFirstRun) || _configuration.DebugMode)
{
AnsiConsole.WriteLine(new string('-', 80));
AnsiConsole.Write(" ");
if (_configuration.DebugMode)
{
AnsiConsole.Markup(" [aqua]Result:[/] ");
}
}

return dataPoint;
Expand Down
8 changes: 8 additions & 0 deletions src/TimeItSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
var datadogProfiler = new Option<bool>("--datadog-profiler", () => false, "Enable Datadog profiler");
var showStdOutForFistRun = new Option<bool>("--first-run-stdout", () => false, "Show the StdOut and StdErr for the first run");
var processFailedExecutions = new Option<bool>("--process-failed-executions", () => false, "Include failed executions in the final results");
var debugMode = new Option<bool>("--debug", () => false, "Run timeit in debug mode");

var root = new RootCommand
{
Expand All @@ -70,6 +71,7 @@
datadogProfiler,
showStdOutForFistRun,
processFailedExecutions,
debugMode,
};

root.SetHandler(async (context) =>
Expand All @@ -84,6 +86,7 @@
var datadogProfilerValue = GetValueForHandlerParameter(datadogProfiler, context);
var showStdOutForFistRunValue = GetValueForHandlerParameter(showStdOutForFistRun, context);
var processFailedExecutionsValue = GetValueForHandlerParameter(processFailedExecutions, context);
var debugModeValue = GetValueForHandlerParameter(debugMode, context);

var isConfigFile = false;
if (File.Exists(argumentValue))
Expand Down Expand Up @@ -155,6 +158,11 @@
configBuilder = configBuilder.ProcessFailedDataPoints();
}

if (debugModeValue)
{
configBuilder = configBuilder.WithDebugMode();
}

var timeitOption = new TimeItOptions(templateVariablesValue);

if (jsonExporterValue)
Expand Down
Loading