简体   繁体   中英

How to link ETW start/stop Opcode concurrent events

I'm using ETW, and logging some events that have stop & stop opcodes, eg

[Event(1, Task = Tasks.ActivateTask, Opcode = EventOpcode.Start)]
public void ActivateTaskStart(string TaskName)
{
    if (IsEnabled())
    {
        WriteEvent(1, TaskName);
    }
}

[Event(2, Task = Tasks.ActivateTask, Opcode = EventOpcode.Stop)]
public void ActivateTaskStop(string TaskName)
{
    if (IsEnabled())
    {
        WriteEvent(2, TaskName);
    }
}

If I have two threads that are both logging ActivateTask start/stop events, how do I make sure the events are correctly paired up? eg If I have:

  • Thead-A: ActivateTaskStart
  • Thead-B: ActivateTaskStart

then later

  • Thead-A: ActivateTaskStop
  • Thead-B: ActivateTaskStop

from my reading of the ETW docs, it will default to assuming that the Stop event belongs to the most recent, unpaired, Start event - but I want to make sure I'm linking the correct Start/Stop events.

Is that possible? If so, how?

To make this more complicated, there's a chance that the Start and Stop events might be coming from different threads (if I need to, I should be able to make the threads sticky).

This is called ActivityTrackig and works since .Net 4.6 . To get this working automatically, you can't use own Thread implementations, you have to wrap all calls into System.Threading.Tasks.Task calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM