Application performance analysis using Windows toolkit
0
/
305
Installing windows performance toolkit for performance analysis:
1. Invoke adksetup.exe which can be downloaded from https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-install 2. From the features list select only “Windows performance toolkit”, we do not need other tools for now. Windows performance toolkit has two main components: Windows Performance Recorder (WPR) and Windows Performance analyzer(WPA). Windows performance recorder is used to record windows session. It can record all activities / events and resource consumption for the current session. The collected data is then stored in a file. Windows performance analyzer is used to analyze the data collected by WPR.How to use Windows Performance Recorder:
1. On the Start screen, click Windows Performance Recorder or from start menu search box execute command WPRUi. This will open the following window. 2. To gather CPU and memory related information, select “CPU usage”, “Heap usage” , and “VirtualAlloc usage” from the Resource Analysis options. Keep “First level triage” selected from First level triage section. 3. Set Performance scenario: “General”, Detail level: “Verbose” and Logging mode: “File” as shown in the image below. 4. Stop other bulky applications such as web browsers etc which you do not need, otherwise, those applications will also be tracked by WPR. 5. Now, click on “Start” button to start the recording. 6. Then start your application server/exe for which you want to do performance and memory leak analysis. 7. Click on the “Save” button to stop the recording. This will launch a new save file dialog. Save your recording to the location you want.Sample program to evaluate windows performance toolkit:
You can use the following sample program to evaluate windows performance toolkit. Using this program you can do CPU usage analysis as well as memory leak analysis. In the following program functions highCPU(), midCPU() and lowCPU() are CPU bound functions. The names given to these functions indicate the level of CPU usage. Function memoryLeak() leaks some memory allocated on heap. This function is used to demonstrate the memory leak analysis. First, start recording session using windows performance recorder (WPR) and then start executing the following program. Once the program finishes execution stop the recording and open the recorded file in windows performance analyzer.// Poor_performance.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include<string>
#include<thread>
#include<vector>
using namespace std;
string highCPU()
{
std::string str = "";
int sum = 0;
for (long i = 0; i < 100; ++i)
for (long j = 0; j < 100; ++j)
for (long k = 0; k < 100; ++k)
for (long l = 0; l < 100; ++l)
for (long m = 0; m < 100; ++m)
{
sum ^= i ^ j ^ k ^ l ^ m;
}
return str;
}
string midCPU()
{
std::string str = "";
int sum = 0;
for (long i = 0; i < 100000; ++i)
{
sum = sum ^ i;
}
return str;
}
string lowCPU()
{
std::string str = "";
for (long i = 0; i < 10; ++i)
str += "l";
return str;
}
string memoryLeak()
{
char *c = new char[100000];
for (long i = 0; i < 10000; ++i)
c[i] = 'k';
string r(c);
return r;
}
int main()
{
std::vector<std::thread> threadVector;
for (int i = 0; i < 8 /* 8 CPU cores */; ++i)
{
std::cout << "High CPU! thread = " << i << "\n";
std::thread threadObj(highCPU);
threadVector.push_back(std::move(threadObj));
}
for (auto &it : threadVector)
{
if (it.joinable())
it.join();
}
cout << "Momory leak" << endl;
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
cout << "Mid / low CPU usage" << endl;
midCPU();
midCPU();
midCPU();
midCPU();
midCPU();
lowCPU();
lowCPU();
lowCPU();
lowCPU();
lowCPU();
lowCPU();
cout << "Momory leak" << endl;
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
memoryLeak();
}