Skip to content

Commit 26e9101

Browse files
committed
trace2: add performance format target
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.
1 parent f8c2e2f commit 26e9101

File tree

5 files changed

+243
-30
lines changed

5 files changed

+243
-30
lines changed

src/shared/Core.Tests/Trace2Tests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System;
2-
using System.Text.RegularExpressions;
3-
using GitCredentialManager.Tests.Objects;
41
using Xunit;
52

63
namespace GitCredentialManager.Tests;
@@ -30,4 +27,14 @@ public void TryGetPipeName_Windows_Returns_Expected_Value(string input, string e
3027
Assert.True(isSuccessful);
3128
Assert.Matches(actual, expected);
3229
}
30+
31+
[Theory]
32+
[InlineData(0.013772, " 0.013772 ")]
33+
[InlineData(26.316083, " 26.316083 ")]
34+
[InlineData(100.316083, "100.316083 ")]
35+
public void BuildTimeSpan_Match_Returns_Expected_String(double input, string expected)
36+
{
37+
var actual = Trace2Message.BuildTimeSpan(input);
38+
Assert.Equal(expected, actual);
39+
}
3340
}

src/shared/Core/Constants.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static class EnvironmentVariables
5656
public const string GcmAllowWia = "GCM_ALLOW_WINDOWSAUTH";
5757
public const string GitTrace2Event = "GIT_TRACE2_EVENT";
5858
public const string GitTrace2Normal = "GIT_TRACE2";
59+
public const string GitTrace2Performance = "GIT_TRACE2_PERF";
5960

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

170171
public static class Trace2
171172
{
172-
public const string SectionName = "trace2";
173-
public const string EventTarget = "eventtarget";
174-
public const string NormalTarget = "normaltarget";
173+
public const string SectionName = "trace2";
174+
public const string EventTarget = "eventtarget";
175+
public const string NormalTarget = "normaltarget";
176+
public const string PerformanceTarget = "perftarget";
175177
}
176178
}
177179

src/shared/Core/ITrace2Writer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace GitCredentialManager;
1010
public enum Trace2FormatTarget
1111
{
1212
Event,
13-
Normal
13+
Normal,
14+
Performance
1415
}
1516

1617
public interface ITrace2Writer : IDisposable
@@ -44,6 +45,9 @@ protected string Format(Trace2Message message)
4445
case Trace2FormatTarget.Normal:
4546
sb.Append(message.ToNormalString());
4647
break;
48+
case Trace2FormatTarget.Performance:
49+
sb.Append(message.ToPerformanceString());
50+
break;
4751
default:
4852
Console.WriteLine($"warning: unrecognized format target '{_formatTarget}', disabling TRACE2 tracing.");
4953
Failed = true;

src/shared/Core/Settings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ public Trace2Settings GetTrace2Settings()
533533
settings.FormatTargetsAndValues.Add(Trace2FormatTarget.Normal, value);
534534
}
535535

536+
if (TryGetSetting(Constants.EnvironmentVariables.GitTrace2Performance, KnownGitCfg.Trace2.SectionName,
537+
Constants.GitConfiguration.Trace2.PerformanceTarget, out value))
538+
{
539+
settings.FormatTargetsAndValues.Add(Trace2FormatTarget.Performance, value);
540+
}
541+
536542
return settings;
537543
}
538544

0 commit comments

Comments
 (0)