...

Source file src/cmd/pprof/testdata/cpu.go

Documentation: cmd/pprof/testdata

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"flag"
     9  	"fmt"
    10  	"os"
    11  	"runtime/pprof"
    12  	"time"
    13  )
    14  
    15  var output = flag.String("output", "", "pprof profile output file")
    16  
    17  func main() {
    18  	flag.Parse()
    19  	if *output == "" {
    20  		fmt.Fprintf(os.Stderr, "usage: %s -output file.pprof\n", os.Args[0])
    21  		os.Exit(2)
    22  	}
    23  
    24  	f, err := os.Create(*output)
    25  	if err != nil {
    26  		fmt.Fprintln(os.Stderr, err)
    27  		os.Exit(2)
    28  	}
    29  	defer f.Close()
    30  
    31  	if err := pprof.StartCPUProfile(f); err != nil {
    32  		fmt.Fprintln(os.Stderr, err)
    33  		os.Exit(2)
    34  	}
    35  	defer pprof.StopCPUProfile()
    36  
    37  	// Spin for long enough to collect some samples.
    38  	start := time.Now()
    39  	for time.Since(start) < time.Second {
    40  	}
    41  }
    42  

View as plain text