PerformanceCounter explanation and usage

Source: Internet
Author: User
Tags ikev2

 

In the past two days, I wrote code to control the CPU usage. It is displayed as a straight line or curve, and the PerformanceCounter class is used when it is displayed as a straight line.

 

 

 

I am still very interested in this category, and it is not very clear that I have found some materials on the Internet. I just studied it myself.

 

 

 

PerformanceCounter is divided into various category types. Each category corresponds to different types of resources, such as "Processor", "IPv6", and so on... There is a list of all types below:

 

View plain

Thread

RAS Total

TCPv6

TCPv4

Paging File

SQLServer: Latches

IPsec AuthIP IPv4

MSDTC Bridge 4.0.0.0

IPsec AuthIP IPv6

. Net clr Data

WF (System. Workflow) 4.0.0.0

Synchronization

Processor

Security Per-Process Statistics

MSDTC Bridge 3.0.0.0

Generic IKEv1, AuthIP, and IKEv2

Database ==> TableClasses

Event Tracing for Windows Session

ASP. NET v4.0.30319

. Net clr Networking

Objects

Terminal Services

BITS Net Utilization

SQLServer: User Settable

. Net clr Exceptions

IPsec IKEv2 IPv6

Process

IPsec IKEv2 IPv4

SQLServer: Broker Activation

WFPv6

SQLServer: Database processing ing

Search Gatherer

Teredo Relay

IPv4

SQLServer: Cursor Manager Total

IPv6

Job Object Details

WFPv4

IPHTTPS Global

ICMP

Offline Files

SQLServer: Cursor Manager by Type

SQLAgent: JobSteps

PhysicalDisk

Search Indexer

Windows Workflow Foundation

Teredo Server

ServiceModelService 3.0.0.0

Processor Information

SQLServer: Replication Logreader

SQLServer: Transactions

ASP. NET Apps v4.0.30319

SQLServer: Broker TO Statistics

SQLServer: Deprecated Features

Per Processor Network Interface Card Activity

Database

Browser

. Net clr Remoting

Pacer Pipe

Event Tracing for Windows

. Net clr LocksAndThreads

Job Object

Client Side Caching

. NET Data Provider for SqlServer

ASP. NET Applications

Terminal Services Session

SQLServer: Broker/DBM Transport

Network Interface

. NET Memory cached 4.0

SQLServer: General Statistics

SQLServer: Resource Pool Stats

SQLServer: Replication Merge

Security System-Wide Statistics

SQLServer: Backup Device

UDPv6

. Net clr Security

Outlook

. Net clr Jit

SQLServer: Workload Group Stats

WFP

ASP. NET State Service

SMSvcHost 4.0.0.0

SQLServer: Databases

SQLServer: Locks

Server Work Queues

ICMPv6

NBT Connection

. Net clr Loading

Server

SQLAgent: Jobs

RAS Port

Per Processor Network Activity Cycles

SMSvcHost 3.0.0.0

ServiceModelEndpoint 3.0.0.0

. Net clr Networking 4.0.0.0

ASP. NET

USB

SQLServer: Memory Manager

Cache

SQLServer: Replication Snapshot

System

Redirector

SQLServer: Wait Statistics

SQLAgent: Statistics

LogicalDisk

. NET Data Provider for Oracle

. Net clr Interop

Distributed Transaction Processing Coordinator

WMI Objects

. Net clr Memory

SQLServer: Access Methods

SQLServer: Buffer Partition

SQLServer: Buffer Manager

Database ==> Instances

ReadyBoost Cache

SQLServer: Plan Cache

SQLServer: Replication Agents

SQLServer: Exec Statistics

Teredo Client

Telephony

IPsec IKEv1 IPv6

Memory

SQLServer: SQL Errors

SQLServer: Replication Dist.

ServiceModelOperation 3.0.0.0

SQLServer: Buffer Node

IPsec IKEv1 IPv4

Search Gatherer Projects

IPsec Driver

SQLServer: Broker Statistics

SQLServer: SQL Statistics

SQLServer: CLR

SQLAgent: Alerts

UDPv4

SQLServer: Catalog Metadata

 

 

Then, each type corresponds to multiple instances. For example, the Processor instance is obtained through the following code:

 

 

 

View plain

Using System;

Using System. Collections. Generic;

Using System. Linq;

Using System. Text;

Using System. Diagnostics;

 

Namespace PerformanceCounterTest

{

Class Program

{

Static void Main (string [] args)

{

PerformanceCounterCategory [] pcc = PerformanceCounterCategory. GetCategories ();

For (int I = 0; I <pcc. Length; I ++)

{

If (pcc [I]. CategoryName = "Processor ")

{

Console. WriteLine ("-----------------------------------");

Console. WriteLine (pcc [I]. CategoryName );

Console. WriteLine ("-----------------------------------");

// Console. WriteLine (pcc [I]. MachineName );

String [] instanceNames = pcc [I]. GetInstanceNames ();

For (int j = 0; j <instanceNames. Length; j ++)

{

Console. WriteLine ("***** Instance Name **********");

Console. WriteLine (instanceNames [j]);

// PerformanceCounter [] counters = pcc [I]. GetCounters (instanceNames [j]);

 

// Console. writeLine ("************************************* *************");

// Console. WriteLine ("* counter name *");

// For (int k = 0; k <counters. Length; k ++)

//{

// Console. WriteLine (counters [k]. CounterName );

//}

}

}

}

}

}

}

 

Output result:

 

View plain

-----------------------------------

Processor

-----------------------------------

* *** Instance Name **********

_ Total

* *** Instance Name **********

0

* *** Instance Name **********

1

Press any key to continue...

 

 

 

In each instance, there are multiple counters, so you need to select the counters you need.

 

The obtained Processor category _ Total instance is used to check the counters contained in the instance. The Department annotated with the above Code includes the counter output. The result is:

 

View plain

-----------------------------------

Processor

-----------------------------------

* *** Instance Name **********

_ Total

**************************************** **********

* Counter name *

% Processor Time

% User Time

% Privileged Time

Interrupts/sec

% DPC Time

% Interrupt Time

DPCs Queued/sec

DPC Rate

% Idle Time

% C1 Time

% C2 Time

% C3 Time

C1 Transitions/sec

C2 Transitions/sec

C3 Transitions/sec

* *** Instance Name **********

0

**************************************** **********

* Counter name *

% Processor Time

% User Time

% Privileged Time

Interrupts/sec

% DPC Time

% Interrupt Time

DPCs Queued/sec

DPC Rate

% Idle Time

% C1 Time

% C2 Time

% C3 Time

C1 Transitions/sec

C2 Transitions/sec

C3 Transitions/sec

* *** Instance Name **********

1

**************************************** **********

* Counter name *

% Processor Time

% User Time

% Privileged Time

Interrupts/sec

% DPC Time

% Interrupt Time

DPCs Queued/sec

DPC Rate

% Idle Time

% C1 Time

% C2 Time

% C3 Time

C1 Transitions/sec

C2 Transitions/sec

C3 Transitions/sec

Press any key to continue...

 

 

 

In this way, you must specify the category, Instance name, and counter name when using PerformanceCounter.

 

View plain

PerformanceCounter pc1 = new PerformanceCounter ("Processor", "% Processor Time", "_ Total ");

 

Then you can obtain the counter value through pc1.NextValue ().

 

Author: Watkins. Song chanllege yourself

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.