handleMetricsCommand displays runtime telemetry in the terminal.
()
| 15 | |
| 16 | // handleMetricsCommand displays runtime telemetry in the terminal. |
| 17 | func (ch *CommandHandler) handleMetricsCommand() { |
| 18 | c := ch.cli |
| 19 | |
| 20 | fmt.Println() |
| 21 | fmt.Println(colorize(" "+i18n.T("metrics.header"), ColorLime)) |
| 22 | fmt.Println() |
| 23 | |
| 24 | // Provider & Model |
| 25 | model := "" |
| 26 | if c.Client != nil { |
| 27 | model = c.Client.GetModelName() |
| 28 | } |
| 29 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.provider"), ColorCyan), colorize(c.Provider, ColorGray)) |
| 30 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.model"), ColorCyan), colorize(model, ColorGray)) |
| 31 | |
| 32 | // Session info |
| 33 | sessionName := c.currentSessionName |
| 34 | if sessionName == "" { |
| 35 | sessionName = i18n.T("metrics.session.unsaved") |
| 36 | } |
| 37 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.session"), ColorCyan), colorize(sessionName, ColorGray)) |
| 38 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.history_msgs"), ColorCyan), colorize(strconv.Itoa(len(c.history)), ColorGray)) |
| 39 | |
| 40 | // Token usage estimate |
| 41 | tokenLimit := c.UserMaxTokens |
| 42 | if tokenLimit <= 0 { |
| 43 | tokenLimit = c.getMaxTokensForCurrentLLM() |
| 44 | } |
| 45 | tokenUsed := 0 |
| 46 | for _, msg := range c.history { |
| 47 | tokenUsed += len(msg.Content) / 4 // rough estimate: ~4 chars per token |
| 48 | } |
| 49 | tokenPct := 0.0 |
| 50 | if tokenLimit > 0 { |
| 51 | tokenPct = float64(tokenUsed) / float64(tokenLimit) * 100 |
| 52 | } |
| 53 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.tokens"), ColorCyan), |
| 54 | colorize(fmt.Sprintf("%d / %d (%.1f%%)", tokenUsed, tokenLimit, tokenPct), ColorGray)) |
| 55 | |
| 56 | // Turn count |
| 57 | turns := 0 |
| 58 | for _, msg := range c.history { |
| 59 | if msg.Role == "user" { |
| 60 | turns++ |
| 61 | } |
| 62 | } |
| 63 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.turns"), ColorCyan), colorize(strconv.Itoa(turns), ColorGray)) |
| 64 | |
| 65 | // Go runtime |
| 66 | var m runtime.MemStats |
| 67 | runtime.ReadMemStats(&m) |
| 68 | fmt.Println() |
| 69 | fmt.Println(colorize(" "+i18n.T("metrics.header.go_runtime"), ColorLime)) |
| 70 | fmt.Println() |
| 71 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.goroutines"), ColorCyan), colorize(strconv.Itoa(runtime.NumGoroutine()), ColorGray)) |
| 72 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.alloc"), ColorCyan), colorize(formatBytes(m.Alloc), ColorGray)) |
| 73 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.sys"), ColorCyan), colorize(formatBytes(m.Sys), ColorGray)) |
| 74 | fmt.Printf(" %s %s\n", colorize(i18n.T("metrics.label.gc_cycles"), ColorCyan), colorize(strconv.FormatUint(uint64(m.NumGC), 10), ColorGray)) |
no test coverage detected