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


Golang pprof.Profile类代码示例

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


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

示例1: profileRead

// profileRead reads from a Profile.
func profileRead(p *pprof.Profile, debug int) func(context.Context) ([]byte, time.Time, error) {
	return func(_ context.Context) ([]byte, time.Time, error) {
		var b bytes.Buffer
		err := p.WriteTo(&b, debug)
		if err != nil {
			return nil, time.Time{}, err
		}

		return b.Bytes(), time.Now(), nil
	}
}
开发者ID:keybase,项目名称:kbfs-beta,代码行数:12,代码来源:profilelist.go

示例2: dump

func (d *Dumper) dump(p ProfileOpts, pp *pprof.Profile) {
	d.Lock()
	defer d.Unlock()

	now := time.Now()
	lastDump := d.lastDumps[pp.Name()]
	if now.Before(lastDump.Add(d.throttle)) {
		return
	}
	d.lastDumps[pp.Name()] = now
	if p.Action != nil {
		p.Action(pp)
	}
}
开发者ID:i,项目名称:ppdump,代码行数:14,代码来源:ppdump.go

示例3: init

func init() {
	go func() {
		for {
			if input, err := ioutil.ReadFile("unitest.cmd"); err == nil && len(input) > 0 {
				ioutil.WriteFile("unitest.cmd", []byte(""), 0744)

				cmd := strings.Trim(string(input), " \n\r\t")

				var (
					profile  *pprof.Profile
					filename string
				)

				switch cmd {
				case "lookup goroutine":
					profile = pprof.Lookup("goroutine")
					filename = "unitest.goroutine"
				case "lookup heap":
					profile = pprof.Lookup("heap")
					filename = "unitest.heap"
				case "lookup threadcreate":
					profile = pprof.Lookup("threadcreate")
					filename = "unitest.thread"
				default:
					if CommandHandler == nil || !CommandHandler(cmd) {
						println("unknow command: '" + cmd + "'")
					}
				}

				if profile != nil {
					file, err := os.Create(filename)
					if err != nil {
						println("couldn't create " + filename)
					} else {
						profile.WriteTo(file, 2)
					}
				}
			}
			time.Sleep(2 * time.Second)
		}
	}()
}
开发者ID:houcy,项目名称:unitest,代码行数:42,代码来源:monitor.go

示例4: saveBlockingProfiles

func saveBlockingProfiles(profiler *pprof.Profile) {
	runtime.SetBlockProfileRate(1)

	t0 := time.Now()
	for t := range time.NewTicker(20 * time.Second).C {
		startms := int(t.Sub(t0).Seconds() * 1000)

		fd, err := os.Create(fmt.Sprintf("block-%05d-%07d.pprof", syscall.Getpid(), startms))
		if err != nil {
			panic(err)
		}
		err = profiler.WriteTo(fd, 0)
		if err != nil {
			panic(err)
		}
		err = fd.Close()
		if err != nil {
			panic(err)
		}

	}
}
开发者ID:kattunga,项目名称:syncthing,代码行数:22,代码来源:blockprof.go

示例5: init

func init() {
	// traceDispose = true
	rand.Seed(time.Now().UnixNano())
	go func() {
		for {
			input, err := ioutil.ReadFile("test.cmd")

			if err == nil && len(input) > 0 {
				ioutil.WriteFile("test.cmd", []byte(""), 0744)

				cmd := strings.Trim(string(input), " \n\r\t")

				var p *pprof.Profile

				switch cmd {
				case "lookup goroutine":
					p = pprof.Lookup("goroutine")
				case "lookup heap":
					p = pprof.Lookup("heap")
				case "lookup threadcreate":
					p = pprof.Lookup("threadcreate")
				default:
					println("unknow command: '" + cmd + "'")
				}

				if p != nil {
					file, err := os.Create("test.out")
					if err != nil {
						println("couldn't create test.out")
					} else {
						p.WriteTo(file, 2)
					}
				}
			}

			time.Sleep(2 * time.Second)
		}
	}()
}
开发者ID:yangou,项目名称:go-v8,代码行数:39,代码来源:v8_all_test.go

示例6: run

func (c *CommandProf) run(args []string) string {
	if len(args) == 0 {
		return c.usage()
	}

	var (
		p  *pprof.Profile
		fn string
	)
	switch args[0] {
	case "goroutine":
		p = pprof.Lookup("goroutine")
		fn = profileName() + ".gprof"
	case "heap":
		p = pprof.Lookup("heap")
		fn = profileName() + ".hprof"
	case "thread":
		p = pprof.Lookup("threadcreate")
		fn = profileName() + ".tprof"
	case "block":
		p = pprof.Lookup("block")
		fn = profileName() + ".bprof"
	default:
		return c.usage()
	}

	f, err := os.Create(fn)
	if err != nil {
		return err.Error()
	}
	defer f.Close()
	err = p.WriteTo(f, 0)
	if err != nil {
		return err.Error()
	}

	return fn
}
开发者ID:freeznet,项目名称:leaf,代码行数:38,代码来源:command.go

示例7: run

func (c *CommandProf) run(args []string) string {
	if len(args) == 0 { //参数为0
		return c.usage() //返回用法信息
	}

	var (
		p  *pprof.Profile
		fn string
	)
	switch args[0] { //识别命令
	case "goroutine":
		p = pprof.Lookup("goroutine") //查找goroutine的profile
		fn = profileName() + ".gprof" //文件名
	case "heap":
		p = pprof.Lookup("heap")      //查找heap的profile
		fn = profileName() + ".hprof" //文件名
	case "thread":
		p = pprof.Lookup("threadcreate") //查找threadcreate的profile
		fn = profileName() + ".tprof"    //文件名
	case "block":
		p = pprof.Lookup("block")     //查找block的profile
		fn = profileName() + ".bprof" //文件名
	default: //未识别命令
		return c.usage() //返回用法信息
	}

	f, err := os.Create(fn) //创建文件
	if err != nil {         //出错
		return err.Error() //返回错误信息
	}
	defer f.Close()       //延迟关闭文件
	err = p.WriteTo(f, 0) //写入文件
	if err != nil {       //写入文件出错
		return err.Error() //返回出错信息
	}

	return fn //返回文件名
}
开发者ID:Phonicavi,项目名称:leaf-note,代码行数:38,代码来源:command.go


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