示例#1
0
func main() {
	trace.Start(os.Stderr)
	http.HandleFunc("/", handler)
	go http.ListenAndServe(":5000", nil)
	time.Sleep(100 * time.Millisecond)
	trace.Stop()
}
示例#2
0
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()
}
示例#3
0
文件: leak.go 项目: divan/talks
func main() {
	trace.Start(os.Stderr)
	for i := 0; i < 1000; i++ {
		go leaker()
	}
	trace.Stop()
}
示例#4
0
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)
}
示例#5
0
文件: hooks.go 项目: gkalabin/goprof
func startWritingTrace(profilesDir string) error {
	traceFile, err := os.Create(filepath.Join(profilesDir, "trace"))
	if err != nil {
		return err
	}
	return trace.Start(traceFile)
}
示例#6
0
文件: app.go 项目: sbinet/tmvl
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,
		)
	}
}
示例#7
0
func main() {
	trace.Start(os.Stderr)
	for i := 0; i < 360/10; i++ {
		go leaker()
	}
	time.Sleep(25 * time.Millisecond)
	trace.Stop()
}
示例#8
0
文件: timer_orig.go 项目: divan/talks
func main() {
	trace.Start(os.Stderr)
	for i := 0; i < 24; i++ {
		c := tick(100 * time.Millisecond)
		<-c
	}
	trace.Stop()
}
示例#9
0
func main() {
	trace.Start(os.Stderr)
	var wg sync.WaitGroup
	wg.Add(36)
	go pool(&wg, 36, 36)
	wg.Wait()
	trace.Stop()
}
示例#10
0
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)
			}
		}
	}
}
示例#11
0
文件: trace.go 项目: achanda/go
func traceHandlerGo17(traceprofile string) {
	f, err := os.Create(traceprofile)
	if err != nil {
		Fatalf("%v", err)
	}
	if err := tracepkg.Start(f); err != nil {
		Fatalf("%v", err)
	}
	atExit(tracepkg.Stop)
}
示例#12
0
func main() {
	var b bytes.Buffer
	trace.Start(&b)
	log.SetFlags(log.Ltime | log.Lshortfile)

	log.Println("first log output")
	log.Printf("second log output\n")
	fn()
	log.Printf("tace: %v\n", b.String())
}
示例#13
0
func doTrace() func() {
	if *traceProfile != "" {
		bw, flush := bufferedFileWriter(*traceProfile)
		trace.Start(bw)
		return func() {
			flush()
			trace.Stop()
		}
	}
	return func() {}
}
示例#14
0
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)
}
示例#15
0
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()
}
示例#16
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)
	}
}
示例#17
0
func (t *logicTest) traceStart(filename string) {
	if t.traceFile != nil {
		t.Fatalf("tracing already active")
	}
	var err error
	t.traceFile, err = os.Create(filename)
	if err != nil {
		t.Fatalf("unable to open trace output file: %s", err)
	}
	if err := trace.Start(t.traceFile); err != nil {
		t.Fatalf("unable to start tracing: %s", err)
	}
}
示例#18
0
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()
}
示例#19
0
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()
}
示例#20
0
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()
}
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)
	}
}
示例#22
0
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()
}
示例#23
0
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()
}
示例#24
0
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()
}
示例#25
0
文件: range.go 项目: yujinqiu/gotrace
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()
}
示例#26
0
文件: main.go 项目: cr0sh/Rockit-LMS
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	dbg := flag.Bool("d", false, "sets loglevel to 0(debug) if set")
	tr := flag.Bool("t", false, "prints execution trace log to Stdout - DO NOT USE NOW")
	flag.Parse()
	if *dbg {
		logger.SetLevel(0)
	}
	if *tr {
		trace.Start(os.Stdout)
	}
	server := server.Server{ServerID: uint64(rand.Uint32()), Socket: *new(network.Socket)}
	if err := server.Socket.Open(19132); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	server.Start()
}
示例#27
0
文件: block.go 项目: yujinqiu/gotrace
// 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()
}
示例#28
0
// StartGoTrace turns on tracing, writing to the given file.
func (h *HandlerT) StartGoTrace(file string) error {
	h.mu.Lock()
	defer h.mu.Unlock()
	if h.traceW != nil {
		return errors.New("trace already in progress")
	}
	f, err := os.Create(expandHome(file))
	if err != nil {
		return err
	}
	if err := trace.Start(f); err != nil {
		f.Close()
		return err
	}
	h.traceW = f
	h.traceFile = file
	glog.V(logger.Info).Infoln("trace started, writing to", h.traceFile)
	return nil
}
示例#29
0
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()
}
示例#30
0
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)
	}
}