Skip to content

dotnet-trace topn report can misprint method names #2994

Closed

Description

@josalem

private static string FormatFunction(string name)
{
string classMethod;
Regex nameRx = new Regex(@"(.*\..*)(\(.*\))");
Match match = nameRx.Match(name);
string functionList = match.Groups[1].Value;
string arguments = match.Groups[2].Value;
string[] usingStatement = functionList.Split(".");
int length = usingStatement.Length;
if (length < 2)
{
if (length == 1)
{
classMethod = usingStatement[length - 1];
}
else
{
classMethod = usingStatement[length];
}
}
else
{
classMethod = usingStatement[length - 2] + "." + usingStatement[length - 1];
}
return classMethod + arguments;
}

Notably, this code assumes all functions look like the regex, but functions in a trace could show up as ?!? if there aren't symbols available. This results in an empty line in the output.

dotnet trace report topN ./dotnet_20220407_033645.nettrace -v
Top 5 Functions (Exclusive)                                                  Inclusive           Exclusive           
1.                                                                           58.33%              58.33%              
2. ManualResetEventSlim.Wait(int32,value class System.Threading.Cancellat    8.33%               8.33%               
   ionToken)                                            
3. WaitHandle.WaitOneNoCheck(int32)                                          8.33%               8.33%               
4. WaitHandle.WaitMultiple(value class System.ReadOnlySpan`1<class System    8.33%               8.33%               
   .Threading.WaitHandle>,bool,int32)                                            
5. SemaphoreSlim.WaitUntilCountOrTimeout(int32,unsigned int32,value class    8.33%               8.33%               
    System.Threading.CancellationToken)                                            

I added some logging to the above sample, and it showed that it was attempting to format ?!?. I still have the trace if you want it.

Activity

  1. added
    bug
    on Apr 8, 2022
  2. hoyosjs commented on Apr 8, 2022

    @hoyosjs
    Member

    Doesn't perfview have an option to expose the address of the method? Printing that here could be useful instead of ?!?

  3. added this to the .NET 7.0 milestone on Apr 8, 2022
  4. mikelle-rogers commented on Apr 8, 2022

    @mikelle-rogers
    Member

    Are there any other ways functions can show up as in a trace besides ?!? and the regex?

  5. josalem commented on Apr 8, 2022

    @josalem
    ContributorAuthor

    Theoretically, yes, but EventPipe traces only contain managed code for now.

    If you wanted to generalize it, you'd need to also be able to handle native frame encoding which is typically module!class::or::namespace::hierarchy::methodname(...), e.g., coreclr!EventPipeAdapter::ep_enable(). That's where ?!? comes from: unknown module and unknown symbol.

    I'm not sure that's worth the time right now, so it's better to just handle managed frames.

  6. mikelle-rogers commented on Apr 11, 2022

    @mikelle-rogers
    Member

    @hoyosjs @josalem would you please point me in the right direction of where to find perfview's option to expose the address of the method?

  7. ghost locked as resolved and limited conversation to collaborators on Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugdotnet-trace

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions