diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-05-26 00:40:40 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-05-26 00:40:40 +0200 |
| commit | 43b0708769eb61392050045b881f8e6ba39c5b66 (patch) | |
| tree | 3939579a13b8325325d5ebb8e05324a41ed78a6d /content/posts/2017-03-07-golang-profiling-simplified.md | |
| parent | 49e7e7d555a6cd9810d81561fa3e98e3d64502be (diff) | |
| download | mitjafelicijan.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.md | 28 |
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 | --- |
| 2 | title: Golang profiling simplified | 2 | title: Golang profiling simplified |
| 3 | url: golang-profiling-simplified.html | 3 | url: golang-profiling-simplified.html |
| 4 | date: 2017-03-07 | 4 | date: 2017-03-07T12:00:00+02:00 |
| 5 | draft: false | 5 | draft: false |
| 6 | --- | 6 | --- |
| 7 | 7 | ||
| 8 | Many 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. | 8 | Many posts have been written regarding profiling in Golang and I haven’t found |
| 9 | proper tutorial regarding this. Almost all of them are missing some part of | ||
| 10 | important information and it gets pretty frustrating when you have a deadline | ||
| 11 | and are not finding simple distilled solution. | ||
| 9 | 12 | ||
| 10 | Nevertheless, after searching and experimenting I have found a solution that works for me and probably should also for you. | 13 | Nevertheless, after searching and experimenting I have found a solution that |
| 14 | works for me and probably should also for you. | ||
| 11 | 15 | ||
| 12 | ## Where are my pprof files? | 16 | ## Where are my pprof files? |
| 13 | 17 | ||
| 14 | By 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. | 18 | By default pprof files are generated in /tmp/ folder. You can override folder |
| 19 | where this files are generated programmatically in your golang code as we will | ||
| 20 | see below in example. | ||
| 15 | 21 | ||
| 16 | ## Why is my CPU profile empty? | 22 | ## Why is my CPU profile empty? |
| 17 | 23 | ||
| 18 | I 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. | 24 | I have found out that sometimes CPU profile is empty because program was not |
| 25 | executing long enough. Programs, that execute too quickly don’t produce pprof | ||
| 26 | file in my cases. Well, file is generated but only contains 4KB of information. | ||
| 19 | 27 | ||
| 20 | ## Profiling | 28 | ## Profiling |
| 21 | 29 | ||
| 22 | As 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. | 30 | As you can see from examples we are executing dummy_benchmark functions to |
| 31 | ensure some sort of execution. Memory profiling can be done without such a | ||
| 32 | “complex” function. But CPU profiling needs it. | ||
| 23 | 33 | ||
| 24 | Both 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. | 34 | Both memory and CPU profiling examples are almost the same. Only parameters |
| 35 | in main function when calling profile.Start are different. When we set | ||
| 36 | profile.ProfilePath(“.”) we tell profiler to store pprof files in the same | ||
| 37 | folder 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 | |||
