Load Testing with Custom Performance Counters: Listing 2.

The DataAccessCounterLocator class, which calls RecordOperation.

public class SqlServerCmsWebPageRepository :
  SqlServerCmsRepositoryBase <ICmsWebPage, 
  CmsDatasetTableAdapters.CmsWebPageTableAdapter >,
  ICmsWebPageRepository
{
  public override void Save(ICmsWebPage saveThis)
  {
    var startTicks = DateTime.Now.Ticks;

    try
    {
      DoSave(saveThis);
    }
    finally
    {
      // Call the locator to access OperationPerformanceCounterManager
      DataAccessCounterLocator.Instance.SaveWebPage.RecordOperation(
        DateTime.Now.Ticks - startTicks);
    }
  }

  // ...
}
public class DataAccessCounterLocator
{
  private static object m_SyncRoot = new object();

  private const string CategoryName = "Benday.com CMS Data Access";

  private DataAccessCounterLocator()
  {
    LoadWebPages = new OperationPerformanceCounterManager(
      CategoryName, "Load Web Pages");

    LoadWebPageById = new OperationPerformanceCounterManager(
      CategoryName, "Load Web Page By Id");

    SaveWebPage = new OperationPerformanceCounterManager(
      CategoryName, "Save Web Page");

    SaveFolder = new OperationPerformanceCounterManager(
      CategoryName, "Save Folder");

    SaveLink = new OperationPerformanceCounterManager(
      CategoryName, "Save Link");
  }

  public OperationPerformanceCounterManager 
    LoadWebPages { get; private set; }
  public OperationPerformanceCounterManager 
    SaveWebPage { get; private set; }
  public OperationPerformanceCounterManager 
    SaveFolder { get; private set; }
  public OperationPerformanceCounterManager 
    SaveLink { get; private set; }
  public OperationPerformanceCounterManager 
    LoadWebPageById { get; private set; }

  private static DataAccessCounterLocator m_Instance;
  public static DataAccessCounterLocator Instance
  {
    get
    {
      if (m_Instance == null)
      {
        lock (m_SyncRoot)
        {
          if (m_Instance == null)
          {
            m_Instance = new DataAccessCounterLocator();
          }
        }
      }

      return m_Instance;
    }
  }        // ...
}

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