func main() { trace.Start(os.Stderr) http.HandleFunc("/", handler) go http.ListenAndServe(":5000", nil) time.Sleep(100 * time.Millisecond) trace.Stop() }
func main() { trace.Start(os.Stderr) for i := 0; i < 1000; i++ { go leaker() } trace.Stop() }
func main() { trace.Start(os.Stderr) ch, ch1 := make(chan int), make(chan int) out := make(chan int) go func() { for i := 0; i < 20; i++ { v := <-out fmt.Println("Recv ", v) time.Sleep(100 * time.Microsecond) } }() go func() { for i := 0; i < 10; i++ { ch <- i } }() go func() { for i := 0; i < 10; i++ { ch <- i } }() for i := 0; i < 20; i++ { select { case v := <-ch: out <- v case v := <-ch1: out <- v } } trace.Stop() }
func (t *logicTest) traceStop() { if t.traceFile != nil { trace.Stop() t.traceFile.Close() t.traceFile = nil } }
func main() { f, err := os.Create("trace") if err != nil { panic(err) } defer func() { if err := f.Close(); err != nil { panic(err) } }() trace.Start(f) for i := 0; i < 10; i++ { go bob(i) } time.Sleep(time.Duration(20) * time.Second) fmt.Println("writing trace") trace.Stop() time.Sleep(time.Duration(100) * time.Second) }
func main(f func(*App)) { flag.Parse() if app.fprof != "" { fprof, err := os.Create(app.fprof) if err != nil { log.Fatalf("error creating pprof output file [%s]: %v\n", app.fprof, err, ) } defer fprof.Close() pprof.StartCPUProfile(fprof) defer pprof.StopCPUProfile() } if app.ftrace != "" { ftrace, err := os.Create(app.ftrace) if err != nil { log.Fatalf("error creating trace output file: %v\n", err) } defer ftrace.Close() trace.Start(ftrace) defer trace.Stop() } fout, err := os.Create(app.fname) if err != nil { log.Fatalf("error creating output file [%s]: %v\n", app.fname, err, ) } defer fout.Close() go app.write(fout) app.errc = make(chan error, app.nconc) app.resc = make(chan Result, app.nconc) go f(app) for i := 0; i < app.nevts; i++ { err := <-app.errc if err != nil { log.Fatalf("error: %v\n", err) } } close(app.resc) close(app.errc) err = fout.Close() if err != nil { log.Fatalf("error closing output file [%s]: %v\n", app.fname, err, ) } }
func main() { trace.Start(os.Stderr) for i := 0; i < 24; i++ { c := tick(100 * time.Millisecond) <-c } trace.Stop() }
func main() { trace.Start(os.Stderr) var wg sync.WaitGroup wg.Add(36) go pool(&wg, 36, 36) wg.Wait() trace.Stop() }
func main() { trace.Start(os.Stderr) for i := 0; i < 360/10; i++ { go leaker() } time.Sleep(25 * time.Millisecond) trace.Stop() }
func gofmtMain() { flag.Usage = usage paths := parseFlags() if *cpuProfile != "" { bw, flush := bufferedFileWriter(*cpuProfile) pprof.StartCPUProfile(bw) defer flush() defer pprof.StopCPUProfile() } if *traceProfile != "" { bw, flush := bufferedFileWriter(*traceProfile) trace.Start(bw) defer flush() defer trace.Stop() } if *memProfileRate > 0 { runtime.MemProfileRate = *memProfileRate bw, flush := bufferedFileWriter(*memProfile) defer func() { runtime.GC() // materialize all statistics if err := pprof.WriteHeapProfile(bw); err != nil { log.Fatal(err) } flush() }() } if *verbose { log.SetFlags(log.LstdFlags | log.Lmicroseconds) imports.Debug = true } if options.TabWidth < 0 { fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", options.TabWidth) exitCode = 2 return } if len(paths) == 0 { if err := processFile("<standard input>", os.Stdin, os.Stdout, true); err != nil { report(err) } return } for _, path := range paths { switch dir, err := os.Stat(path); { case err != nil: report(err) case dir.IsDir(): walkDir(path) default: if err := processFile(path, nil, os.Stdout, false); err != nil { report(err) } } } }
func doTrace() func() { if *traceProfile != "" { bw, flush := bufferedFileWriter(*traceProfile) trace.Start(bw) return func() { flush() trace.Stop() } } return func() {} }
func main() { trace.Start(os.Stderr) runtime.GOMAXPROCS(24) in := make(chan int) out := make(chan int) go pool(in, out) go generate(in) go print(out) time.Sleep(1 * time.Second) trace.Stop() }
func main() { trace.Start(os.Stderr) runtime.GOMAXPROCS(1) in := make(chan int) out := make(chan int) go pool(in, out) go generate(in) print(out) trace.Stop() os.Exit(0) }
// MakeTrace POST Trace binaries to the deferpanic website func (c *DeferPanicClient) MakeTrace(commandId int, agent *Agent) { var buf []byte buffer := bytes.NewBuffer(buf) c.Lock() c.RunningCommands[commandId] = true c.Unlock() defer func() { c.Lock() delete(c.RunningCommands, commandId) c.Unlock() }() log.Println("trace started") err := trace.Start(buffer) if err != nil { log.Println(err) return } select { case <-time.After(30 * time.Second): trace.Stop() log.Println("trace finished") out := make([]byte, len(buffer.Bytes())) copy(out, buffer.Bytes()) pkgpath, err := filepath.Abs(os.Args[0]) if err != nil { log.Println(err) return } pkg, err := ioutil.ReadFile(pkgpath) if err != nil { log.Println(err) return } crc32 := crc32.ChecksumIEEE(pkg) size := int64(len(pkg)) if agent.CRC32 == crc32 && agent.Size == size { pkg = []byte{} } t := NewTrace(out, pkg, commandId, false) b, err := json.Marshal(t) if err != nil { log.Println(err) return } c.Postit(b, traceUrl, false) } }
func main() { trace.Start(os.Stderr) var Ball int table := make(chan int) go player(table) go player(table) table <- Ball time.Sleep(1 * time.Second) <-table trace.Stop() }
// StopTrace stops an ongoing trace. func (h *HandlerT) StopGoTrace() error { h.mu.Lock() defer h.mu.Unlock() trace.Stop() if h.traceW == nil { return errors.New("trace not in progress") } glog.V(logger.Info).Infoln("done writing trace to", h.traceFile) h.traceW.Close() h.traceW = nil h.traceFile = "" return nil }
func main() { trace.Start(os.Stderr) ch := make(chan int) out := make(chan int) go producer(ch, 10*time.Millisecond) go producer(ch, 25*time.Millisecond) go reader(out) for i := 0; i < 20; i++ { i := <-ch out <- i } trace.Stop() }
func main() { trace.Start(os.Stderr) ch := make(chan int) go Generate(ch) for i := 0; i < 10; i++ { prime := <-ch fmt.Println(prime) out := make(chan int) go Filter(ch, out, prime) ch = out } trace.Stop() }
func main() { flag.Parse() if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { log.Fatalln("Error creating file for profile.", err) } err = pprof.StartCPUProfile(f) if err != nil { log.Fatalln("Error starting CPU profile.", err) } // defer adds to list of things to execute when surrounding // function (not lexical block) returns. defer pprof.StopCPUProfile() } if *traceFilename != "" { f, err := os.Create(*traceFilename) if err != nil { log.Fatalln("Error creating file for trace.", err) } err = trace.Start(f) if err != nil { log.Fatalln("Error starting trace.", err) } defer trace.Stop() } digest, err := hex.DecodeString(*digestHexStr) if err != nil { log.Fatalln("Error parsing digest.", err) } if n := len(digest) * 8; n < 8 || n > 48 || n%8 != 0 { log.Fatalln("Invalid value for n.") } if d := *div; d > 64 { log.Fatalln("Invalid value for div.") } //pre := findPreImage(digest) pre := findPreImageConcurrent(digest, *div) if pre != nil { fmt.Println(hex.EncodeToString(pre)) } else { log.Println("No preimage found for ", *digestHexStr) } }
func main() { trace.Start(os.Stderr) fmt.Println("Listening on :5000. Send something using nc: echo hello | nc localhost 5000") fmt.Println("Exiting in 1 second...") l, err := net.Listen("tcp", ":5000") if err != nil { panic(err) } ch := make(chan int) go logger(ch) go server(l, ch) time.Sleep(1 * time.Second) trace.Stop() }
func main() { trace.Start(os.Stderr) // create new channel of type int ch := make(chan int) // start new anonymous goroutine go func() { // send 42 to channel time.Sleep(10 * time.Millisecond) ch <- 42 }() // read from channel <-ch trace.Stop() }
// after runs after all testing. func (m *M) after() { if *cpuProfile != "" { m.deps.StopCPUProfile() // flushes profile to disk } if *traceFile != "" { trace.Stop() // flushes trace to disk } if *memProfile != "" { f, err := os.Create(toOutputDir(*memProfile)) if err != nil { fmt.Fprintf(os.Stderr, "testing: %s\n", err) os.Exit(2) } runtime.GC() // materialize all statistics if err = m.deps.WriteHeapProfile(f); err != nil { fmt.Fprintf(os.Stderr, "testing: can't write %s: %s\n", *memProfile, err) os.Exit(2) } f.Close() } if *blockProfile != "" && *blockProfileRate >= 0 { f, err := os.Create(toOutputDir(*blockProfile)) if err != nil { fmt.Fprintf(os.Stderr, "testing: %s\n", err) os.Exit(2) } if err = m.deps.WriteProfileTo("block", f, 0); err != nil { fmt.Fprintf(os.Stderr, "testing: can't write %s: %s\n", *blockProfile, err) os.Exit(2) } f.Close() } if *mutexProfile != "" && *mutexProfileFraction >= 0 { f, err := os.Create(toOutputDir(*mutexProfile)) if err != nil { fmt.Fprintf(os.Stderr, "testing: %s\n", err) os.Exit(2) } if err = m.deps.WriteProfileTo("mutex", f, 0); err != nil { fmt.Fprintf(os.Stderr, "testing: can't write %s: %s\n", *blockProfile, err) os.Exit(2) } f.Close() } if cover.Mode != "" { coverReport() } }
func main() { trace.Start(os.Stderr) ch := make(chan int) go func(ch chan int) { for i := 0; i < 10; i++ { time.Sleep(10 * time.Millisecond) ch <- i } close(ch) }(ch) for v := range ch { fmt.Println(v) } trace.Stop() }
func main() { trace.Start(os.Stderr) var Ball int table := make(chan int) for i := 0; i < 36; i++ { // this sleep is added to more or less preserve an order // of the goroutines id on creation time.Sleep(10 * time.Millisecond) go player(table) } table <- Ball time.Sleep(1 * time.Second) <-table trace.Stop() }
// This example shows blocked state and some CPU usage visualization func main() { trace.Start(os.Stderr) time.Sleep(10 * time.Millisecond) ch := make(chan int) go func() { time.Sleep(10 * time.Millisecond) for i := 0; i < 10000000; i++ { j := math.Sqrt(float64(i * i)) j *= j * float64(i) _ = j } ch <- 42 time.Sleep(10 * time.Millisecond) }() <-ch time.Sleep(100 * time.Millisecond) trace.Stop() }
func main() { trace.Start(os.Stderr) fmt.Println("Listening on :5000. Send something using nc: echo hello | nc localhost 5000") fmt.Println("Exiting in 1 second...") go time.AfterFunc(1*time.Second, func() { trace.Stop(); os.Exit(0) }) l, err := net.Listen("tcp", ":5000") if err != nil { panic(err) } for { c, err := l.Accept() if err != nil { continue } go handler(c) } }
func main() { trace.Start(os.Stderr) var wg sync.WaitGroup wg.Add(WORKERS) tasks := make(chan int) for i := 0; i < WORKERS; i++ { time.Sleep(1 * time.Millisecond) go worker(tasks, &wg) } for i := 0; i < TASKS; i++ { tasks <- i } close(tasks) wg.Wait() trace.Stop() }
// Trace responds with the execution trace in binary form. // Tracing lasts for duration specified in seconds GET parameter, or for 1 second if not specified. // The package initialization registers it as /debug/pprof/trace. func Trace(w http.ResponseWriter, r *http.Request) { sec, _ := strconv.ParseInt(r.FormValue("seconds"), 10, 64) if sec == 0 { sec = 1 } // Set Content Type assuming trace.Start will work, // because if it does it starts writing. w.Header().Set("Content-Type", "application/octet-stream") if err := trace.Start(w); err != nil { // trace.Start failed, so no writes yet. // Can change header back to text content and send error code. w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(w, "Could not enable tracing: %s\n", err) return } time.Sleep(time.Duration(sec) * time.Second) trace.Stop() }
func (s *server) signalToggleTrace() { if s.traceFile == nil { traceFile, err := ioutil.TempFile("", common.ProductName+"_Trace_") if goshawk.CheckWarn(err) { return } if goshawk.CheckWarn(trace.Start(traceFile)) { return } s.traceFile = traceFile log.Println("Tracing started in", traceFile.Name()) } else { trace.Stop() if !goshawk.CheckWarn(s.traceFile.Close()) { log.Println("Tracing stopped in", s.traceFile.Name()) } s.traceFile = nil } }
func main() { cfg := &config{} cmd := writ.New("devo", cfg) cmd.Help.Usage = usage cmd.Help.Header = header cmd.Help.Footer = footer _, positional, err := cmd.Decode(os.Args[1:]) if err != nil || cfg.HelpFlag { cmd.ExitHelp(err) } if cfg.VersionFlag { fmt.Fprintf(os.Stdout, "DeVo version %d.%d.%d\nCompiled with %s\n", devo.Version.Major, devo.Version.Minor, devo.Version.Patch, runtime.Version()) os.Exit(0) } if len(positional) != 0 { cmd.ExitHelp(fmt.Errorf("too many arguments provided")) } err = cfg.validate() if err != nil { cmd.ExitHelp(err) } if cfg.TraceOutput != nil { defer cfg.TraceOutput.Close() err = trace.Start(cfg.TraceOutput) check(err) defer trace.Stop() } if cfg.ProfileOutput != nil { defer cfg.ProfileOutput.Close() err = pprof.StartCPUProfile(cfg.ProfileOutput) check(err) defer pprof.StopCPUProfile() } defer cfg.Output.Close() check(devo.Decrypt(cfg.Output, cfg.Input, cfg.AccessKey)) }