diff options
Diffstat (limited to 'content/posts/2017-03-07-golang-profiling-simplified.md')
| -rw-r--r-- | content/posts/2017-03-07-golang-profiling-simplified.md | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/content/posts/2017-03-07-golang-profiling-simplified.md b/content/posts/2017-03-07-golang-profiling-simplified.md index 7eee2dd..4bd18b2 100644 --- a/content/posts/2017-03-07-golang-profiling-simplified.md +++ b/content/posts/2017-03-07-golang-profiling-simplified.md | |||
| @@ -6,34 +6,34 @@ draft: false | |||
| 6 | --- | 6 | --- |
| 7 | 7 | ||
| 8 | Many posts have been written regarding profiling in Golang and I haven’t found | 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 | 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 | 10 | important information and it gets pretty frustrating when you have a deadline |
| 11 | and are not finding simple distilled solution. | 11 | and are not finding simple distilled solution. |
| 12 | 12 | ||
| 13 | Nevertheless, after searching and experimenting I have found a solution that | 13 | Nevertheless, after searching and experimenting I have found a solution that |
| 14 | works for me and probably should also for you. | 14 | works for me and probably should also for you. |
| 15 | 15 | ||
| 16 | ## Where are my pprof files? | 16 | ## Where are my pprof files? |
| 17 | 17 | ||
| 18 | By default pprof files are generated in /tmp/ folder. You can override folder | 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 | 19 | where this files are generated programmatically in your golang code as we will |
| 20 | see below in example. | 20 | see below in example. |
| 21 | 21 | ||
| 22 | ## Why is my CPU profile empty? | 22 | ## Why is my CPU profile empty? |
| 23 | 23 | ||
| 24 | I have found out that sometimes CPU profile is empty because program was not | 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 | 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. | 26 | file in my cases. Well, file is generated but only contains 4KB of information. |
| 27 | 27 | ||
| 28 | ## Profiling | 28 | ## Profiling |
| 29 | 29 | ||
| 30 | As you can see from examples we are executing dummy_benchmark functions to | 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 | 31 | ensure some sort of execution. Memory profiling can be done without such a |
| 32 | “complex” function. But CPU profiling needs it. | 32 | “complex” function. But CPU profiling needs it. |
| 33 | 33 | ||
| 34 | Both memory and CPU profiling examples are almost the same. Only parameters | 34 | Both memory and CPU profiling examples are almost the same. Only parameters in |
| 35 | in main function when calling profile.Start are different. When we set | 35 | main function when calling profile.Start are different. When we set |
| 36 | profile.ProfilePath(“.”) we tell profiler to store pprof files in the same | 36 | profile.ProfilePath(“.”) we tell profiler to store pprof files in the same |
| 37 | folder as our program. | 37 | folder as our program. |
| 38 | 38 | ||
| 39 | ### Memory profiling | 39 | ### Memory profiling |
