Skip to content

Commit 6fe637f

Browse files
committed
core/runmet: m perma skip dbg metrics
1 parent 5bea407 commit 6fe637f

1 file changed

Lines changed: 20 additions & 45 deletions

File tree

intra/core/runmet.go

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,51 +54,30 @@ func init() {
5454
sb.Grow(len(allsamples) * 100)
5555
}
5656

57-
func skipped(s string, skip []string) bool {
58-
for _, prefix := range skip {
59-
if strings.HasPrefix(s, prefix) {
60-
return true
61-
}
62-
}
63-
return false
64-
}
65-
6657
// from pkg.go.dev/runtime/metrics#Read
67-
func Metrics(skip ...string) string {
68-
if len(skip) > 0 {
69-
filtered := make([]metrics.Sample, len(descs))
70-
for i := range filtered {
71-
if skipped(descs[i].Name, skip) {
72-
continue
73-
}
74-
filtered[i].Name = descs[i].Name
75-
}
76-
return readMetrics(filtered)
77-
}
58+
func Metrics() string {
59+
mu.Lock()
60+
defer mu.Unlock()
7861

7962
if !lastcall.IsZero() && time.Since(lastcall) < memoizationThreshold {
80-
mu.Lock()
81-
defer mu.Unlock()
8263
return sb.String()
8364
}
8465

8566
lastcall = time.Now()
86-
return readMetrics(allsamples)
87-
}
88-
89-
// TODO: read only once every 10s?
90-
func readMetrics(samples []metrics.Sample) string {
91-
mu.Lock()
92-
defer mu.Unlock()
9367

9468
sb.Reset()
9569
sb.WriteString("\n")
9670

97-
metrics.Read(samples)
71+
metrics.Read(allsamples)
9872

99-
for _, sample := range samples {
73+
for _, sample := range allsamples {
10074
name, value := sample.Name, sample.Value
10175

76+
switch name {
77+
case MetCgo, MetDbg: // skip debug
78+
continue
79+
}
80+
10281
switch value.Kind() {
10382
case metrics.KindUint64:
10483
s := fmt.Sprintf("%s: %d\n", name, value.Uint64())
@@ -109,7 +88,7 @@ func readMetrics(samples []metrics.Sample) string {
10988
case metrics.KindFloat64Histogram:
11089
// The histogram may be quite large, so let's just pull out
11190
// a crude estimate for the median.
112-
s := fmt.Sprintf("%s: p50(%f)\n", name, medianBucket(value.Float64Histogram()))
91+
s := fmt.Sprintf("%s: hist(%s)\n", name, histoCsv(value.Float64Histogram()))
11392
sb.WriteString(s)
11493
case metrics.KindBad:
11594
fallthrough
@@ -122,19 +101,15 @@ func readMetrics(samples []metrics.Sample) string {
122101
return sb.String()
123102
}
124103

125-
func medianBucket(h *metrics.Float64Histogram) float64 {
126-
total := uint64(0)
127-
for _, count := range h.Counts {
128-
total += count
129-
}
130-
thresh := total / 2
131-
total = 0
132-
for i, count := range h.Counts {
133-
total += count
134-
if total >= thresh {
135-
return h.Buckets[i]
104+
func histoCsv(h *metrics.Float64Histogram) string {
105+
var sb strings.Builder
106+
sb.Grow(20 * len(h.Buckets))
107+
for i, b := range h.Buckets {
108+
s := fmt.Sprintf("%f:%d", b, h.Counts[i])
109+
sb.WriteString(s)
110+
if i < len(h.Buckets)-1 {
111+
sb.WriteString(",")
136112
}
137113
}
138-
// should not happen
139-
return -1.0
114+
return sb.String()
140115
}

0 commit comments

Comments
 (0)