Load Testing with Custom Performance Counters: Listing 1.

The DocumentManager class.

public class DocumentManager
{
  private OperationPerformanceCounterManager m_PerfMonCountersForCreateDocument;

  public DocumentManager()
  {
    string categoryName = "My Application Name";

    // Initialize an OperationPerformanceCounterManager;
    // the Create Document operation
    m_PerfMonCountersForCreateDocument =
      new OperationPerformanceCounterManager(
        categoryName, "Create Document"); 
  }

  public int CreateDocument(string name)
  {
    // Get the start time
    var startTicks = DateTime.Now.Ticks;

    try
    {
      // Perform the operation
      var documentId = DoCreateDocument(name);

      return documentId;
    }
    finally
    {
      // After the operation completes, record how long it took 
      m_PerfMonCountersForCreateDocument.RecordOperation(
        DateTime.Now.Ticks - startTicks);
    }
  }

  private int DoCreateDocument(string name)
  {
    // Do some work            
  }
}

About the Author

Benjamin Day is a consultant and trainer specializing in software best practices using Microsoft tools. Ben’s main areas of emphasis include Team Foundation Server, Scrum, software testing, and software architecture. He is a Microsoft Visual Studio ALM MVP, a certified Scrum trainer via Scrum.org, and a speaker at conferences such as TechEd and Visual Studio Live! When not developing software, Ben’s been known to go running and sea kayaking in order to balance out his love of cheese, cured meats, and champagne. He can be contacted via www.benday.com.

comments powered by Disqus

Featured

  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

Subscribe on YouTube