mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:24:18 +02:00
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
/*
|
|
Copyright © 2026 Thomas von Dein
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package printer
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime/metrics"
|
|
"strconv"
|
|
)
|
|
|
|
func printGoRoutineMetrics() {
|
|
fmt.Println("\nGoroutine metrics:")
|
|
printMetric("/sched/goroutines-created:goroutines", "Created")
|
|
printMetric("/sched/goroutines:goroutines", "Live")
|
|
printMetric("/sched/goroutines/not-in-go:goroutines", "Syscall/CGO")
|
|
printMetric("/sched/goroutines/runnable:goroutines", "Runnable")
|
|
printMetric("/sched/goroutines/running:goroutines", "Running")
|
|
printMetric("/sched/goroutines/waiting:goroutines", "Waiting")
|
|
|
|
fmt.Println("Thread metrics:")
|
|
printMetric("/sched/gomaxprocs:threads", "Max")
|
|
printMetric("/sched/threads/total:threads", "Live")
|
|
}
|
|
|
|
func printMetric(name string, descr string) {
|
|
sample := []metrics.Sample{{Name: name}}
|
|
metrics.Read(sample)
|
|
|
|
var val string
|
|
|
|
switch sample[0].Value.Kind() {
|
|
case metrics.KindFloat64, metrics.KindFloat64Histogram:
|
|
val = fmt.Sprintf("%.2f", sample[0].Value.Float64())
|
|
case metrics.KindUint64:
|
|
val = strconv.FormatUint(sample[0].Value.Uint64(), 10)
|
|
case metrics.KindBad:
|
|
val = "n/a"
|
|
}
|
|
|
|
fmt.Printf(" %s: %v\n", descr, val)
|
|
}
|