当前位置: 首页>>代码示例>>Golang>>正文


Golang pprof.StopCPUProfile函数代码示例

本文整理汇总了Golang中runtime/pprof.StopCPUProfile函数的典型用法代码示例。如果您正苦于以下问题:Golang StopCPUProfile函数的具体用法?Golang StopCPUProfile怎么用?Golang StopCPUProfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了StopCPUProfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.Parse()

	if arguments.pprof {
		log.Println("pprof enabled")
		go func() {
			log.Println(http.ListenAndServe("localhost:6060", nil))
		}()

		fp, err := os.Create("backend.pprof")
		if err != nil {
			panic(err)
		}
		defer fp.Close()

		pprof.StartCPUProfile(fp)
		defer pprof.StopCPUProfile()
	}

	if err := loadTree(arguments.tree); err != nil {
		log.Println(err)
		os.Exit(-1)
	}

	http.Handle("/", http.FileServer(http.Dir(arguments.web)))
	http.Handle("/render", websocket.Handler(renderServer))

	log.Println("waiting for connections...")
	if err := http.ListenAndServe(fmt.Sprintf(":%v", arguments.port), nil); err != nil {
		log.Println(err)
		os.Exit(-1)
	}
}
开发者ID:andreas-jonsson,项目名称:octatron,代码行数:33,代码来源:backend.go

示例2: main

func main() {
	f, err := os.Create("currentsrv.prof")
	if err != nil {
		log.Fatal(err)
	}
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		select {
		case <-c:
			log.Println("Stop profiling")
			pprof.StopCPUProfile()
			syscall.Exit(0)
		}
	}()

	props := property.Init()
	evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], props["mongodb.stream"])
	if err != nil {
		log.Fatalln("Error connecting to event store. ", err)
	}
	wsServer := wsock.NewServer(props["events.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	go processClientConnection(wsServer, evStore)
	go wsServer.Listen()

	//http.Handle(props["static.url"], http.FileServer(http.Dir("webroot")))
	err = http.ListenAndServe(props["events.url"], nil)
	evStore.Close()
}
开发者ID:vsysoev,项目名称:goeventstore,代码行数:34,代码来源:eventsrv.go

示例3: main

func main() {
	list_T := make([]*buffered.Token, M)
	list_D := make([]*buffered.Data, M)
	t := time.Now()
	f, _ := os.Create("with_bufferManager.prof")
	pprof.StartCPUProfile(f)
	m := buffered.NewBufferManager(M * 2)
	for i := 0; i < N; i++ {
		for j := 0; j < M; j++ {
			t := m.GetToken()
			t.Data.Str = "haha"
			list_T[j] = t
		}
		for j := 0; j < M; j++ {
			list_T[j].Return()
		}
	}
	fmt.Printf("With bufferManager:                    %v\n", time.Since(t))
	pprof.StopCPUProfile()

	t = time.Now()
	f, _ = os.Create("without_bufferManager.prof")
	pprof.StartCPUProfile(f)
	for i := 0; i < N; i++ {
		for j := 0; j < M; j++ {
			d := new(buffered.Data)
			d.Str = "haha"
			list_D[j] = d
		}
	}
	fmt.Printf("Without buffermanager (Relying on GC): %v\n", time.Since(t))
	pprof.StopCPUProfile()

}
开发者ID:postfix,项目名称:bufferManager.go,代码行数:34,代码来源:main.go

示例4: CPUProfile

func CPUProfile(cpuProfile string) func() {
	errors.Logf("DEBUG", "starting cpu profile: %v", cpuProfile)
	f, err := os.Create(cpuProfile)
	if err != nil {
		log.Fatal(err)
	}
	err = pprof.StartCPUProfile(f)
	if err != nil {
		log.Fatal(err)
	}
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		sig := <-sigs
		errors.Logf("DEBUG", "closing cpu profile")
		pprof.StopCPUProfile()
		err := f.Close()
		errors.Logf("DEBUG", "closed cpu profile, err: %v", err)
		panic(errors.Errorf("caught signal: %v", sig))
	}()
	return func() {
		errors.Logf("DEBUG", "closing cpu profile")
		pprof.StopCPUProfile()
		err := f.Close()
		errors.Logf("DEBUG", "closed cpu profile, err: %v", err)
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:27,代码来源:cmd.go

示例5: Start

// This is a blocking call, starts reverse proxy, connects to the backends, etc
func (s *Service) Start() error {
	if s.options.cpuProfile != "" {
		f, err := os.Create(s.options.cpuProfile)
		if err != nil {
			return err
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()

		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt)
		go func() {
			for sig := range c {
				glog.Errorf("captured %v, stopping profiler and exiting..", sig)
				pprof.StopCPUProfile()
				os.Exit(1)
			}
		}()
	}

	if err := s.writePid(); err != nil {
		return err
	}
	if err := s.startLogsCleanup(); err != nil {
		return err
	}

	proxy, err := s.initProxy()
	if err != nil {
		return err
	}
	s.proxy = proxy
	return s.startProxy()
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:35,代码来源:service.go

示例6: main

func main() {
	// Use as many procs as there are
	runtime.GOMAXPROCS(runtime.NumCPU())

	// Enable CPU profiling if the flag is set
	// -cpuprofile=logfile.log
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()

		// Catch CTRL+C and stop the profiling
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt)
		go func() {
			for sig := range c {
				log.Printf("captured %v, stopping profiler and exiting..", sig)
				pprof.StopCPUProfile()
				os.Exit(1)
			}
		}()
	}

	server.StartServer()
}
开发者ID:leobcn,项目名称:gosnippet,代码行数:29,代码来源:main.go

示例7: main

func main() {
	flag.Parse()

	if cpuprofile != "" {
		profFD, err := os.Create(cpuprofile)
		if err != nil {
			log.Fatalf("Cpuprofile: os.Create(): %v", err)
		}

		pprof.StartCPUProfile(profFD)
		defer pprof.StopCPUProfile()
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP,
		syscall.SIGPIPE)
	go func() {
		<-c

		if cpuprofile != "" {
			pprof.StopCPUProfile()
		}

		// In case we had a hang, we print the stack trace here.
		buf := make([]byte, 256*1024)
		n := runtime.Stack(buf, true)
		fmt.Fprintln(os.Stderr, string(buf[0:n]))

		os.Exit(1)
	}()

	var fd *os.File = os.Stdin
	var err error
	if filename != "" {
		fd, err = os.Open(filename)
		if err != nil {
			log.Fatalf("Input: os.Open(): %v", err)
		}
		defer fd.Close()
	}

	md, err := openpgp.ReadMessage(fd, emptyKR{}, newPromptFunction(), nil)
	if err != nil {
		log.Fatalf("openpgp.ReadMessage(): %v", err)
	}
	log.Println("openpgp.ReadMessage() returned without error")

	_, err = io.Copy(os.Stdout, md.UnverifiedBody)
	if err != nil {
		log.Fatalf("Reading unverified plain text: io.Copy(): %v", err)
	}

	// Check that any authentication code for the message was
	// verified successfully
	if md.SignatureError != nil {
		log.Fatalln("Integrity Check FAILED:", md.SignatureError)
	}
}
开发者ID:dylanpoe,项目名称:decrypt-symmetric,代码行数:58,代码来源:main.go

示例8: runMaster

func runMaster(cmd *Command, args []string) bool {
	if *mMaxCpu < 1 {
		*mMaxCpu = runtime.NumCPU()
	}
	runtime.GOMAXPROCS(*mMaxCpu)
	if *masterCpuProfile != "" {
		f, err := os.Create(*masterCpuProfile)
		if err != nil {
			glog.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
		OnInterrupt(func() {
			pprof.StopCPUProfile()
		})
	}
	if err := util.TestFolderWritable(*metaFolder); err != nil {
		glog.Fatalf("Check Meta Folder (-mdir) Writable %s : %s", *metaFolder, err)
	}
	if *masterWhiteListOption != "" {
		masterWhiteList = strings.Split(*masterWhiteListOption, ",")
	}

	r := mux.NewRouter()
	ms := weed_server.NewMasterServer(r, *mport, *metaFolder,
		*volumeSizeLimitMB, *mpulse, *confFile, *defaultReplicaPlacement, *garbageThreshold,
		masterWhiteList, *masterSecureKey,
	)

	listeningAddress := *masterBindIp + ":" + strconv.Itoa(*mport)

	glog.V(0).Infoln("Start Seaweed Master", util.VERSION, "at", listeningAddress)

	listener, e := util.NewListener(listeningAddress, time.Duration(*mTimeout)*time.Second)
	if e != nil {
		glog.Fatalf("Master startup error: %v", e)
	}

	go func() {
		time.Sleep(100 * time.Millisecond)
		myMasterAddress := *masterIp + ":" + strconv.Itoa(*mport)
		var peers []string
		if *masterPeers != "" {
			peers = strings.Split(*masterPeers, ",")
		}
		raftServer := weed_server.NewRaftServer(r, peers, myMasterAddress, *metaFolder, ms.Topo, *mpulse)
		ms.SetRaftServer(raftServer)
	}()

	if e := http.Serve(listener, r); e != nil {
		glog.Fatalf("Fail to serve: %v", e)
	}
	return true
}
开发者ID:ham1,项目名称:seaweedfs,代码行数:54,代码来源:master.go

示例9: SavePprofShot

func SavePprofShot() {
	f, err := os.OpenFile("E:/GO_PATH/src/go_code/cpu.prof", os.O_RDWR|os.O_CREATE, 0644)
	if err != nil {
		log.Fatal(err)
	}

	defer f.Close()
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()

	pprof.StopCPUProfile()
	f.Close()
}
开发者ID:yunkaiyueming,项目名称:go_code,代码行数:13,代码来源:log.go

示例10: main

func main() {

	if os.Getenv("GOMAXPROCS") == "" {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}

	cmd := &cobra.Command{
		Use:   "hurl",
		Short: "hurl is a tool to hurl traffic at URLs",
		Long: `hurl is a flexiable benchmarking tool with the ability to scale out.

Complete documentation is available online at:
	https://github.com/pquerna/hurl/`,
		Run: func(cmd *cobra.Command, args []string) {
			cmd.UsageFunc()(cmd)
		},
	}

	cpuprofile := os.Getenv("CPUPROFILE")

	if cpuprofile != "" {
		f, err := os.Create(cpuprofile)
		if err != nil {
			fmt.Errorf("Error opening: %s, %v\n", cpuprofile, err)
			panic(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()

		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt)
		go func() {
			for sig := range c {
				fmt.Printf("captured %v, stopping profiler and exiting..", sig)
				pprof.StopCPUProfile()
				os.Exit(1)
			}
		}()
	}

	subcmds := ui.ConsoleCommands()

	for _, c := range subcmds {
		cmd.AddCommand(c)
	}

	err := cmd.Execute()
	if err != nil {
		common.ConsoleErr(cmd, fmt.Sprintf("Error: %s", err))
	}
}
开发者ID:pquerna,项目名称:hurl,代码行数:51,代码来源:main.go

示例11: main

func main() {
	flag.Parse()

	if *procs == 0 {
		runtime.GOMAXPROCS(runtime.NumCPU())
	} else {
		runtime.GOMAXPROCS(*procs)
	}

	if *logFile != "" {
		f, err := os.OpenFile(*logFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
		if err != nil {
			log.Fatalln(err.Error())
		}
		log.SetOutput(f)
	}

	if *cpuProfile != "" {
		f, err := os.Create(*cpuProfile)
		if err != nil {
			log.Fatalln(err.Error())
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	config, err := gopush.ReadConfig(*configName)
	if err != nil {
		log.Fatal(err)
	}

	svc := gopush.NewService(config, gopush.NewMySQLBackend(config), gopush.NewStandardTemplateStoreInWorkingDir())

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for sig := range c {
			svc.Stop()
			log.Printf("Received signal %d, shutting down\n", sig)
			if *cpuProfile != "" { // Stop profiling
				pprof.StopCPUProfile()
			}
			os.Exit(1)
		}
	}()

	if err := svc.Start(); err != nil {
		log.Fatal(err)
	}
}
开发者ID:Pronovix,项目名称:gopush,代码行数:50,代码来源:gopush_server.go

示例12: prob41

func prob41() {
	f, _ := os.Create("a.prof")
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		s := <-c
		switch s {
		case syscall.SIGINT:
			pprof.StopCPUProfile()
			os.Exit(1)
		}
	}()

	mk := func(n int) []int {
		v := make([]int, n)
		for i := 0; i < n; i++ {
			v[i] = -(n - i)
		}
		return v
	}
	toI := func(v []int) int {
		r := 0
		for _, x := range v {
			r = r*10 + x
		}
		return -r
	}
	// 1+...+9 = 45 = 0 mod 3
	// 1+...+8 = 36 = 0 mod 3
	// so, you can start with n := 7
	n := 9
	v := mk(n)
	for {
		p := toI(v)
		if v[len(v)-1]%2 != 0 && IsPrime(p) {
			fmt.Println(p)
			break
		}
		b := NextPermutation(v)
		if !b {
			n--
			if n == 1 {
				break
			}
			v = mk(n)
		}
	}
}
开发者ID:herumi,项目名称:misc,代码行数:50,代码来源:projecteuler.go

示例13: main

func main() {
	kingpin.Version("0.0.7")
	kingpin.Parse()

	//go tool pprof --pdf saxer cpu.pprof > callgraph.pdf
	//evince callgraph.pdf

	if *cpuProfile {
		f, err := os.Create("cpu.pprof")
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		fmt.Println("profiling!")
		defer pprof.StopCPUProfile()
	}

	if strings.TrimSpace(*filename) != "" {
		absFilename, err := abs(*filename)
		if err != nil {
			fmt.Printf("Error finding file: %s\n", absFilename)
		}
		file, err := os.Open(absFilename)
		if err != nil {
			fmt.Printf("Error opening file: %s\n", absFilename)
		}
		defer file.Close()
		SaxXmlInput(file)
	} else {
		reader := bufio.NewReader(os.Stdin)
		SaxXmlInput(reader)
	}
}
开发者ID:tcw,项目名称:saxer,代码行数:33,代码来源:saxer.go

示例14: test

func test() {

	f, _ := os.Create("ls.prof")

	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer func() {
			pprof.StopCPUProfile()
		}()
	}

	// ...
	t := &T{}
	for i := 0; i < 1000000; i++ {
		v := reflect.ValueOf(t)
		if v.Kind() == reflect.Ptr {
			v = v.Elem()
		}
		t.B = append(t.B, i)
		t.A = append(t.A, sumtest())
	}

	// var buffer bytes.Buffer
	pprof.WriteHeapProfile(f)
	// fmt.Println(buffer.String())

}
开发者ID:elivoa,项目名称:gotapestry,代码行数:32,代码来源:goprofile.go

示例15: teardown

func teardown() {
	// Clear namespace so that we hit all the VMs
	SetNamespace("")

	vncClear()
	clearAllCaptures()
	vms.Kill(Wildcard)
	dnsmasqKillAll()
	ksmDisable()
	vms.Flush()
	vms.CleanDirs()
	containerTeardown()

	if err := bridgesDestroy(); err != nil {
		log.Errorln(err)
	}

	commandSocketRemove()
	goreadline.Rlcleanup()

	if err := os.Remove(filepath.Join(*f_base, "minimega.pid")); err != nil {
		log.Fatalln(err)
	}

	if cpuProfileOut != nil {
		pprof.StopCPUProfile()
		cpuProfileOut.Close()
	}

	os.Exit(0)
}
开发者ID:cdshann,项目名称:minimega,代码行数:31,代码来源:main.go


注:本文中的runtime/pprof.StopCPUProfile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。