mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-12-24 13:48:04 +08:00
feat: add pprof
This commit is contained in:
10
plugin/debug/pkg/internal/report/testdata/README.md
vendored
Normal file
10
plugin/debug/pkg/internal/report/testdata/README.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
sample/ contains a sample program that can be profiled.
|
||||
sample.bin is its x86-64 binary.
|
||||
sample.cpu is a profile generated by sample.bin.
|
||||
|
||||
To update the binary and profile:
|
||||
|
||||
```shell
|
||||
go build -o sample.bin ./sample
|
||||
./sample.bin -cpuprofile sample.cpu
|
||||
```
|
||||
BIN
plugin/debug/pkg/internal/report/testdata/sample.bin
vendored
Executable file
BIN
plugin/debug/pkg/internal/report/testdata/sample.bin
vendored
Executable file
Binary file not shown.
BIN
plugin/debug/pkg/internal/report/testdata/sample.cpu
vendored
Normal file
BIN
plugin/debug/pkg/internal/report/testdata/sample.cpu
vendored
Normal file
Binary file not shown.
55
plugin/debug/pkg/internal/report/testdata/sample/sample.go
vendored
Normal file
55
plugin/debug/pkg/internal/report/testdata/sample/sample.go
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2017 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// sample program that is used to produce some of the files in
|
||||
// pprof/internal/report/testdata.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
var cpuProfile = flag.String("cpuprofile", "", "where to write cpu profile")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
f, err := os.Create(*cpuProfile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create CPU profile: ", err)
|
||||
}
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatal("could not start CPU profile: ", err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
busyLoop()
|
||||
}
|
||||
|
||||
func busyLoop() {
|
||||
m := make(map[int]int)
|
||||
for i := 0; i < 1000000; i++ {
|
||||
m[i] = i + 10
|
||||
}
|
||||
var sum float64
|
||||
for i := 0; i < 100; i++ {
|
||||
for _, v := range m {
|
||||
sum += math.Abs(float64(v))
|
||||
}
|
||||
}
|
||||
fmt.Println("Sum", sum)
|
||||
}
|
||||
17
plugin/debug/pkg/internal/report/testdata/source.dot
vendored
Normal file
17
plugin/debug/pkg/internal/report/testdata/source.dot
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
digraph "unnamed" {
|
||||
node [style=filled fillcolor="#f8f8f8"]
|
||||
subgraph cluster_L { "Duration: 10s, Total samples = 11111 " [shape=box fontsize=16 label="Duration: 10s, Total samples = 11111 \lShowing nodes accounting for 11111, 100% of 11111 total\l\lSee https://git.io/JfYMW for how to read the graph\l"] }
|
||||
N1 [label="tee\nsource2:8\n10000 (90.00%)" id="node1" fontsize=24 shape=box tooltip="tee testdata/source2:8 (10000)" color="#b20500" fillcolor="#edd6d5"]
|
||||
N2 [label="main\nsource1:2:2\n1 (0.009%)\nof 11111 (100%)" id="node2" fontsize=9 shape=box tooltip="main testdata/source1:2:2 (11111)" color="#b20000" fillcolor="#edd5d5"]
|
||||
N3 [label="tee\nsource2:2\n1000 (9.00%)\nof 11000 (99.00%)" id="node3" fontsize=14 shape=box tooltip="tee testdata/source2:2 (11000)" color="#b20000" fillcolor="#edd5d5"]
|
||||
N4 [label="tee\nsource2:8\n100 (0.9%)" id="node4" fontsize=10 shape=box tooltip="tee testdata/source2:8 (100)" color="#b2b0aa" fillcolor="#edecec"]
|
||||
N5 [label="bar\nsource1:10\n10 (0.09%)" id="node5" fontsize=9 shape=box tooltip="bar testdata/source1:10 (10)" color="#b2b2b1" fillcolor="#ededed"]
|
||||
N6 [label="bar\nsource1:10\n0 of 100 (0.9%)" id="node6" fontsize=8 shape=box tooltip="bar testdata/source1:10 (100)" color="#b2b0aa" fillcolor="#edecec"]
|
||||
N7 [label="foo\nsource1:4:4\n0 of 10 (0.09%)" id="node7" fontsize=8 shape=box tooltip="foo testdata/source1:4:4 (10)" color="#b2b2b1" fillcolor="#ededed"]
|
||||
N2 -> N3 [label=" 11000" weight=100 penwidth=5 color="#b20000" tooltip="main testdata/source1:2:2 -> tee testdata/source2:2 (11000)" labeltooltip="main testdata/source1:2:2 -> tee testdata/source2:2 (11000)"]
|
||||
N3 -> N1 [label=" 10000" weight=91 penwidth=5 color="#b20500" tooltip="tee testdata/source2:2 -> tee testdata/source2:8 (10000)" labeltooltip="tee testdata/source2:2 -> tee testdata/source2:8 (10000)"]
|
||||
N6 -> N4 [label=" 100" color="#b2b0aa" tooltip="bar testdata/source1:10 -> tee testdata/source2:8 (100)" labeltooltip="bar testdata/source1:10 -> tee testdata/source2:8 (100)"]
|
||||
N2 -> N6 [label=" 100" color="#b2b0aa" tooltip="main testdata/source1:2:2 -> bar testdata/source1:10 (100)" labeltooltip="main testdata/source1:2:2 -> bar testdata/source1:10 (100)"]
|
||||
N7 -> N5 [label=" 10" color="#b2b2b1" tooltip="foo testdata/source1:4:4 -> bar testdata/source1:10 (10)" labeltooltip="foo testdata/source1:4:4 -> bar testdata/source1:10 (10)"]
|
||||
N2 -> N7 [label=" 10" color="#b2b2b1" tooltip="main testdata/source1:2:2 -> foo testdata/source1:4:4 (10)" labeltooltip="main testdata/source1:2:2 -> foo testdata/source1:4:4 (10)"]
|
||||
}
|
||||
49
plugin/debug/pkg/internal/report/testdata/source.rpt
vendored
Normal file
49
plugin/debug/pkg/internal/report/testdata/source.rpt
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
Total: 11111
|
||||
ROUTINE ======================== bar in testdata/source1
|
||||
10 110 (flat, cum) 0.99% of Total
|
||||
. . 5:source1 line 5;
|
||||
. . 6:source1 line 6;
|
||||
. . 7:source1 line 7;
|
||||
. . 8:source1 line 8;
|
||||
. . 9:source1 line 9;
|
||||
10 110 10:source1 line 10;
|
||||
. . 11:source1 line 11;
|
||||
. . 12:source1 line 12;
|
||||
. . 13:source1 line 13;
|
||||
. . 14:source1 line 14;
|
||||
. . 15:source1 line 15;
|
||||
ROUTINE ======================== foo in testdata/source1
|
||||
0 10 (flat, cum) 0.09% of Total
|
||||
. . 1:source1 line 1;
|
||||
. . 2:source1 line 2;
|
||||
. . 3:source1 line 3;
|
||||
. 10 4:source1 line 4;
|
||||
. . 5:source1 line 5;
|
||||
. . 6:source1 line 6;
|
||||
. . 7:source1 line 7;
|
||||
. . 8:source1 line 8;
|
||||
. . 9:source1 line 9;
|
||||
ROUTINE ======================== main in testdata/source1
|
||||
1 11111 (flat, cum) 100% of Total
|
||||
. . 1:source1 line 1;
|
||||
1 11111 2:source1 line 2;
|
||||
. . 3:source1 line 3;
|
||||
. . 4:source1 line 4;
|
||||
. . 5:source1 line 5;
|
||||
. . 6:source1 line 6;
|
||||
. . 7:source1 line 7;
|
||||
ROUTINE ======================== tee in testdata/source2
|
||||
11100 21100 (flat, cum) 189.90% of Total
|
||||
. . 1:source2 line 1;
|
||||
1000 11000 2:source2 line 2;
|
||||
. . 3:source2 line 3;
|
||||
. . 4:source2 line 4;
|
||||
. . 5:source2 line 5;
|
||||
. . 6:source2 line 6;
|
||||
. . 7:source2 line 7;
|
||||
10100 10100 8:source2 line 8;
|
||||
. . 9:source2 line 9;
|
||||
. . 10:source2 line 10;
|
||||
. . 11:source2 line 11;
|
||||
. . 12:source2 line 12;
|
||||
. . 13:source2 line 13;
|
||||
19
plugin/debug/pkg/internal/report/testdata/source1
vendored
Normal file
19
plugin/debug/pkg/internal/report/testdata/source1
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
source1 line 1;
|
||||
source1 line 2;
|
||||
source1 line 3;
|
||||
source1 line 4;
|
||||
source1 line 5;
|
||||
source1 line 6;
|
||||
source1 line 7;
|
||||
source1 line 8;
|
||||
source1 line 9;
|
||||
source1 line 10;
|
||||
source1 line 11;
|
||||
source1 line 12;
|
||||
source1 line 13;
|
||||
source1 line 14;
|
||||
source1 line 15;
|
||||
source1 line 16;
|
||||
source1 line 17;
|
||||
source1 line 18;
|
||||
|
||||
19
plugin/debug/pkg/internal/report/testdata/source2
vendored
Normal file
19
plugin/debug/pkg/internal/report/testdata/source2
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
source2 line 1;
|
||||
source2 line 2;
|
||||
source2 line 3;
|
||||
source2 line 4;
|
||||
source2 line 5;
|
||||
source2 line 6;
|
||||
source2 line 7;
|
||||
source2 line 8;
|
||||
source2 line 9;
|
||||
source2 line 10;
|
||||
source2 line 11;
|
||||
source2 line 12;
|
||||
source2 line 13;
|
||||
source2 line 14;
|
||||
source2 line 15;
|
||||
source2 line 16;
|
||||
source2 line 17;
|
||||
source2 line 18;
|
||||
|
||||
Reference in New Issue
Block a user