MCPcopy Index your code
hub / github.com/github/gh-aw / renderTokenUsageDiffPrettySection

Function renderTokenUsageDiffPrettySection

pkg/cli/audit_diff_render.go:516–585  ·  view source on GitHub ↗

renderTokenUsageDiffPrettySection renders detailed token usage as a pretty console sub-section

(run1ID, run2ID int64, diff *TokenUsageDiff)

Source from the content-addressed store, hash-verified

514
515// renderTokenUsageDiffPrettySection renders detailed token usage as a pretty console sub-section
516func renderTokenUsageDiffPrettySection(run1ID, run2ID int64, diff *TokenUsageDiff) {
517 fmt.Fprintln(os.Stderr, console.FormatSectionHeader("Token Usage Details"))
518 fmt.Fprintln(os.Stderr)
519
520 config := console.TableConfig{
521 Headers: []string{"Token Type", fmt.Sprintf("Run #%d", run1ID), fmt.Sprintf("Run #%d", run2ID), "Change"},
522 Rows: make([][]string, 0),
523 }
524
525 if diff.Run1InputTokens > 0 || diff.Run2InputTokens > 0 {
526 config.Rows = append(config.Rows, []string{
527 "Input",
528 strconv.Itoa(diff.Run1InputTokens),
529 strconv.Itoa(diff.Run2InputTokens),
530 diff.InputTokensChange,
531 })
532 }
533 if diff.Run1OutputTokens > 0 || diff.Run2OutputTokens > 0 {
534 config.Rows = append(config.Rows, []string{
535 "Output",
536 strconv.Itoa(diff.Run1OutputTokens),
537 strconv.Itoa(diff.Run2OutputTokens),
538 diff.OutputTokensChange,
539 })
540 }
541 if diff.Run1CacheReadTokens > 0 || diff.Run2CacheReadTokens > 0 {
542 config.Rows = append(config.Rows, []string{
543 "Cache read",
544 strconv.Itoa(diff.Run1CacheReadTokens),
545 strconv.Itoa(diff.Run2CacheReadTokens),
546 diff.CacheReadTokensChange,
547 })
548 }
549 if diff.Run1CacheWriteTokens > 0 || diff.Run2CacheWriteTokens > 0 {
550 config.Rows = append(config.Rows, []string{
551 "Cache write",
552 strconv.Itoa(diff.Run1CacheWriteTokens),
553 strconv.Itoa(diff.Run2CacheWriteTokens),
554 diff.CacheWriteTokensChange,
555 })
556 }
557 if diff.Run1AIC > 0 || diff.Run2AIC > 0 {
558 config.Rows = append(config.Rows, []string{
559 "AI Credits",
560 fmt.Sprintf("%.3f", diff.Run1AIC),
561 fmt.Sprintf("%.3f", diff.Run2AIC),
562 diff.AICChange,
563 })
564 }
565 if diff.Run1TotalRequests > 0 || diff.Run2TotalRequests > 0 {
566 config.Rows = append(config.Rows, []string{
567 "API requests",
568 strconv.Itoa(diff.Run1TotalRequests),
569 strconv.Itoa(diff.Run2TotalRequests),
570 diff.RequestsDelta,
571 })
572 }
573 if diff.Run1CacheEfficiency > 0 || diff.Run2CacheEfficiency > 0 {

Callers 1

Calls 2

FormatSectionHeaderFunction · 0.92
RenderTableFunction · 0.92

Tested by

no test coverage detected