Code Monkey home page Code Monkey logo

csharp-performance-recorder's Introduction

C# Performance Recorder

documentation pipeline status project version on nuget

C# performance recorder library using aspect oriented programming.

Project documentation available here.

Installation

Add the library to your project by following the instructions on the nuget.org package page.

Add Attribute

Use the [PerfomanceLogging] attribute on your methods, properties, or classes to have their execution time recorded.

[PerformanceLogging]
public void RunApplication()
{
    // ...
}

Enable Recording

Enable recording on the library API to have all method execution times recorded.

IPerformanceRecorderApi api = new PerformanceRecorderApiImpl();
api.EnablePerformanceRecording();

Print Results

Retrieve the results of a performance recording session using the API

IPerformanceRecorderApi api = new PerformanceRecorderApiImpl();
IRecordingSessionResult results = api.GetResults();

The IRecordingSessionResult interface provides access to all the recording data for that session.

Use the one of the provided formatters (in this case, the nested string formatter) to print the results.

IFormatterFactoryApi formatterFactory = api.NewFormatterFactoryApi();
var formatter = formatterFactory.NewNestedStringResultFormatter();

// Write formatted results to console
Console.WriteLine(formatter.FormatAs(results)

The nested formatter will format the results in a tree structure to show where methods are called from.

Output:

+-
   +- ApplicationImpl.RunApplication              count:  1  sum: 1.85  avg: 1.85  max: 1.85  min: 1.85
      +- WorkerImpl.RunOperationB                 count:  1  sum: 1.13  avg: 1.13  max: 1.13  min: 1.13
      |  +- WorkerImpl.RunPrivateOperationB2      count:  1  sum: 0.41  avg: 0.41  max: 0.41  min: 0.41
      |  |  +- WorkerImpl.RunPrivateOperationB21  count:  1  sum: 0.00  avg: 0.00  max: 0.00  min: 0.00
      +- ApplicationImpl.Worker                   count: 11  sum: 0.16  avg: 0.01  max: 0.14  min: 0.00
         +- WorkerImpl..ctor                      count: 11  sum: 0.00  avg: 0.00  max: 0.00  min: 0.00

As the indentation of the method ID increases, so does the depth at which it was run. In the example above, RunPrivateOperationB2 was run from RunOperationB. The execution time of the parent method will include the time of each child, any missing time is due to either a non-instrumented method/property, or an overhead of the performance recorder.

Credits

Made possible by the AspectInjector library

csharp-performance-recorder's People

Contributors

hectorjsmith avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.