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


Golang runtime.BlockProfile函数代码示例

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


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

示例1: writeBlock

// writeBlock writes the current blocking profile to w.
func writeBlock(w io.Writer, debug int) error {
	var p []runtime.BlockProfileRecord
	n, ok := runtime.BlockProfile(nil)
	for {
		p = make([]runtime.BlockProfileRecord, n+50)
		n, ok = runtime.BlockProfile(p)
		if ok {
			p = p[:n]
			break
		}
	}

	sort.Sort(byCycles(p))

	b := bufio.NewWriter(w)
	var tw *tabwriter.Writer
	w = b
	if debug > 0 {
		tw = tabwriter.NewWriter(w, 1, 8, 1, '\t', 0)
		w = tw
	}

	fmt.Fprintf(w, "--- contention:\n")
	fmt.Fprintf(w, "cycles/second=%v\n", runtime_cyclesPerSecond())
	for i := range p {
		r := &p[i]
		fmt.Fprintf(w, "%v %v @", r.Cycles, r.Count)
		for _, pc := range r.Stack() {
			fmt.Fprintf(w, " %#x", pc)
		}
		fmt.Fprint(w, "\n")
		if debug > 0 {
			printStackRecord(w, r.Stack(), true)
		}
	}

	if tw != nil {
		tw.Flush()
	}
	return b.Flush()
}
开发者ID:RBEGamer,项目名称:go,代码行数:42,代码来源:pprof.go

示例2: writeBlock

// writeBlock writes the current blocking profile to w.
func writeBlock(w io.Writer, debug int) error {
	var p []runtime.BlockProfileRecord
	n, ok := runtime.BlockProfile(nil)
	for {
		// Code by analogy with writeBlock func
		p = make([]runtime.BlockProfileRecord, n+50)
		n, ok = runtime.BlockProfile(p)
		if ok {
			p = p[:n]
			break
		}
	}

	sort.Slice(p, func(i, j int) bool { return p[i].Cycles > p[j].Cycles })

	prof := &profile.Profile{
		PeriodType: &profile.ValueType{Type: "contentions", Unit: "count"},
		Period:     1,
		SampleType: []*profile.ValueType{
			{Type: "contentions", Unit: "count"},
			{Type: "delay", Unit: "nanoseconds"},
		},
	}

	cpuHz := runtime_cyclesPerSecond()
	locs := make(map[uint64]*profile.Location)
	for i := range p {
		r := &p[i]
		var v1, v2 int64
		v1 = r.Cycles
		v2 = r.Count
		if prof.Period > 0 {
			if cpuHz > 0 {
				cpuGHz := float64(cpuHz) / 1e9
				v1 = int64(float64(v1) * float64(prof.Period) / cpuGHz)
			}
			v2 = v2 * prof.Period
		}

		value := []int64{v2, v1}
		var sloc []*profile.Location

		for _, pc := range r.Stack() {
			addr := uint64(pc)
			addr--
			loc := locs[addr]
			if locs[addr] == nil {
				loc = &profile.Location{
					Address: addr,
				}
				prof.Location = append(prof.Location, loc)
				locs[addr] = loc
			}
			sloc = append(sloc, loc)
		}
		prof.Sample = append(prof.Sample, &profile.Sample{
			Value:    value,
			Location: sloc,
		})
	}

	prof.RemapAll()
	protopprof.Symbolize(prof)
	return prof.Write(w)
}
开发者ID:achanda,项目名称:go,代码行数:66,代码来源:pprof.go

示例3: countBlock

// countBlock returns the number of records in the blocking profile.
func countBlock() int {
	n, _ := runtime.BlockProfile(nil)
	return n
}
开发者ID:achanda,项目名称:go,代码行数:5,代码来源:pprof.go


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