aboutsummaryrefslogtreecommitdiff
path: root/content/posts/2017-03-07-golang-profiling-simplified.md
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2023-05-26 00:40:40 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2023-05-26 00:40:40 +0200
commit43b0708769eb61392050045b881f8e6ba39c5b66 (patch)
tree3939579a13b8325325d5ebb8e05324a41ed78a6d /content/posts/2017-03-07-golang-profiling-simplified.md
parent49e7e7d555a6cd9810d81561fa3e98e3d64502be (diff)
downloadmitjafelicijan.com-43b0708769eb61392050045b881f8e6ba39c5b66.tar.gz
Massive update to posts, archetypes
Added a archetypes for creating notes and posts so it auto-populates fields. Fixed existing posts so they align with the rule of 80 columns now.
Diffstat (limited to 'content/posts/2017-03-07-golang-profiling-simplified.md')
-rw-r--r--content/posts/2017-03-07-golang-profiling-simplified.md28
1 files changed, 21 insertions, 7 deletions
diff --git a/content/posts/2017-03-07-golang-profiling-simplified.md b/content/posts/2017-03-07-golang-profiling-simplified.md
index 92ff881..7eee2dd 100644
--- a/content/posts/2017-03-07-golang-profiling-simplified.md
+++ b/content/posts/2017-03-07-golang-profiling-simplified.md
@@ -1,27 +1,40 @@
1--- 1---
2title: Golang profiling simplified 2title: Golang profiling simplified
3url: golang-profiling-simplified.html 3url: golang-profiling-simplified.html
4date: 2017-03-07 4date: 2017-03-07T12:00:00+02:00
5draft: false 5draft: false
6--- 6---
7 7
8Many posts have been written regarding profiling in Golang and I haven’t found proper tutorial regarding this. Almost all of them are missing some part of important information and it gets pretty frustrating when you have a deadline and are not finding simple distilled solution. 8Many posts have been written regarding profiling in Golang and I haven’t found
9proper tutorial regarding this. Almost all of them are missing some part of
10important information and it gets pretty frustrating when you have a deadline
11and are not finding simple distilled solution.
9 12
10Nevertheless, after searching and experimenting I have found a solution that works for me and probably should also for you. 13Nevertheless, after searching and experimenting I have found a solution that
14works for me and probably should also for you.
11 15
12## Where are my pprof files? 16## Where are my pprof files?
13 17
14By default pprof files are generated in /tmp/ folder. You can override folder where this files are generated programmatically in your golang code as we will see below in example. 18By default pprof files are generated in /tmp/ folder. You can override folder
19where this files are generated programmatically in your golang code as we will
20see below in example.
15 21
16## Why is my CPU profile empty? 22## Why is my CPU profile empty?
17 23
18I have found out that sometimes CPU profile is empty because program was not executing long enough. Programs, that execute too quickly don’t produce pprof file in my cases. Well, file is generated but only contains 4KB of information. 24I have found out that sometimes CPU profile is empty because program was not
25executing long enough. Programs, that execute too quickly don’t produce pprof
26file in my cases. Well, file is generated but only contains 4KB of information.
19 27
20## Profiling 28## Profiling
21 29
22As you can see from examples we are executing dummy_benchmark functions to ensure some sort of execution. Memory profiling can be done without such a “complex” function. But CPU profiling needs it. 30As you can see from examples we are executing dummy_benchmark functions to
31ensure some sort of execution. Memory profiling can be done without such a
32“complex” function. But CPU profiling needs it.
23 33
24Both memory and CPU profiling examples are almost the same. Only parameters in main function when calling profile.Start are different. When we set profile.ProfilePath(“.”) we tell profiler to store pprof files in the same folder as our program. 34Both memory and CPU profiling examples are almost the same. Only parameters
35in main function when calling profile.Start are different. When we set
36profile.ProfilePath(“.”) we tell profiler to store pprof files in the same
37folder as our program.
25 38
26### Memory profiling 39### Memory profiling
27 40
@@ -109,3 +122,4 @@ This will generate PDF document with visualized profile.
109 122
110- [Memory PDF profile example](/assets/go-profiling/golang-profiling-mem.pdf) 123- [Memory PDF profile example](/assets/go-profiling/golang-profiling-mem.pdf)
111- [CPU PDF profile example](/assets/go-profiling/golang-profiling-cpu.pdf) 124- [CPU PDF profile example](/assets/go-profiling/golang-profiling-cpu.pdf)
125