A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/paintdotnet/PaintDotNet.Systrace below:

paintdotnet/PaintDotNet.Systrace: A simple .NET library for emitting Chrome Systrace logs for use with chrome://tracing

Systrace library from Paint.NET

This is a copy/fork of the code I'm using in Paint.NET to do simple runtime tracing in Paint.NET. It's not a complete library for emitting events, it only supports simple begin/end pairs. That's a great place to start, however, and you can get a lot done with it.

These trace files can then be loaded in Chrome by opening a new tab and navigating to chrome://tracing. Dragging and dropping trace files into that mini-app works!

Starting with Paint.NET v4.2.2, you can use the /enableTracing:filename command-line argument to enable tracing. You can then open that in chrome://tracing, or just look at it in a text editor, to get a feel of the file format.

I've also included some sample traces in the samples directory.

Some code:

sealed class MainForm : Form
{
    private Button button;
    private Label label;

    // This is how I like to do tracing for a constructor
    public MainForm()
    {
        using (Systrace.BeginEvent(nameof(MainForm) + "::ctor"))
        {
            ...
            InitializeComponent();
            ...
        }
    }

    // Other times you don't really need the class prefix in the event name since the method is always called from the constructor
    private void InitializeComponent()
    {
        using (Systrace.BeginEvent(nameof(InitializeComponent)))
        {
            // You might want to trace for different segments of code
            using (Systrace.BeginEvent("instantiate controls"))
            {
                this.button = new Button();
                this.label = new Label();
            }

            using (Systrace.BeginEvent("initialize controls"))
            {
                this.button.Click += ...;
                this.button.Text = ...;

                this.label.Text = ...;
            }

            using (Systrace.BeginEvent("add controls"))
            {
                SuspendLayout();
                this.Controls.Add(this.button);
                this.Controls.Add(this.label);
                ResumeLayout();
            }
            ...
        }
    }

    // An example where you want a trace event for a specific method
    protected override void OnLayout(LayoutEventArgs levent)
    {
        using (Systrace.BeginEvent(nameof(MainForm) + "::" + nameof(OnLayout))) // "MainForm::OnLayout"
        {
            ... layout code goes here ...
            base.OnLayout(levent);
        }
    }

    // And sometimes you want a trace event that spans method calls ...
    private Systrace.BeginEventScope resizeTracingScope;

    protected override void OnResizeBegin(EventArgs e)
    {
        this.resizeTracingScope = Systrace.BeginEvent(nameof(MainForm) + "::Resize");
        ...
        base.OnResizeBegin(e);
    }

    protected override void OnResizeEnd(EventArgs e)
    {
        ...
        base.OnResizeBegin(e);
        this.resizeTracingScope.Dispose(); // no need to check for null because it's a struct and can't be null
    }
}

This is what it looks like, using one of the sample trace from the samples directory:

MIT license.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4