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

Fix parse dotnet trace providers option #2730

Merged
merged 4 commits into from
Nov 22, 2021
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
11 changes: 9 additions & 2 deletions src/Tools/dotnet-trace/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,21 @@ private static Dictionary<string, string> ParseArgumentString(string argument)
}
curIdx += 1;
}
AddKeyValueToArgumentDict(argumentDict, argument, keyStart, keyEnd, valStart, valEnd);
if(valStart > valEnd)
{
valEnd = curIdx;
}
if (keyStart < keyEnd)
{
AddKeyValueToArgumentDict(argumentDict, argument, keyStart, keyEnd, valStart, valEnd);
}
return argumentDict;
}

private static void AddKeyValueToArgumentDict(Dictionary<string, string> argumentDict, string argument, int keyStart, int keyEnd, int valStart, int valEnd)
{
string key = argument.Substring(keyStart, keyEnd - keyStart);
string val = argument.Substring(valStart);
string val = argument.Substring(valStart, valEnd - valStart);
if (val.StartsWith("\"") && val.EndsWith("\""))
{
val = val.Substring(1, val.Length - 2);
Expand Down
41 changes: 41 additions & 0 deletions src/tests/dotnet-trace/ProviderParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,47 @@ public void MultipleProvidersWithComplexFilters_CorrectlyParse(string providersT
Assert.True(providerThree.Arguments["FilterAndPayloadSpecs"] == "QuotedValue:-\r\nQuoted/Value:-A=B;C=D;");
}

[Fact]
public void ProvidersWithComplexFilters_CorrectlyParse()
{
string providersToParse = @"MyProvider:::A=B;C=D";
List<EventPipeProvider> parsedProviders = Extensions.ToProviders(providersToParse);
Assert.Single(parsedProviders);
EventPipeProvider providerOne = parsedProviders[0];
Assert.Equal("MyProvider", providerOne.Name);
Assert.Equal(2, providerOne.Arguments.Count);
Assert.Equal("B", providerOne.Arguments["A"]);
Assert.Equal("D", providerOne.Arguments["C"]);

providersToParse = @"MyProvider:::A=B;C=""D"",MyProvider2:::A=1;B=2;";
parsedProviders = Extensions.ToProviders(providersToParse);
Assert.Equal(2, parsedProviders.Count);
providerOne = parsedProviders[0];
EventPipeProvider providerTwo = parsedProviders[1];
Assert.Equal("MyProvider", providerOne.Name);
Assert.Equal("MyProvider2", providerTwo.Name);
Assert.Equal(2, providerOne.Arguments.Count);
Assert.Equal("B", providerOne.Arguments["A"]);
Assert.Equal("D", providerOne.Arguments["C"]);
Assert.Equal(2, providerTwo.Arguments.Count);
Assert.Equal("1", providerTwo.Arguments["A"]);
Assert.Equal("2", providerTwo.Arguments["B"]);

providersToParse = @"MyProvider:::A=""B;C=D"",MyProvider2:::A=""spaced words"";C=1285;D=Spaced Words 2";
parsedProviders = Extensions.ToProviders(providersToParse);
Assert.Equal(2, parsedProviders.Count);
providerOne = parsedProviders[0];
providerTwo = parsedProviders[1];
Assert.Equal("MyProvider", providerOne.Name);
Assert.Equal("MyProvider2", providerTwo.Name);
Assert.Equal(1, providerOne.Arguments.Count);
Assert.Equal(3, providerTwo.Arguments.Count);
Assert.Equal("B;C=D", providerOne.Arguments["A"]);
Assert.Equal("spaced words", providerTwo.Arguments["A"]);
Assert.Equal("Spaced Words 2", providerTwo.Arguments["D"]);
Assert.Equal("1285", providerTwo.Arguments["C"]);
}

[Theory]
[InlineData("ProviderOne:0x1:Verbose")]
[InlineData("ProviderOne:0x1:verbose")]
Expand Down