What is Performance Profiling?
Performance Profiling is a tool that is especially valuable for assisting in the design of particular mental, physical and professional training programs. While executing profiling at going code, the result stored in the file either with .out or .pprof file. The result can be stored in any file format while performing generating a benchmark result. Then to read the result from a file in which profiling information stored, follow commands mentioned in this document.
A tool that enables end users, administrators and organizations to gauge and evaluate the performance of a given system. Click to explore about, Performance Monitoring Tools
What are the benefits of enabling Performance Profiling?
The benefits of Performance Profiling are listed below:
- Performance profiling helps to identify bottlenecks of code.
- While bottlenecks identified, changes to code easily made, which are creating a bottleneck to a code.
How does Performance Profiling work?Generation of Performance Profiling results without using a benchmark related command -
- Write a code to do Profiling.
- Go to a specific location where code file is placed.
- Execute command to get profiling information.
- Go build -o app/test && time .app/test >filename.pprof.
- Profiling information for code stored in a file named as (filename.pprof).
- Execute go tool pprof filename.pprof to get information from profiling file.
Test all the BenchMark present in the file for functions of code
Go test -run =. -bench =. -cpuprofile = cpu.out -benchmem -memprofile = mem.out.
- After execution of the above command result for CPU, Profiling will store in cpu.out and result for Memory Profiling stored in mem.out.
- Execution of the following command helps to access the content of cpu.out and mem.out file.
- Execute go tool pprof cpu.out for CPU Profiling and go tool pprof mem.out for Memory Profiling.
Why Profiling is important?
- It is required to find an execution time and resource usage inside a specific function.
- For command execution time and CPU resource usage, various commands performed.
- There is a need to follow some parameters; if parameters appearing on the console are understandable, then the output easily analyzed.
Parameters to analyze the resultProfiling KPIs
- Flat - helps to identify a time spend to execute a specific function.
- Flat% - shows the amount of CPU spent to implement a function.
- Cum - It stands for cumulative frequency. It represents a time spend to execute a specific function including time spent to perform an all other function called from that particular function.
- Cum% - Shows that what amount to CPU to implement a particular function including all other functions present inside that function.
Choosing the right Performance Automation Testing tool will help you to empower your project and make the Automation Framework function for you. -From the Article, Cloud Performance Automation Testing Tools
How to adopt Performance Profiling?
The steps to adopt Performance Profiling are listed below:
Memory Profiling commandsCommands that help in CPU and memory profiling explained below -
go tool pprof -cum --inuse_objects mem.out
go tool pprof -cum --alloc_space mem.out
go tool pprof -cum --inuse_space mem.out
go tool pprof -cum --alloc_objects mem.out
CPU Profiling commandsTo do profiling on cpu.out file in which CPU profiling regarding information stored. Use the following command -
go tool pprof cpu.out
CPU Profiling on a specific functionTo do profiling on specific function following command can be used.
Profiling for top CPU processesTop command This command is listing resources according to more resource usage. The resource which is consuming more CPU is listed first and which is taking less CPU resource is listed last. TOP 4 Specifying the number of nodes along with the top command helps us to define how many nodes user wants to see in a result. Profiling on the main method
This command will use the resource usage for the main class. Profiling on the main method also lists resource usage of other components as follows -
Visualize result from a.PDF FileTo generate a result in a .pdf file using a mem.out or cpu.out, use the following command - Go to the location of the project where a file with .out extension is present. Use the following command for this. /usr/local/src/Projects/Doc_demo/main$ ls After that execute the following command to generate a pdf file. go tool pprof --pdf "location of .test file" "location of the file whose result converted into pdf file" >filename.pdf
After execution of the above command, the cpu.out or mem.out result will be available in a file with.PDF file. After then listing all files, file with the .pdf extension will be present. Whenever a PDF file generated which containing a profiling result can be open by using the following command.
go tool pprof --pdf cpu.out > cpu0.pdf
Finally, After accessing a PDF file from the console, the PDF file will be open as follows. Above all procedure was to store a CPU.out file result in a PDF file. On the other hand, the same above procedure can be followed to save a mem.out file results in a file with.PDF extension.
Memory profiling on API endpointsTo do profiling on API based benchmarks, we need to follow steps, which are specified below -
- First of all, go to a location at which code for go is present.
- Run an application at a specific point where you want to run.
- Then open a new console screen as like the previous path (look above step ), from here run a benchmark for application, by using a command written below -
go test -run=xxx -bench=. -cpuprofile profile_cpu.out
What are the best Performance Profiling tools?Below the well-known performance profiling tools that support to speed up the coding and to make it run more quickly.