0

I need the to write a log message and capture that in PerfView. I would like to avoid using EventLog or EventSource because they are quite invasive: they require registering a new source or ETW provider, which leaves leftovers in the system.

Ideally I just want to call Debug.WriteLine (which uses OutputDebugString), but it seems that PerfView cannot collect it. Or is there some ETW provider that sees debug messages?

If you have an answer, please state the two parts of the solution:

  1. What should I write in C#, and
  2. How to configure PerfView to capture it (if there is some ETW provider, just name it).
fernacolo
  • 7,012
  • 5
  • 40
  • 61
  • DebugView is the tool for reading Debug.WriteLines https://learn.microsoft.com/en-us/sysinternals/downloads/debugview – Thomas Weller Jan 07 '19 at 08:00
  • I know, but I need PerfView. DebugView won't show everything else that is happing. – fernacolo Jan 07 '19 at 08:06
  • Then you want to configure a [TraceListener](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventing.eventprovidertracelistener?view=netframework-4.7.2) via the [app.config](https://learn.microsoft.com/en-us/dotnet/framework/debug-trace-profile/how-to-use-tracesource-and-filters-with-trace-listeners) – Thomas Weller Jan 07 '19 at 08:08
  • 1
    EventSource doesn't require any registration. – magicandre1981 Jan 07 '19 at 15:22
  • @magicandre1981 Yes, but it creates a new ETW provider in the system and requires me to learn the GUID in order to use in the PerfView. I would like a less intrusive solution where I can just trace something and it will appear. – fernacolo Jan 09 '19 at 04:05
  • I found this: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-dbgprint. Maybe is possible to configure PerfView to capture that? – fernacolo Jan 09 '19 at 04:09
  • no, I already requested an ETW provider for debug calls, but MS refuses this. I've posted the simple code to do what you want via EventSource. – magicandre1981 Jan 09 '19 at 16:15

1 Answers1

1

What you want is to use EventSource. Here you don't need to deal with GUIDs and registration to system.

public sealed class MinimalEventSource : EventSource
{
    public class Tasks
    {
        public const EventTask Information = (EventTask)1;
    }

    public static MinimalEventSource Log = new MinimalEventSource();

    [Event(1, Message = "{0}", Opcode = EventOpcode.Info, Task = Tasks.Information)]
    public void Information(string message)
    {
        if (IsEnabled())
        {
            WriteEvent(1, message);
        }
    }
}

Lof the data with MinimalEventSource.Log.Information("my debug info"); and capture them with perfview with PerfView /OnlyProviders=*MinimalEventSource. The imprtant thing is the * . Eventsource logs the Manifest with the definitions via ManifestEvent which gets added to the ETL, so no manifest registration is required.

magicandre1981
  • 27,895
  • 5
  • 86
  • 127