[英]How to link ETW start/stop Opcode concurrent events
I'm using ETW, and logging some events that have stop & stop opcodes, eg 我正在使用ETW,并记录一些具有停止和停止操作码的事件,例如
[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? 如果我有两个线程同时记录ActivateTask启动/停止事件,我如何确保事件正确配对? eg If I have:
如果我有:
then later 然后
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. 从我阅读ETW文档中,它将默认假设Stop事件属于最新的,未配对的Start事件 - 但我想确保我链接正确的Start / Stop事件。
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). 为了使这更复杂,Start和Stop事件可能来自不同的线程(如果我需要,我应该能够使线程变粘)。
This is called ActivityTrackig and works since .Net 4.6 . 这称为ActivityTrackig,自.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.
要自动运行,您不能使用自己的Thread实现,必须将所有调用包装到System.Threading.Tasks.Task调用中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.