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


Golang debug.ReadGCStats函数代码示例

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


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

示例1: StartDriver

// Stats driver waits for samples and publishes results to listeners
func StartDriver() {
	go func() {
		var gcStats debug.GCStats
		var listeners = make(map[chan *Stats]string)
		stats := NewStats()
		statsUpdate := time.Tick(config.StatsUpdatePeriodMs)
		for {
			select {
			// Time to send a stats update
			case <-statsUpdate:
				// Update the stats GC
				debug.ReadGCStats(&gcStats)
				stats.GcCount = gcStats.NumGC
				if len(gcStats.Pause) > 0 {
					pauseTime := float64(gcStats.Pause[0]) / float64(time.Millisecond)
					stats.GcPauseTime = strconv.FormatFloat(pauseTime, 'f', 2, 64)
				}
				// Send to all listeners, that are idle, the most recent frame buffer
				for k, _ := range listeners {
					// Send a the latest stats if listener has processed the last one
					select {
					case k <- stats:
					default:
					}
				}
				// New stats so we don't corrupt last one sent by reference
				stats = NewStats()

			// New stats sample from somewhere
			case s := <-statSampleChannel:
				{
					switch s.StatType {
					case statFrameRenderTime:
						stats.addFrameRenderTimeSample(s.Src, s.Sample)
					case statFrameSyncJitter:
						stats.addFrameSyncJitterSample(s.Src, s.Sample)
					case statSerialSendTime:
						stats.addSerialSendTimeSample(s.Src, s.Sample)
					case statSerialDroppedFrame:
						stats.addSerialDroppedFrame(s.Src)
					case statFrameRenderDroppedFrame:
						stats.addFrameRenderDroppedFrame()
					default:
						panic("Unknown stat type " + strconv.Itoa(s.StatType))
					}
				}

			// Process new listener requests
			case newListener := <-addListener:
				log.WithField("name", newListener.name).Info("Stats listener added")
				listeners[newListener.src] = newListener.name

			// Process remove listener request
			case listenerToRemove := <-listenerDone:
				log.WithField("name", listeners[listenerToRemove]).Info("Stats listener removed")
				delete(listeners, listenerToRemove)
			}
		}
	}()
}
开发者ID:andew42,项目名称:brightlight,代码行数:61,代码来源:driver.go

示例2: GCSummary

// Get GC summary.
func GCSummary() *GCSummaryInfo {
	gcstats := debug.GCStats{PauseQuantiles: make([]time.Duration, 100)}
	debug.ReadGCStats(&gcstats)

	memStats := runtime.MemStats{}
	runtime.ReadMemStats(&memStats)

	elapsed := time.Now().Sub(startTime)

	summary := &GCSummaryInfo{
		Alloc:     memStats.Alloc,
		Sys:       memStats.Sys,
		AllocRate: uint64(float64(memStats.TotalAlloc) / elapsed.Seconds()),
	}

	if gcstats.NumGC > 0 {
		summary.NumGC = gcstats.NumGC
		summary.LastPause = gcstats.Pause[0]
		summary.PauseAvg = durationAvg(gcstats.Pause)
		summary.Overhead = float64(gcstats.PauseTotal) / float64(elapsed) * 100
		summary.Histogram1 = gcstats.PauseQuantiles[94]
		summary.Histogram2 = gcstats.PauseQuantiles[98]
		summary.Histogram3 = gcstats.PauseQuantiles[99]
	}

	return summary
}
开发者ID:miffa,项目名称:pprof,代码行数:28,代码来源:gc_summary.go

示例3: memProfile

func memProfile() {
	var gcstats *debug.GCStats
	var stats *runtime.MemStats

	stats = &runtime.MemStats{}
	gcstats = &debug.GCStats{}

	for {
		fmt.Println("STATS")

		runtime.ReadMemStats(stats)
		fmt.Printf("EnableGC: %v.\n", stats.EnableGC)
		fmt.Printf("LastGC: %d.\n", stats.LastGC)
		fmt.Printf("Mallocs: %d.\n", stats.Mallocs)
		fmt.Printf("Frees: %d.\n", stats.Frees)
		fmt.Printf("Mallocs - Frees: %d.\n", stats.Mallocs-stats.Frees)

		debug.ReadGCStats(gcstats)
		fmt.Printf("LastGC: %v.\n", gcstats.LastGC)
		fmt.Printf("NumGC: %d.\n", gcstats.NumGC)

		time.Sleep(time.Second * 2)
		fmt.Println("")
		fmt.Println("")
	}
}
开发者ID:hiroakiukaji,项目名称:shooter-server,代码行数:26,代码来源:main.go

示例4: show_info

func show_info(par string) {
	common.Busy_mutex.Lock()
	if common.BusyWith != "" {
		fmt.Println("Chain thread busy with:", common.BusyWith)
	} else {
		fmt.Println("Chain thread is idle")
	}
	common.Busy_mutex.Unlock()

	network.MutexRcv.Lock()
	fmt.Println("Last Header:", network.LastCommitedHeader.BlockHash.String(), "@", network.LastCommitedHeader.Height)
	discarded := len(network.DiscardedBlocks)
	cached := len(network.CachedBlocks)
	b2g_len := len(network.BlocksToGet)
	b2g_idx_len := len(network.IndexToBlocksToGet)
	lb2g := network.LowestIndexToBlocksToGet
	network.MutexRcv.Unlock()

	common.Last.Mutex.Lock()
	fmt.Println("Last Block :", common.Last.Block.BlockHash.String(), "@", common.Last.Block.Height)
	fmt.Printf("Timestamp: %s,  Diff: %.0f,  Got: %s ago,  ToGetFrom: %d\n",
		time.Unix(int64(common.Last.Block.Timestamp()), 0).Format("2006/01/02 15:04:05"),
		btc.GetDifficulty(common.Last.Block.Bits()), time.Now().Sub(common.Last.Time).String(),
		lb2g)
	fmt.Print("Median Time: ", time.Unix(int64(common.Last.Block.GetMedianTimePast()), 0).Format("2006/01/02 15:04:05"), ",   ")
	common.Last.Mutex.Unlock()

	network.Mutex_net.Lock()
	fmt.Printf("NetQueueSize:%d, NetConns:%d, Peers:%d, B2G:%d/%d\n", len(network.NetBlocks),
		len(network.OpenCons), peersdb.PeerDB.Count(), b2g_len, b2g_idx_len)
	network.Mutex_net.Unlock()

	network.TxMutex.Lock()
	fmt.Printf("TransactionsToSend:%d,  TransactionsRejected:%d,  TransactionsPending:%d/%d\n",
		len(network.TransactionsToSend), len(network.TransactionsRejected),
		len(network.TransactionsPending), len(network.NetTxs))
	fmt.Printf("WaitingForInputs:%d,  SpentOutputs:%d,  Hashrate:%s,  AverageFee:%.1f SpB\n",
		len(network.WaitingForInputs), len(network.SpentOutputs), usif.GetNetworkHashRate(), common.GetAverageFee())
	network.TxMutex.Unlock()

	common.PrintStats()

	// Memory used
	al, sy := sys.MemUsed()
	fmt.Println("Heap size:", al>>20, "MB    Sys mem used:", sy>>20, "MB    QDB extra mem:",
		atomic.LoadInt64(&qdb.ExtraMemoryConsumed)>>20, "MB in",
		atomic.LoadInt64(&qdb.ExtraMemoryAllocCnt), "recs")

	var gs debug.GCStats
	debug.ReadGCStats(&gs)
	fmt.Println("Go version:", runtime.Version(), "  LastGC:", time.Now().Sub(gs.LastGC).String(),
		"   NumGC:", gs.NumGC,
		"   PauseTotal:", gs.PauseTotal.String())

	fmt.Println("Gocoin:", gocoin.Version,
		"  Uptime:", time.Now().Sub(common.StartTime).String(),
		"  ECDSA cnt:", btc.EcdsaVerifyCnt,
		"  cach:", cached, "  dis:", discarded)
}
开发者ID:piotrnar,项目名称:gocoin,代码行数:59,代码来源:textui.go

示例5: PrintGCSummary

// print gc information to io.Writer
func PrintGCSummary(w io.Writer) {
	memStats := &runtime.MemStats{}
	runtime.ReadMemStats(memStats)
	gcstats := &debug.GCStats{PauseQuantiles: make([]time.Duration, 100)}
	debug.ReadGCStats(gcstats)

	printGC(memStats, gcstats, w)
}
开发者ID:tempbottle,项目名称:xweb,代码行数:9,代码来源:profile.go

示例6: GCSummary

func GCSummary() string {
	memStats := &runtime.MemStats{}
	runtime.ReadMemStats(memStats)
	gcstats := &debug.GCStats{PauseQuantiles: make([]time.Duration, 100)}
	debug.ReadGCStats(gcstats)

	return printGC(memStats, gcstats)
}
开发者ID:yicaoyimuys,项目名称:GoGameServer,代码行数:8,代码来源:profile.go

示例7: PrintGCSummary

// print gc information to io.Writer
func PrintGCSummary(w http.ResponseWriter, r *http.Request) {
	memStats := &runtime.MemStats{}
	runtime.ReadMemStats(memStats)
	gcstats := &debug.GCStats{PauseQuantiles: make([]time.Duration, 100)}
	debug.ReadGCStats(gcstats)

	printGC(memStats, gcstats, w)
}
开发者ID:dzhcool,项目名称:eye,代码行数:9,代码来源:pprof.go

示例8: HandleServer

func (msg *DebugCommand) HandleServer(server *Server) {
	client := msg.Client()
	if !client.flags[Operator] {
		return
	}

	switch msg.subCommand {
	case "GCSTATS":
		stats := debug.GCStats{
			Pause:          make([]time.Duration, 10),
			PauseQuantiles: make([]time.Duration, 5),
		}
		debug.ReadGCStats(&stats)

		server.Replyf(client, "last GC:     %s", stats.LastGC.Format(time.RFC1123))
		server.Replyf(client, "num GC:      %d", stats.NumGC)
		server.Replyf(client, "pause total: %s", stats.PauseTotal)
		server.Replyf(client, "pause quantiles min%%: %s", stats.PauseQuantiles[0])
		server.Replyf(client, "pause quantiles 25%%:  %s", stats.PauseQuantiles[1])
		server.Replyf(client, "pause quantiles 50%%:  %s", stats.PauseQuantiles[2])
		server.Replyf(client, "pause quantiles 75%%:  %s", stats.PauseQuantiles[3])
		server.Replyf(client, "pause quantiles max%%: %s", stats.PauseQuantiles[4])

	case "NUMGOROUTINE":
		count := runtime.NumGoroutine()
		server.Replyf(client, "num goroutines: %d", count)

	case "PROFILEHEAP":
		profFile := "ergonomadic.mprof"
		file, err := os.Create(profFile)
		if err != nil {
			server.Replyf(client, "error: %s", err)
			break
		}
		defer file.Close()
		pprof.Lookup("heap").WriteTo(file, 0)
		server.Replyf(client, "written to %s", profFile)

	case "STARTCPUPROFILE":
		profFile := "ergonomadic.prof"
		file, err := os.Create(profFile)
		if err != nil {
			server.Replyf(client, "error: %s", err)
			break
		}
		if err := pprof.StartCPUProfile(file); err != nil {
			defer file.Close()
			server.Replyf(client, "error: %s", err)
			break
		}

		server.Replyf(client, "CPU profile writing to %s", profFile)

	case "STOPCPUPROFILE":
		pprof.StopCPUProfile()
		server.Reply(client, "CPU profiling stopped")
	}
}
开发者ID:JustinJudd,项目名称:ergonomadic,代码行数:58,代码来源:debug.go

示例9: work

func (w *StatsWorker) work() {
	w.stats["time"] = time.Now()
	w.stats["routes"] = w.collectRouteStats()
	w.stats["other"] = w.collectReporters()
	debug.ReadGCStats(w.gcstats)
	w.rt["gc"] = w.gcstats.NumGC
	w.rt["go"] = int64(runtime.NumGoroutine())
	w.save()
}
开发者ID:karlseguin,项目名称:garnish,代码行数:9,代码来源:stats.go

示例10: 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

示例11: CaptureDebugGCStatsOnce

// Capture new values for the Go garbage collector statistics exported in
// debug.GCStats.  This is designed to be called in a background goroutine.
// Giving a registry which has not been given to RegisterDebugGCStats will
// panic.
func CaptureDebugGCStatsOnce(r Registry) {
	lastGC := gcStats.LastGC
	debug.ReadGCStats(&gcStats)
	r.Get("debug.GCStats.LastGC").(Gauge).Update(int64(gcStats.LastGC.UnixNano()))
	r.Get("debug.GCStats.NumGC").(Gauge).Update(int64(gcStats.NumGC))
	r.Get("debug.GCStats.PauseTotal").(Gauge).Update(int64(gcStats.PauseTotal))
	if lastGC != gcStats.LastGC && 0 < len(gcStats.Pause) {
		r.Get("debug.GCStats.Pause").(Histogram).Update(int64(gcStats.Pause[0]))
	}
	//r.Get("debug.GCStats.PauseQuantiles").(Histogram).Update(gcStats.PauseQuantiles)
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:15,代码来源:debug.go

示例12: CaptureDebugGCStatsOnce

// Capture new values for the Go garbage collector statistics exported in
// debug.GCStats.  This is designed to be called in a background goroutine.
// Giving a registry which has not been given to RegisterDebugGCStats will
// panic.
func CaptureDebugGCStatsOnce(r Registry) {
	lastGC := gcStats.LastGC
	t := time.Now()
	debug.ReadGCStats(&gcStats)
	debugMetrics.ReadGCStats.UpdateSince(t)

	debugMetrics.GCStats.LastGC.Update(int64(gcStats.LastGC.UnixNano()))
	debugMetrics.GCStats.NumGC.Update(int64(gcStats.NumGC))
	if lastGC != gcStats.LastGC && 0 < len(gcStats.Pause) {
		debugMetrics.GCStats.Pause.Update(int64(gcStats.Pause[0]))
	}
	//debugMetrics.GCStats.PauseQuantiles.Update(gcStats.PauseQuantiles)
	debugMetrics.GCStats.PauseTotal.Update(int64(gcStats.PauseTotal))
}
开发者ID:schmichael,项目名称:go-metrics,代码行数:18,代码来源:debug.go

示例13: show_info

func show_info(par string) {
	common.Busy_mutex.Lock()
	if common.BusyWith != "" {
		fmt.Println("Chain thread busy with:", common.BusyWith)
	} else {
		fmt.Println("Chain thread is idle")
	}
	common.Busy_mutex.Unlock()

	common.Last.Mutex.Lock()
	fmt.Println("Last Block:", common.Last.Block.BlockHash.String())
	fmt.Printf("Height: %d @ %s,  Diff: %.0f,  Got: %s ago\n",
		common.Last.Block.Height,
		time.Unix(int64(common.Last.Block.Timestamp()), 0).Format("2006/01/02 15:04:05"),
		btc.GetDifficulty(common.Last.Block.Bits()), time.Now().Sub(common.Last.Time).String())
	common.Last.Mutex.Unlock()

	network.Mutex_net.Lock()
	fmt.Printf("BlocksCached: %d,  NetQueueSize: %d,  NetConns: %d,  Peers: %d\n",
		len(network.CachedBlocks), len(network.NetBlocks), len(network.OpenCons), network.PeerDB.Count())
	network.Mutex_net.Unlock()

	network.TxMutex.Lock()
	fmt.Printf("TransactionsToSend:%d,  TransactionsRejected:%d,  TransactionsPending:%d/%d\n",
		len(network.TransactionsToSend), len(network.TransactionsRejected),
		len(network.TransactionsPending), len(network.NetTxs))
	fmt.Printf("WaitingForInputs:%d,  SpentOutputs:%d,  Hashrate:%s\n",
		len(network.WaitingForInputs), len(network.SpentOutputs), usif.GetNetworkHashRate())
	network.TxMutex.Unlock()

	common.PrintStats()

	// Memory used
	var ms runtime.MemStats
	var gs debug.GCStats
	runtime.ReadMemStats(&ms)
	fmt.Println("Go version:", runtime.Version(),
		"   Heap size:", ms.Alloc>>20, "MB",
		"   Sys mem used", ms.Sys>>20, "MB")

	debug.ReadGCStats(&gs)
	fmt.Println("LastGC:", time.Now().Sub(gs.LastGC).String(),
		"   NumGC:", gs.NumGC,
		"   PauseTotal:", gs.PauseTotal.String())

	fmt.Println("Gocoin:", btc.SourcesTag,
		"  Threads:", btc.UseThreads,
		"  Uptime:", time.Now().Sub(common.StartTime).String(),
		"  ECDSA cnt:", btc.EcdsaVerifyCnt)
}
开发者ID:vipwzw,项目名称:gocoin,代码行数:50,代码来源:textui.go

示例14: damain

//export damain
func damain() {
	var buffer bytes.Buffer
	var gc debug.GCStats

	var lastgc int64

	buffer.Write(make([]byte, 0, 1000000*5))

	debug.ReadGCStats(&gc)
	gcs := strconv.FormatInt(gc.NumGC, 10)
	fmt.Printf("gcs:%v\n", gcs)
	lastgc = gc.LastGC.UnixNano()
	fmt.Printf("lastgc:%v\n", lastgc)
}
开发者ID:deferpanic,项目名称:gorump,代码行数:15,代码来源:hello.go

示例15: updateMetrics

func (gcr *gcReader) updateMetrics() {
	debug.ReadGCStats(&gcStats)

	gcr.numGC.Mark(gcStats.NumGC - gcr.lastNumGC)
	gcr.lastNumGC = gcStats.NumGC

	gcr.pauseDur.Mark(int64(gcStats.PauseTotal - gcr.lastPauseTotal))
	gcr.lastPauseTotal = gcStats.PauseTotal

	if gcr.lastGC != gcStats.LastGC && 0 < len(gcStats.Pause) {
		gcr.pauseTime.Update(int64(gcStats.Pause[0]))
	}

	gcr.lastGC = gcStats.LastGC
}
开发者ID:neocortical,项目名称:gonr,代码行数:15,代码来源:gc.go


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