Debian Codegraph @

internal/report/testdata/sample/sample.go

raw symbols SCIP
1 // Copyright 2017 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // sample program that is used to produce some of the files in
16 // pprof/internal/report/testdata.
17 package main
18
19 import (
20 "flag"
21 "fmt"
22 "log"
23 "math"
24 "os"
25 "runtime/pprof"
26 )
27
28 var cpuProfile = flag.String("cpuprofile", "", "where to write cpu profile")
29
30 func main() {
31 flag.Parse()
32 f, err := os.Create(*cpuProfile)
33 if err != nil {
34 log.Fatal("could not create CPU profile: ", err)
35 }
36 if err := pprof.StartCPUProfile(f); err != nil {
37 log.Fatal("could not start CPU profile: ", err)
38 }
39 defer pprof.StopCPUProfile()
40 busyLoop()
41 }
42
43 func busyLoop() {
44 m := make(map[int]int)
45 for i := 0; i < 1000000; i++ {
46 m[i] = i + 10
47 }
48 var sum float64
49 for i := 0; i < 100; i++ {
50 for _, v := range m {
51 sum += math.Abs(float64(v))
52 }
53 }
54 fmt.Println("Sum", sum)
55 }