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


Golang runtime.CPUProfile函数代码示例

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


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

示例1: startProfiler

func startProfiler(filename *string) error {
	if filename == nil || *filename == "" {
		return nil
	}

	cpuProfileFile, err := os.Create(*filename)
	if err != nil {
		return err
	}
	runtime.SetCPUProfileRate(500)
	stopped := make(chan bool)

	go waitForSignals(stopped)

	go func() {
		for {
			select {
			default:
				data := runtime.CPUProfile()
				if data == nil {
					cpuProfileFile.Close()
					stopped <- true
					break
				}
				cpuProfileFile.Write(data)
			}
		}
	}()
	return nil
}
开发者ID:schmurfy,项目名称:influxdb,代码行数:30,代码来源:influxd.go

示例2: profileWriter

func profileWriter(w io.Writer) {
	startTime := time.Now()
	// This will buffer the entire profile into buf and then
	// translate it into a profile.Profile structure. This will
	// create two copies of all the data in the profile in memory.
	// TODO(matloob): Convert each chunk of the proto output and
	// stream it out instead of converting the entire profile.
	var buf bytes.Buffer
	for {
		data := runtime.CPUProfile()
		if data == nil {
			break
		}
		buf.Write(data)
	}

	profile, err := protopprof.TranslateCPUProfile(buf.Bytes(), startTime)
	if err != nil {
		// The runtime should never produce an invalid or truncated profile.
		// It drops records that can't fit into its log buffers.
		panic(fmt.Errorf("could not translate binary profile to proto format: %v", err))
	}

	profile.Write(w)
	cpu.done <- true
}
开发者ID:oshimaya,项目名称:go,代码行数:26,代码来源:pprof.go

示例3: startProfiler

func startProfiler() error {
	if profileFilename == nil || *profileFilename == "" {
		return nil
	}

	startCHeapProfiler(*profileFilename)
	runtime.MemProfileRate = 1024

	cpuProfileFile, err := os.Create(fmt.Sprintf("%s.cpu", *profileFilename))
	if err != nil {
		return err
	}
	runtime.SetCPUProfileRate(500)
	stopped := make(chan bool)

	go waitForSignals(*profileFilename, stopped)

	go func() {
		for {
			select {
			default:
				data := runtime.CPUProfile()
				if data == nil {
					cpuProfileFile.Close()
					stopped <- true
					break
				}
				cpuProfileFile.Write(data)
			}
		}
	}()
	return nil
}
开发者ID:rramos,项目名称:influxdb,代码行数:33,代码来源:profiler.go

示例4: profileWriter

func profileWriter(w io.Writer) {
	for {
		data := runtime.CPUProfile()
		if data == nil {
			break
		}
		errors.Logf("DEBUG", "profileWriter got data %v", len(data))
		w.Write(data)
	}
	profileDone <- true
}
开发者ID:timtadh,项目名称:sfp,代码行数:11,代码来源:main.go

示例5: main

func main() {
	select {
	case <-time.After(time.Second):
		fmt.Println(time.Minute.Seconds(), time.Second)
	}
	select {
	case <-time.After(time.Minute):
		fmt.Println(time.Minute.Seconds(), time.Second)
	}
	var kvlist []int
	kvlist = make([]int, 0, 10)
	kvlist = append(kvlist, 1)
	fmt.Println(kvlist)
	m := make(map[int]int, 10)
	m[1] += 1
	fmt.Println("aaaa:", string(runtime.CPUProfile()), m, cap(kvlist))
	for i := 0; ; i++ {
		pc, file, line, ok := runtime.Caller(i)
		if ok == false {
			break
		}
		fmt.Println(pc, file, line, ok)
		//runtime.Breakpoint()
	}
	fmt.Println(runtime.Version())
	buf := make([]byte, 1025)
	len := runtime.Stack(buf, true)
	fmt.Println(string(runtime.CPUProfile()))
	fmt.Println(len, string(buf[:len]))
	//debug.PrintStack()
	fmt.Println(debug.SetMaxThreads(10))
	i := 100
	fmt.Println(reflect.TypeOf((*int32)(nil)).Elem())
	fmt.Println(reflect.ValueOf(&i).Kind())
	fmt.Println(reflect.TypeOf(&i).Kind())
	RoundPos(3, func(r, x, y int32) {
		println(r, x, y)
	})
}
开发者ID:yc7369,项目名称:gostudy,代码行数:39,代码来源:runtimetest.go

示例6: profileWriter

func profileWriter(w io.Writer) {
	for {
		data := runtime.CPUProfile()
		if data == nil {
			break
		}
		w.Write(data)
	}

	// We are emitting the legacy profiling format, which permits
	// a memory map following the CPU samples. The memory map is
	// simply a copy of the GNU/Linux /proc/self/maps file. The
	// profiler uses the memory map to map PC values in shared
	// libraries to a shared library in the filesystem, in order
	// to report the correct function and, if the shared library
	// has debug info, file/line. This is particularly useful for
	// PIE (position independent executables) as on ELF systems a
	// PIE is simply an executable shared library.
	//
	// Because the profiling format expects the memory map in
	// GNU/Linux format, we only do this on GNU/Linux for now. To
	// add support for profiling PIE on other ELF-based systems,
	// it may be necessary to map the system-specific mapping
	// information to the GNU/Linux format. For a reasonably
	// portable C++ version, see the FillProcSelfMaps function in
	// https://github.com/gperftools/gperftools/blob/master/src/base/sysinfo.cc
	//
	// The code that parses this mapping for the pprof tool is
	// ParseMemoryMap in cmd/internal/pprof/legacy_profile.go, but
	// don't change that code, as similar code exists in other
	// (non-Go) pprof readers. Change this code so that that code works.
	//
	// We ignore errors reading or copying the memory map; the
	// profile is likely usable without it, and we have no good way
	// to report errors.
	if runtime.GOOS == "linux" {
		f, err := os.Open("/proc/self/maps")
		if err == nil {
			io.WriteString(w, "\nMAPPED_LIBRARIES:\n")
			io.Copy(w, f)
			f.Close()
		}
	}

	cpu.done <- true
}
开发者ID:kraj,项目名称:gcc,代码行数:46,代码来源:pprof.go

示例7: profileWriter

func profileWriter(w io.Writer) {
	var buf bytes.Buffer
	for {
		data := runtime.CPUProfile()
		buf.Write(data)
		if data == nil {
			break
		}
	}
	p, err := protopprof.TranslateCPUProfile(buf.Bytes(), cpu.startTime)
	if err != nil {
		panic(err)
	}
	p.RemapAll()
	protopprof.CleanupDuplicateLocations(p)
	protopprof.Symbolize(p)
	p.Write(w)
	cpu.done <- true
}
开发者ID:achanda,项目名称:go,代码行数:19,代码来源:pprof.go

示例8: startProfiler

func startProfiler(stoppable Stoppable) error {
	if profileFilename == nil || *profileFilename == "" {
		log.Info("Not starting profiling since the profile prefix is not set")
		return nil
	}

	log.Info("Starting profiling with prefix %s", *profileFilename)

	startCHeapProfiler(*profileFilename)
	// startCCpuProfiler(*profileFilename)
	runtime.MemProfileRate = 1024

	cpuProfileFile, err := os.Create(fmt.Sprintf("%s.cpu", *profileFilename))
	if err != nil {
		return err
	}
	runtime.SetCPUProfileRate(500)
	stopped := make(chan bool)

	go waitForSignals(stoppable, *profileFilename, stopped)

	go func() {
		for {
			select {
			default:
				data := runtime.CPUProfile()
				if data == nil {
					cpuProfileFile.Close()
					stopped <- true
					break
				}
				cpuProfileFile.Write(data)
			}
		}
	}()
	return nil
}
开发者ID:9cat,项目名称:influxdb,代码行数:37,代码来源:profiler.go


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