skip to content
Alvin Lucillo

CPU profile source line view

/ 1 min read

Using yesterday’s BenchmarkCountAllowedEvents, if we want to see the source code view associated to the CPU work, use -list, which allows you to supply a regular fexpression to match function names.

In the result, we can see which part of the code has the majority of the CPU work, which is slices.Contains

go tool pprof \
  -list=codec01.CountAllowedEventsLinear \
  /tmp/codec01-allowlist-linear-cpu.pprof
Total: 6.14s
ROUTINE ======================== codec01.CountAllowedEventsLinear in /home/allowlist.go
      20ms      6.14s (flat, cum)   100% of Total
         .          .     11:func CountAllowedEventsLinear(eventNames, allowedNames []string) int {
         .          .     12:   count := 0
      20ms       20ms     13:   for _, name := range eventNames {
         .      6.12s     14:           if slices.Contains(allowedNames, name) {
         .          .     15:                   count++
         .          .     16:           }
         .          .     17:   }
         .          .     18:   return count
         .          .     19:}