microsoft / microsoft/perfview

Missing activity in case of "broken" ActivityID in events

Open
#2,122 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.7k
Forks
775
Avg merge
5d 11h
Merged PRs (30d)
9

Description

There is a bug in the BCL that generates 00 byte in an event ActivityID GUID that leads to stopping the parsing and "hidding" final activities.
Image
Since each Start/Stop action is adding an activity, I was expecting to see them (i.e. /1/4/2000/xx/ instead of /1/4/2000/
However, the GUID seemed to contain the missing xx value like in the second 32 value -0010- or -0020-.

 23360 | 00d0c714-0000-0000-0000-00003d2d6f5a =       /1/4/2000/ > event   1 __ [ 1| Start] RequestStart
       |> http://localhost:5500/Products/Info/1990
 23360 | 00d0c714-0010-0000-0000-00002d2d6f5a =       /1/4/2000/ > event   7 __ [ 1| Start] RequestHeadersStart
       |QH[ 20]
 23360 | 00d0c714-0010-0000-0000-00002d2d6f5a =       /1/4/2000/ > event   8 __ [ 2|  Stop] RequestHeadersStop
      <|QH
 44048 | 00d0c714-0020-0000-0000-00001d2d6f5a =       /1/4/2000/ > event  11 __ [ 1| Start] ResponseHeadersStart
       |RH>
 44048 | 00d0c714-0020-0000-0000-00001d2d6f5a =       /1/4/2000/ > event  12 __ [ 2|  Stop] ResponseHeadersStop
  200 <|RH
 44048 | 00d0c714-0030-0000-0000-00000d2d6f5a =       /1/4/2000/ > event  13 __ [ 1| Start] ResponseContentStart
       |RC>
 44048 | 00d0c714-0030-0000-0000-00000d2d6f5a =       /1/4/2000/ > event  14 __ [ 2|  Stop] ResponseContentStop
      <|RC
 44048 | 00d0c714-0000-0000-0000-00003d2d6f5a =       /1/4/2000/ > event   2 __ [ 2|  Stop] RequestStop
  200 <|

These output were generated to analyze network events (HTTP, socket, security, DNS).

This happens only when a 12 bits value is stored AND the high bits are stored in the low nibble of a byte. The following code update in StartStopActivityComputer.cs seems to avoid the problem and supports the proposed fix in the BCL:

// Compute the number (little endian) (thus backwards).
for (int i = (int)numBytes - 1; 0 <= i; --i)
{
    value = (value << 8) + bytePtr[i];
}

// Print the value
sb.Append(separator).Append(value);

bytePtr += numBytes;        // Advance past the bytes.

// FIX: there is a special case for a value < 4096/0xFFF where the encoder made a mistake
// It is encoded with 1 nibble + 1 byte + 1 byte that contains 0 (hence stopping the parsing)
if ((value >= 0xFF) && (value < 0xFFF) && (bytePtr + 1 < endPtr) && (bytePtr[0] == 0) && (bytePtr[1] != 0))
{
    bytePtr++;  // Advance past the 00 byte
}

Note: feel free to use this test app to debug and validate the fix.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/TraceEvent/Computers/StartStopActivityComputer.cs around the activity-ID parsing at the referenced line. Use the linked dotnet-activity test app to reproduce the malformed GUID case and compare the output with the proposed BCL fix. Done means parsing continues past the embedded zero byte and the final activities appear in the activity path.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.