Application Instrumentation Using Performance Counters

Understand how and why to add custom performance counter instrumentation to your managed and native Windows applications.
Course info
Rating
(36)
Level
Intermediate
Updated
Jan 26, 2015
Duration
4h 24m
Table of contents
Introduction
Performance Counter Architecture
Understanding the Performance Counter Types
Implementing Custom Performance Counters in .NET
Implementing Custom Performance Counters With PerfLib 2.0
Implementing Custom Performance Counters With PerfLib 1.0
Description
Course info
Rating
(36)
Level
Intermediate
Updated
Jan 26, 2015
Duration
4h 24m
Description

Many applications are black holes - information is processed but not broadcast. It can be difficult to monitor the state of these applications without having the proper instrumentation channels in place. Performance counters offer an effective instrumentation strategy that combines the tractability of numbers with the liberty of automation frameworks. In this course, you will learn what counter types are available to your application, how the counters are managed by the operating system, and how to create custom performance counters in both native and managed code.

About the author
About the author

Jim has spent over 17 years developing software for aerospace, education, and casinos. Since 2010 he has run Code Owls LLC, a company in Charlotte NC specializing in IT tooling and automation technologies. Jim is a PowerShell MVP and avid speaker.

More from the author
Play by Play: Visual Studio 2017 and C# 7
Intermediate
2h 34m
Aug 25, 2017
PowerShell Gotchas
Intermediate
1h 40m
Oct 28, 2013
More courses by Jim Christopher
Section Introduction Transcripts
Section Introduction Transcripts

Introduction
Hey, hey, hey. Welcome to Application Instrumentation Using Performance Counters. This is Pluralsight author and PowerShell MVP, Jim Christopher, and I will be your guide through this course. You know, some of the more terrifying moments in my career have centered around deploying Windows services. It's not that Windows services are hard, it's just that once they're in production, they tend to be little black holes. That is, they don't typically output any information unless you forcibly go in and extract it. Now if you know me, you know I love logging so my Windows services will typically log information. I find this instrumentation channel very useful, but only to an extent. See, logs are great, but they require a person on the other end to interpret them. Moreover, logs are very transient. It can be very difficult to reconstruct some complex service behavior based on nothing but a bunch of text blobs. There is another form of instrumentation I like to take advantage of inside of my Windows applications. These are performance counters and that is what this course is all about, and the reason I like performance counters is that they're numeric. Numbers are great because they mean very specific things and they're also actionable. Like if I see the number 7 in a particular context coming out of a performance counter from my Windows service, that might be an indicator that the service is over taxed and I can take a very specific action to rectify the situation. The other nice thing about numbers is that they're tractable. That is, I can get a history of the values of these counters from my service, which makes it really easy to say things like, oh, look. The load on the service doubled in the span of 4 seconds.

Implementing Custom Performance Counters in .NET
Throughout this module we'll be looking at ways you can implement custom performance counters in your. NET code. In the previous modules of this course we have divided the things you can do to performance counters into three categories: managing them, publishing them, and consuming them. At this point in the course, we're done consuming performance counters and we're really only talking about managing them and publishing them. Specifically, when we talk about managing performance counters, there are three activities we're concerned with. We need to test for the existence of a performance counter category and we need to be able to create the category and delete the category. In terms of publishing values, we're again limited to three activities. We need to be able to create instances of a performance counter and we need to be able to publish incremental values as well as time values. During this module, we're going to rely on two functional demonstrations to illustrate these concepts. First, we're going to revisit our instrumented queue. We used this application to demonstrate the different types of performance counters that are available to us. In this module we're going to dive a little bit deeper into a few specific performance counters and how they are implemented around this queue. In addition, we're going to implement a new performance counter category called key pounder that will allow us to track the number of keys that we're pressing for a specific process.

Implementing Custom Performance Counters With PerfLib 1.0
In this module we'll continue our look at implementing custom performance counters using native code. This go around will tackle PerfLib 1. 0. Now building counters on PerfLib 1. 0 is a two-step process. First, we need to create what is known as a performance extension DLL. This is a DLL that will be loaded by a performance counter client such as PerfMon and used to collect performance counter data. Step two of this process is to make the necessary registry changes on the system where we want the performance counters to be installed. Once we have our counters built and installed, we'll see how the performance counter client loads our extension DLL and then uses this DLL to collect performance data from other applications across some inter-process communication channel.