func CaptureRuntimeMemStatsWithContext(ctx context.Context, registry RootRegistry, collectionFreq time.Duration) bool {
	mRegProvider, ok := registry.(metricsRegistryProvider)
	if !ok {
		return false
	}

	goRegistry := metrics.NewPrefixedChildRegistry(mRegProvider.Registry(), "go.")
	metrics.RegisterRuntimeMemStats(goRegistry)
	go func() {
		ticker := time.NewTicker(collectionFreq)
		defer ticker.Stop()
		for {
			select {
			case <-ticker.C:
				metrics.CaptureRuntimeMemStatsOnce(goRegistry)
			case <-ctx.Done():
				return
			}
		}
	}()
	return true
}
// CaptureRuntimeMemStatsWithContext creates a child registry of the provided registry that tracks Go runtime memory
// metrics and starts a goroutine that captures them to that registry every collectionFreq. This function only supports
// RootRegistry implementations that implement the metricsRegistryProvider interface -- if the provided RootRegistry
// does not satisfy this interface, this function is a no-op. This function returns true if it starts the runtime metric
// collection goroutine, false otherwise. If this function starts a goroutine, the goroutine runs until the provided
// context is done.
//
// The gauges/metrics etc. used to track runtime statistics are shared globally and the values are reset every time this
// function is called (if it is not a no-op). Note that this function should typically only be called once per Go
// runtime, but no enforcement of this is performed.
CaptureRuntimeMemStatsWithContext creates a child registry of the provided registry that tracks Go runtime memory
metrics and starts a goroutine that captures them to that registry every collectionFreq. This function only supports
RootRegistry implementations that implement the metricsRegistryProvider interface -- if the provided RootRegistry
does not satisfy this interface, this function is a no-op. This function returns true if it starts the runtime metric
collection goroutine, false otherwise. If this function starts a goroutine, the goroutine runs until the provided
context is done.

The gauges/metrics etc. used to track runtime statistics are shared globally and the values are reset every time this
function is called (if it is not a no-op). Note that this function should typically only be called once per Go
runtime, but no enforcement of this is performed.
// CaptureRuntimeMemStatsWithContext creates a child registry of the provided registry that tracks Go runtime memory // metrics and starts a goroutine that captures them to that registry every collectionFreq . This function only supports // RootRegistry implementations that implement the metricsRegistryProvider interface -- if the provided RootRegistry // does not satisfy this interface this function is a no - op . This function returns true if it starts the runtime metric // collection goroutine false otherwise . If this function starts a goroutine the goroutine runs until the provided // context is done . // // The gauges / metrics etc . used to track runtime statistics are shared globally and the values are reset every time this // function is called ( if it is not a no - op ) . Note that this function should typically only be called once per Go // runtime but no enforcement of this is performed .
func CaptureRuntimeMemStatsWithContext(ctx context.Context, registry RootRegistry, collectionFreq time.Duration) bool {
	mRegProvider, ok := registry.(metricsRegistryProvider)
	if !ok {
		return false
	}
	goRegistry := metrics.NewPrefixedChildRegistry(mRegProvider.Registry(), "go.")
	metrics.RegisterRuntimeMemStats(goRegistry)
	go func() {
		ticker := time.NewTicker(collectionFreq)
		defer ticker.Stop()
		for {
			select {
			case <-ticker.C:
				metrics.CaptureRuntimeMemStatsOnce(goRegistry)
			case <-ctx.Done():
				return
			}
		}
	}()
	return true
}
func CaptureRuntimeMemStatsWithContext ( ctx context . Context , registry RootRegistry , collectionFreq time . Duration ) bool { mRegProvider , ok := registry . ( metricsRegistryProvider ) if ! ok { return false } goRegistry := metrics . NewPrefixedChildRegistry ( mRegProvider . Registry ( ) , " " ) metrics . RegisterRuntimeMemStats ( goRegistry ) go func ( ) { ticker := time . NewTicker ( collectionFreq ) defer ticker . Stop ( ) for { select { case <- ticker . C : metrics . CaptureRuntimeMemStatsOnce ( goRegistry ) case <- ctx . Done ( ) : return } } } ( ) return true }
CaptureRuntimeMemStatsWithContext creates a child registry of the provided registry that tracks Go runtime memory
metrics and starts a goroutine that captures them to that registry every collectionFreq.
CaptureRuntimeMemStatsWithContext creates a child registry of the provided registry that tracks Go runtime memory metrics and starts a goroutine that captures them to that registry every collectionFreq .