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


Golang runtime.NumCgoCall函数代码示例

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


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

示例1: StartReadText

func StartReadText() {
	hello := new(Job)
	hello.text = "hello"
	hello.i = 0
	hello.max = 3

	world := new(Job)
	world.text = "world"
	world.i = 0
	world.max = 5
	go ReadText(hello)
	go ReadText(world)

	cpus := runtime.GOMAXPROCS(0)
	fmt.Println(runtime.GOOS, runtime.NumCPU(), runtime.NumCgoCall(), runtime.NumGoroutine(), "list cpu number:", cpus)

	max := 8
	for i := 1; i < max; i++ {
		go showNumber(i)
	}
	//This is because there’s no guarantee as to how
	//many goroutines, if any, will complete before the end of the main() function
	runtime.Gosched()
	fmt.Println("exits!")
}
开发者ID:elitecodegroovy,项目名称:GolangBestPractice,代码行数:25,代码来源:scheduler.go

示例2: PrintPostLoopSummary

//	Prints a summary of go:ngine's *Stats* performance counters when the parent example app exits.
func PrintPostLoopSummary() {
	printStatSummary := func(name string, timing *ng.TimingStats) {
		fmt.Printf("%v\t\tAvg=%8.3fms\tMax=%8.3fms\n", name, timing.Average()*1000, timing.Max()*1000)
	}
	fmt.Printf("Average FPS:\t\t%v (total %v over %v)\n", ng.Stats.AverageFps(), ng.Stats.TotalFrames(), time.Duration(int64(ng.Loop.Time()*1000*1000*1000)))
	printStatSummary("Full Loop Iteration", &ng.Stats.Frame)
	printStatSummary("Frame On.EverySec", &ng.Stats.FrameOnSec)
	printStatSummary("Frame On.AppThread", &ng.Stats.FrameAppThread)
	printStatSummary("Frame On.WinThread", &ng.Stats.FrameWinThread)
	printStatSummary("Frame Prep Thread", &ng.Stats.FramePrepThread)
	printStatSummary("Frame Thread Sync", &ng.Stats.FrameThreadSync)
	printStatSummary("Frame Render (CPU)", &ng.Stats.FrameRenderCpu)
	printStatSummary("Frame Render (GPU)", &ng.Stats.FrameRenderGpu)
	printStatSummary("Frame Render Both", &ng.Stats.FrameRenderBoth)
	if s := "GC (max. 1x/sec)"; ng.Options.Loop.GcEvery.Frame || ng.Options.Loop.GcEvery.Sec {
		if ng.Options.Loop.GcEvery.Frame {
			s = "GC (max 1x/frame)"
		}
		printStatSummary(s, &ng.Stats.Gc)
		if !ng.Options.Loop.GcEvery.Frame {
			fmt.Printf("Averaged GC/frame cost:\t%1.3fms\n", (ng.Stats.Gc.Average()/ng.Stats.AverageFps())*1000)
		}
	}
	fmt.Printf("Shaders: compiled %v GLSL shader programs over time, which took %v in total.\n", ng.Stats.Programs.NumProgsCompiled, time.Duration(ng.Stats.Programs.TotalTimeCost))
	cgoPerFrame, numTotalFrames := int64(0), ng.Stats.TotalFrames()
	if numTotalFrames != 0 {
		cgoPerFrame = runtime.NumCgoCall() / int64(ng.Stats.TotalFrames())
	}
	fmt.Printf("CGO calls: pre-loop init %v, loop %v (avg. %v/frame)\n\n", numCgo.preLoop, numCgo.postLoop-numCgo.preLoop, cgoPerFrame)
}
开发者ID:Raven67854,项目名称:go-ngine,代码行数:31,代码来源:misc.go

示例3: setStatsPane

func (gui *Gui) setStatsPane() {
	var memStats runtime.MemStats
	runtime.ReadMemStats(&memStats)

	statsPane := gui.getObjectByName("statsPane")
	statsPane.Set("text", fmt.Sprintf(`###### Mist %s (%s) #######

eth %d (p2p = %d)

CPU:        # %d
Goroutines: # %d
CGoCalls:   # %d

Alloc:      %d
Heap Alloc: %d

CGNext:     %x
NumGC:      %d
`, Version, runtime.Version(),
		eth.ProtocolVersion, 2,
		runtime.NumCPU, runtime.NumGoroutine(), runtime.NumCgoCall(),
		memStats.Alloc, memStats.HeapAlloc,
		memStats.NextGC, memStats.NumGC,
	))
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:25,代码来源:gui.go

示例4: GetValue

func (metrica *noCgoCallsMetrica) GetValue() (float64, error) {
	currentValue := runtime.NumCgoCall()
	value := float64(currentValue - metrica.lastValue)
	metrica.lastValue = currentValue

	return value, nil
}
开发者ID:jskrzypek,项目名称:jqplay,代码行数:7,代码来源:runtime_metrics.go

示例5: ShowAdmin

func ShowAdmin(res http.ResponseWriter, req *http.Request, base *BaseController) {
	// TODO: add total transactions
	male_players := models.GetMalePlayers()
	female_players := models.GetFemalePlayers()
	m := &runtime.MemStats{}
	runtime.ReadMemStats(m)
	online_records, err := models.GetOnlineRecords()
	if err != nil {
		http.Error(res, "Error while getting online records: "+err.Error(), 500)
		return
	}
	views.Parser.ExecuteTemplate(res, "admin.html", &AdminOverviewResponse{
		male_players,
		female_players,
		models.GetSorcererPlayers(),
		models.GetDruidPlayers(),
		models.GetPaladinPlayers(),
		models.GetKnightPlayers(),
		models.GetTotalAccounts(),
		models.GetTotalPlayers(),
		m,
		runtime.NumCPU(),
		runtime.NumGoroutine(),
		runtime.NumCgoCall(),
		runtime.Version(),
		online_records,
	})
}
开发者ID:Cloakaac,项目名称:core,代码行数:28,代码来源:admin.go

示例6: main

func main() {
	log.Println("Version=", runtime.Version())
	log.Println("GOMAXPROCS=", runtime.GOMAXPROCS(0))
	log.Println("NumCPUs=", runtime.NumCPU())
	log.Println("NumCgoCall=", runtime.NumCgoCall())
	log.Println("NumGoroutines=", runtime.NumGoroutine())
	debug.PrintStack()
}
开发者ID:Kane-Sendgrid,项目名称:gopher-meetup-talk,代码行数:8,代码来源:envs.go

示例7: SampleEnvironment

// SampleEnvironment queries the runtime system for various interesting metrics,
// storing the resulting values in the set of metric gauges maintained by
// RuntimeStatSampler. This makes runtime statistics more convenient for
// consumption by the time series and status systems.
//
// This method should be called periodically by a higher level system in order
// to keep runtime statistics current.
func (rsr *RuntimeStatSampler) SampleEnvironment() {
	// Record memory and call stats from the runtime package.
	// TODO(mrtracy): memory statistics will not include usage from RocksDB.
	// Determine an appropriate way to compute total memory usage.
	numCgoCall := runtime.NumCgoCall()
	numGoroutine := runtime.NumGoroutine()

	// It might be useful to call ReadMemStats() more often, but it stops the
	// world while collecting stats so shouldn't be called too often.
	ms := runtime.MemStats{}
	runtime.ReadMemStats(&ms)

	// Record CPU statistics using syscall package.
	ru := syscall.Rusage{}
	if err := syscall.Getrusage(syscall.RUSAGE_SELF, &ru); err != nil {
		log.Errorf("Getrusage failed: %v", err)
	}

	// Time statistics can be compared to the total elapsed time to create a
	// useful percentage of total CPU usage, which would be somewhat less accurate
	// if calculated later using downsampled time series data.
	now := rsr.clock.PhysicalNow()
	dur := float64(now - rsr.lastNow)
	newUtime := ru.Utime.Nano()
	newStime := ru.Stime.Nano()
	uPerc := float64(newUtime-rsr.lastUtime) / dur
	sPerc := float64(newStime-rsr.lastStime) / dur
	pausePerc := float64(ms.PauseTotalNs-rsr.lastPauseTime) / dur
	rsr.lastNow = now
	rsr.lastUtime = newUtime
	rsr.lastStime = newStime
	rsr.lastPauseTime = ms.PauseTotalNs

	// Log summary of statistics to console, if requested.
	activeMiB := float64(ms.Alloc) / (1 << 20)
	cgoRate := float64((numCgoCall-rsr.lastCgoCall)*int64(time.Second)) / dur
	log.Infof("runtime stats: %d goroutines, %.2fMiB active, %.2fcgo/sec, %.2f/%.2f %%(u/s)time, %.2f %%gc (%dx)",
		numGoroutine, activeMiB, cgoRate, uPerc, sPerc, pausePerc, ms.NumGC-rsr.lastNumGC)
	if log.V(2) {
		log.Infof("memstats: %+v", ms)
	}
	if logOSStats != nil {
		logOSStats()
	}
	rsr.lastCgoCall = numCgoCall
	rsr.lastNumGC = ms.NumGC

	rsr.cgoCalls.Update(numCgoCall)
	rsr.goroutines.Update(int64(numGoroutine))
	rsr.allocBytes.Update(int64(ms.Alloc))
	rsr.gcCount.Update(int64(ms.NumGC))
	rsr.gcPauseNS.Update(int64(ms.PauseTotalNs))
	rsr.gcPausePercent.Update(pausePerc)
	rsr.cpuUserNS.Update(newUtime)
	rsr.cpuUserPercent.Update(uPerc)
	rsr.cpuSysNS.Update(newStime)
	rsr.cpuSysPercent.Update(sPerc)
}
开发者ID:bogdanbatog,项目名称:cockroach,代码行数:65,代码来源:runtime.go

示例8: capture

// capture does a one time collection of DeferStats
func (c *Client) capture() {

	var mem runtime.MemStats
	var gc debug.GCStats

	mems := ""
	if c.GrabMem {
		runtime.ReadMemStats(&mem)
		mems = strconv.FormatUint(mem.Alloc, 10)
	}

	gcs := ""
	if c.GrabGC {
		debug.ReadGCStats(&gc)
		gcs = strconv.FormatInt(gc.NumGC, 10)
	}

	grs := ""
	if c.GrabGR {
		grs = strconv.Itoa(runtime.NumGoroutine())
	}

	cgos := ""
	if c.GrabCgo {
		cgos = strconv.FormatInt(runtime.NumCgoCall(), 10)
	}

	fds := ""
	if c.GrabFd {
		fds = strconv.Itoa(openFileCnt())
	}

	ds := DeferStats{
		Mem:        mems,
		GoRoutines: grs,
		Cgos:       cgos,
		Fds:        fds,
		HTTPs:      curlist.List(),
		DBs:        Querylist.List(),
		GC:         gcs,
	}

	// FIXME
	// empty our https/dbs
	curlist.Reset()
	Querylist.Reset()

	go func() {
		b, err := json.Marshal(ds)
		if err != nil {
			log.Println(err)
		}

		c.BaseClient.Postit(b, c.statsUrl)
	}()
}
开发者ID:akashshinde,项目名称:deferclient,代码行数:57,代码来源:stats.go

示例9: Status

// Status will return the current status of this system
func (ctx *BroadcastContext) Status() (*BroadcastServerStatus, error) {
	status := new(BroadcastServerStatus)
	status.NumGoroutines = runtime.NumGoroutine()
	status.NumCpu = runtime.NumCPU()
	status.NumCgoCall = runtime.NumCgoCall()
	status.NumClients = ctx.ClientSize
	status.Memory = new(runtime.MemStats)
	runtime.ReadMemStats(status.Memory)
	return status, nil
}
开发者ID:nyxtom,项目名称:broadcast,代码行数:11,代码来源:context.go

示例10: GetTimeSeriesData

// GetTimeSeriesData returns a slice of TimeSeriesData updates based on current
// runtime statistics.
//
// Calling this method will query various system packages for runtime statistics
// and convert the information to time series data. This is currently done in
// one method because it is convenient; however, in the future querying and
// recording can be easily separated, similar to the way that NodeStatus is
// separated into a monitor and a recorder.
func (rsr *RuntimeStatRecorder) GetTimeSeriesData() []ts.TimeSeriesData {
	data := make([]ts.TimeSeriesData, 0, rsr.lastDataCount)

	// Record memory and call stats from the runtime package.
	// TODO(mrtracy): memory statistics will not include usage from RocksDB.
	// Determine an appropriate way to compute total memory usage.
	numCgoCall := runtime.NumCgoCall()
	numGoroutine := runtime.NumGoroutine()
	ms := runtime.MemStats{}
	runtime.ReadMemStats(&ms)

	// Record CPU statistics using syscall package.
	ru := syscall.Rusage{}
	if err := syscall.Getrusage(syscall.RUSAGE_SELF, &ru); err != nil {
		log.Errorf("Getrusage failed: %v", err)
	}

	// Time statistics can be compared to the total elapsed time to create a
	// useful percentage of total CPU usage, which would be somewhat less accurate
	// if calculated later using downsampled time series data.
	now := rsr.clock.PhysicalNow()
	dur := float64(now - rsr.lastNow)
	newUtime := ru.Utime.Nano()
	newStime := ru.Stime.Nano()
	uPerc := float64(newUtime-rsr.lastUtime) / dur
	sPerc := float64(newStime-rsr.lastStime) / dur
	pausePerc := float64(ms.PauseTotalNs-rsr.lastPauseTime) / dur
	rsr.lastNow = now
	rsr.lastUtime = newUtime
	rsr.lastStime = newStime
	rsr.lastPauseTime = ms.PauseTotalNs

	// Log summary of statistics to console, if requested.
	if log.V(1) {
		activeMiB := float64(ms.Alloc) / (1 << 20)
		cgoRate := float64((numCgoCall-rsr.lastCgoCall)*int64(time.Second)) / dur
		log.Infof("runtime stats: %d goroutines, %.2fMiB active, %.2fcgo/sec, %.2f/%.2f %%(u/s)time, %.2f %%gc (%dx)",
			numGoroutine, activeMiB, cgoRate, uPerc, sPerc, pausePerc, ms.NumGC-rsr.lastNumGC)
		rsr.lastCgoCall = numCgoCall
		rsr.lastNumGC = ms.NumGC
	}

	data = append(data, rsr.record(now, "cgocalls", float64(numCgoCall)))
	data = append(data, rsr.record(now, "goroutines", float64(numGoroutine)))
	data = append(data, rsr.record(now, "allocbytes", float64(ms.Alloc)))
	data = append(data, rsr.record(now, "gc.count", float64(ms.NumGC)))
	data = append(data, rsr.record(now, "gc.pause.ns", float64(ms.PauseTotalNs)))
	data = append(data, rsr.record(now, "gc.pause.percent", pausePerc))
	data = append(data, rsr.record(now, "cpu.user.ns", float64(newUtime)))
	data = append(data, rsr.record(now, "cpu.user.percent", uPerc))
	data = append(data, rsr.record(now, "cpu.sys.ns", float64(newStime)))
	data = append(data, rsr.record(now, "cpu.sys.percent", sPerc))
	rsr.lastDataCount = len(data)
	return data
}
开发者ID:rohanahata,项目名称:cockroach,代码行数:63,代码来源:runtime.go

示例11: GoRuntimeMetrics

// a few simple stats from go runtime, in your app, if you want these
// add them as a metrics function
//
//		func init() {
//			metrics.AddMetricsFunction(metrics.GoRuntimeMetrics)
//		}
func GoRuntimeMetrics(snap *Snapshot) {

	snap.Ints["go_cgocall.ct"] = uint64(runtime.NumCgoCall())
	snap.Ints["go_numgoroutine.ct"] = uint64(runtime.NumGoroutine())
	// http://weekly.golang.org/pkg/runtime/#MemStats
	runtime.ReadMemStats(&rtMem)
	snap.Ints["go_memalloc.avg"] = rtMem.Alloc / 1048576
	snap.Ints["go_memtotalloc.avg"] = rtMem.TotalAlloc / 1048576
	snap.Ints["go_memsys.avg"] = rtMem.Sys / 1048576

}
开发者ID:araddon,项目名称:go-metrics,代码行数:17,代码来源:goruntime.go

示例12: SysInfo

func SysInfo(job *Job) ([]byte, error) {
	return json.Marshal(&systemInfo{
		GOOS:         runtime.GOOS,
		GOARCH:       runtime.GOARCH,
		GOROOT:       runtime.GOROOT(),
		Version:      runtime.Version(),
		NumCPU:       runtime.NumCPU(),
		NumGoroutine: runtime.NumGoroutine(),
		NumCgoCall:   runtime.NumCgoCall(),
	})
}
开发者ID:jasonmoo,项目名称:gearman-go,代码行数:11,代码来源:func.go

示例13: main

func main() {

	go func() {
		fmt.Println("before")
		runtime.Goexit()
		fmt.Println("after")
	}()

	fmt.Println(runtime.GOROOT(), runtime.GOMAXPROCS(0), runtime.NumCPU(), runtime.NumCgoCall())
	<-time.After(time.Second * 2)
}
开发者ID:pfeilbr,项目名称:go-examples,代码行数:11,代码来源:main.go

示例14: RESTGetRuntimeStats

func RESTGetRuntimeStats(w http.ResponseWriter, r *http.Request) {
	MustEncode(w, map[string]interface{}{
		"currTime":  time.Now(),
		"startTime": StartTime,
		"go": map[string]interface{}{
			"numGoroutine":   runtime.NumGoroutine(),
			"numCgoCall":     runtime.NumCgoCall(),
			"memProfileRate": runtime.MemProfileRate,
		},
	})
}
开发者ID:nimishzynga,项目名称:cbgt,代码行数:11,代码来源:rest.go

示例15: GoStats

// golang stats
func GoStats() []byte {
	res := map[string]interface{}{}
	res["compiler"] = runtime.Compiler
	res["arch"] = runtime.GOARCH
	res["os"] = runtime.GOOS
	res["max_procs"] = runtime.GOMAXPROCS(-1)
	res["root"] = runtime.GOROOT()
	res["cgo_call"] = runtime.NumCgoCall()
	res["goroutine_num"] = runtime.NumGoroutine()
	res["version"] = runtime.Version()
	return jsonRes(res)
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:13,代码来源:stat.go


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