Skip to content

Commit

Permalink
trace2: add performance format target
Browse files Browse the repository at this point in the history
Add the performance format target for TRACE2 tracing. This change
includes a few notable components:

1. A new GetMessage method to ensure message strings written to normal and
performance targets are not duplicated.
2. A new PerformanceFormatComponent class to track sizing of optional
properties of performance format messages.
3. A BuildSpan method that Trace2Message children use to create
correctly-sized "spans" for optional properties of performance format
messages. A span is a piece of the message beginning with a pipe (|) and
ending just before the next pipe or the end of the message.
4. A BuildTimeSpan method that adjusts spans for long/short times. In
future, when we have events that include performance format string span
components, we will need to add an additional method to handle them.
  • Loading branch information
ldennington committed Mar 15, 2023
1 parent c0a3a03 commit 59a2692
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 30 deletions.
13 changes: 10 additions & 3 deletions src/shared/Core.Tests/Trace2Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Text.RegularExpressions;
using GitCredentialManager.Tests.Objects;
using Xunit;

namespace GitCredentialManager.Tests;
Expand Down Expand Up @@ -30,4 +27,14 @@ public void TryGetPipeName_Windows_Returns_Expected_Value(string input, string e
Assert.True(isSuccessful);
Assert.Matches(actual, expected);
}

[Theory]
[InlineData(0.013772, " 0.013772 ")]
[InlineData(26.316083, " 26.316083 ")]
[InlineData(100.316083, "100.316083 ")]
public void BuildTimeSpan_Match_Returns_Expected_String(double input, string expected)
{
var actual = Trace2Message.BuildTimeSpan(input);
Assert.Equal(expected, actual);
}
}
8 changes: 5 additions & 3 deletions src/shared/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static class EnvironmentVariables
public const string GcmAllowWia = "GCM_ALLOW_WINDOWSAUTH";
public const string GitTrace2Event = "GIT_TRACE2_EVENT";
public const string GitTrace2Normal = "GIT_TRACE2";
public const string GitTrace2Performance = "GIT_TRACE2_PERF";

/*
* Unlike other environment variables, these proxy variables are normally lowercase only.
Expand Down Expand Up @@ -169,9 +170,10 @@ public static class Remote

public static class Trace2
{
public const string SectionName = "trace2";
public const string EventTarget = "eventtarget";
public const string NormalTarget = "normaltarget";
public const string SectionName = "trace2";
public const string EventTarget = "eventtarget";
public const string NormalTarget = "normaltarget";
public const string PerformanceTarget = "perftarget";
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/shared/Core/ITrace2Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace GitCredentialManager;
public enum Trace2FormatTarget
{
Event,
Normal
Normal,
Performance
}

public interface ITrace2Writer : IDisposable
Expand Down Expand Up @@ -44,6 +45,9 @@ protected string Format(Trace2Message message)
case Trace2FormatTarget.Normal:
sb.Append(message.ToNormalString());
break;
case Trace2FormatTarget.Performance:
sb.Append(message.ToPerformanceString());
break;
default:
Console.WriteLine($"warning: unrecognized format target '{_formatTarget}', disabling TRACE2 tracing.");
Failed = true;
Expand Down
6 changes: 6 additions & 0 deletions src/shared/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ public Trace2Settings GetTrace2Settings()
settings.FormatTargetsAndValues.Add(Trace2FormatTarget.Normal, value);
}

if (TryGetSetting(Constants.EnvironmentVariables.GitTrace2Performance, KnownGitCfg.Trace2.SectionName,
Constants.GitConfiguration.Trace2.PerformanceTarget, out value))
{
settings.FormatTargetsAndValues.Add(Trace2FormatTarget.Performance, value);
}

return settings;
}

Expand Down
Loading

0 comments on commit 59a2692

Please sign in to comment.