Documentation
¶
Overview ¶
Package metrics provides utilities for measuring and formatting metrics.
Package metrics provides measurement utilities for source code analysis.
Index ¶
- func EstimateTokens(text string) int
- func EstimateTokensInFile(content []byte) int
- func FormatBytes(bytes int64) string
- func FormatNumber(n int) string
- func WalkSourceFiles(root string, opts WalkOptions) ([]string, error)
- func WalkSourceFilesWithContent(root string, opts WalkOptions, fn func(path string, content []byte) error) error
- type WalkOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstimateTokens ¶
EstimateTokens estimates the token count for text using heuristics.
The estimation accounts for: - Word boundaries (identifiers, keywords) - Code punctuation (braces, parentheses, operators) - GPT tokenizer behavior (~1.5 tokens per word for code)
This is an approximation; actual token counts depend on the specific tokenizer used by the target LLM.
func EstimateTokensInFile ¶
EstimateTokensInFile estimates tokens in a source file. This is a convenience wrapper that accepts byte content.
func FormatBytes ¶
FormatBytes formats a byte count as a human-readable string (e.g., "1.5 KB").
func FormatNumber ¶
FormatNumber formats a number with K/M suffixes for readability.
func WalkSourceFiles ¶
func WalkSourceFiles(root string, opts WalkOptions) ([]string, error)
WalkSourceFiles walks a directory and returns all source files matching the options.
func WalkSourceFilesWithContent ¶
func WalkSourceFilesWithContent(root string, opts WalkOptions, fn func(path string, content []byte) error) error
WalkSourceFilesWithContent walks a directory and calls fn for each matching file with its content. If fn returns an error, walking stops and the error is returned.
Types ¶
type WalkOptions ¶
type WalkOptions struct {
// Extensions to include (e.g., []string{".go", ".java"}). Empty means all files.
Extensions []string
// SkipDirs are directory names to skip (e.g., "vendor", "node_modules").
SkipDirs []string
// SkipHidden skips directories starting with "." (default: true).
SkipHidden bool
// SkipTests skips test files based on language conventions.
SkipTests bool
}
WalkOptions configures source file walking behavior.
func DefaultWalkOptions ¶
func DefaultWalkOptions() WalkOptions
DefaultWalkOptions returns sensible defaults for Go projects.