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

  • What's New in TypeScript 5.3

    Microsoft advanced TypeScript to version 5.3 with a bevy of changes affecting everything from import attributes to interactive inlay hints for types, along with multiple optimizations.

  • Finally Go Eyes On with Upcoming Visual Studio 2022 UI Refresh

    Six months ago, Microsoft teased Visual Studio 2022 developers by announcing an upcoming UI refresh, which they can now finally get their eyes on in the new v17.9 preview 1.

  • DBSCAN Data Clustering from Scratch Using C#

    Compared to other clustering techniques, DBSCAN does not require you to explicitly specify how many data clusters to use, explains Dr. James McCaffrey of Microsoft Research in this full-code, step-by-step machine language tutorial.

  • GitHub Copilot Leads Productivity Gains in New Visual Studio 2022 17.8

    In announcing Visual Studio 2022 17.8 today, Microsoft emphasized community-driven productivity gains among the new features and functionality.

  • Microsoft Ships .NET 8

    In announcing .NET 8 today, Microsoft emphasized the cloud, performance, full-stack Blazor, AI and .NET MAUI as major highlights of the latest edition of the company's free, cross-platform, open source developer platform.

Subscribe on YouTube

Upcoming Events