Documentation
¶
Overview ¶
Package shotness provides shotness functionality.
Index ¶
- Constants
- Variables
- func GenerateStoreSections(reader analyze.ReportReader) ([]plotpage.Section, error)
- func RegisterPlotSections()
- type AggregateData
- type Analyzer
- func (s *Analyzer) ApplySnapshot(snap analyze.PlumbingSnapshot)
- func (s *Analyzer) Boot() error
- func (s *Analyzer) Configure(facts map[string]any) error
- func (s *Analyzer) Consume(ctx context.Context, ac *analyze.Context) (analyze.TC, error)
- func (s *Analyzer) DiscardState()
- func (s *Analyzer) ExtractCommitTimeSeries(report analyze.Report) map[string]any
- func (s *Analyzer) Fork(n int) []analyze.HistoryAnalyzer
- func (s *Analyzer) GenerateChart(report analyze.Report) (components.Charter, error)
- func (s *Analyzer) GenerateSections(report analyze.Report) ([]plotpage.Section, error)
- func (s *Analyzer) Hibernate() error
- func (s *Analyzer) Initialize(_ *gitlib.Repository) error
- func (s *Analyzer) Merge(branches []analyze.HistoryAnalyzer)
- func (s *Analyzer) Name() string
- func (s *Analyzer) NeedsUAST() bool
- func (s *Analyzer) ReleaseSnapshot(snap analyze.PlumbingSnapshot)
- func (s *Analyzer) SnapshotPlumbing() analyze.PlumbingSnapshot
- func (s *Analyzer) WriteToStore(ctx context.Context, ticks []analyze.TICK, w analyze.ReportWriter) error
- type CommitData
- type CommitSummary
- type ComputedMetrics
- type HotspotNodeData
- type NodeCouplingData
- type NodeDelta
- type NodeHotnessData
- type NodeStoreRecord
- type NodeSummary
- type ReportData
- type TickData
Constants ¶
const ( // ConfigShotnessDSLStruct is the configuration key for the DSL structure expression. ConfigShotnessDSLStruct = "Shotness.DSLStruct" // ConfigShotnessDSLName is the configuration key for the DSL name expression. ConfigShotnessDSLName = "Shotness.DSLName" // DefaultShotnessDSLStruct is the default DSL expression for selecting code structures. DefaultShotnessDSLStruct = "filter(.roles has \"Function\")" // DefaultShotnessDSLName is the default DSL expression for extracting names. DefaultShotnessDSLName = ".props.name" )
const ( HotspotThresholdHigh = 20 HotspotThresholdMedium = 10 )
Hotspot thresholds.
const ( RiskLevelHigh = "HIGH" RiskLevelMedium = "MEDIUM" RiskLevelLow = "LOW" )
Risk level constants.
const ( KindNodeData = "node_data" KindAggregate = "aggregate" )
Store record kind constants.
Variables ¶
var ErrInvalidCounters = errors.New("invalid shotness report: expected []map[int]int for Counters")
ErrInvalidCounters indicates the report doesn't contain expected counters data.
var ErrInvalidNodes = errors.New("invalid shotness report: expected []NodeSummary for Nodes")
ErrInvalidNodes indicates the report doesn't contain expected nodes data.
Functions ¶
func GenerateStoreSections ¶
func GenerateStoreSections(reader analyze.ReportReader) ([]plotpage.Section, error)
GenerateStoreSections reads pre-computed shotness data from a ReportReader and builds the same plot sections as GenerateSections, without materializing a full Report or recomputing the co-change matrix.
func RegisterPlotSections ¶
func RegisterPlotSections()
RegisterPlotSections registers the shotness plot section renderer with the analyze package.
Types ¶
type AggregateData ¶
type AggregateData struct {
TotalNodes int `json:"total_nodes" yaml:"total_nodes"`
TotalChanges int `json:"total_changes" yaml:"total_changes"`
TotalCouplings int `json:"total_couplings" yaml:"total_couplings"`
AvgChangesPerNode float64 `json:"avg_changes_per_node" yaml:"avg_changes_per_node"`
AvgCouplingStrength float64 `json:"avg_coupling_strength" yaml:"avg_coupling_strength"`
HotNodes int `json:"hot_nodes" yaml:"hot_nodes"`
}
AggregateData contains summary statistics.
type Analyzer ¶
type Analyzer struct {
*analyze.BaseHistoryAnalyzer[*ComputedMetrics]
FileDiff *plumbing.FileDiffAnalyzer
UAST *plumbing.UASTChangesAnalyzer
DSLStruct string
DSLName string
// contains filtered or unexported fields
}
Analyzer measures co-change frequency of code entities across commit history.
func (*Analyzer) ApplySnapshot ¶
func (s *Analyzer) ApplySnapshot(snap analyze.PlumbingSnapshot)
ApplySnapshot restores plumbing state from a previously captured snapshot.
func (*Analyzer) Boot ¶
Boot restores the analyzer from hibernated state. Re-initializes the merge tracker for the next chunk.
func (*Analyzer) DiscardState ¶
func (s *Analyzer) DiscardState()
DiscardState clears cumulative node coupling state. In streaming timeseries mode, per-commit data is already captured in the TC; the accumulated nodes map (which grows O(N²) with coupling pairs) is only needed for the final report and can be discarded between chunks.
func (*Analyzer) ExtractCommitTimeSeries ¶
ExtractCommitTimeSeries implements analyze.CommitTimeSeriesProvider. It extracts per-commit structural hotspot data for the unified timeseries output.
func (*Analyzer) Fork ¶
func (s *Analyzer) Fork(n int) []analyze.HistoryAnalyzer
Fork creates a copy of the analyzer for parallel processing. Each fork gets independent mutable state while sharing read-only dependencies.
func (*Analyzer) GenerateChart ¶
GenerateChart creates a bar chart showing the hottest functions.
func (*Analyzer) GenerateSections ¶
GenerateSections returns the sections for combined reports.
func (*Analyzer) Hibernate ¶
Hibernate compresses the analyzer's state to reduce memory usage. Resets the merge tracker since processed commits won't be seen again during streaming (commits are processed chronologically).
func (*Analyzer) Initialize ¶
func (s *Analyzer) Initialize(_ *gitlib.Repository) error
Initialize prepares the analyzer for processing commits.
func (*Analyzer) Merge ¶
func (s *Analyzer) Merge(branches []analyze.HistoryAnalyzer)
Merge combines results from forked analyzer branches.
func (*Analyzer) ReleaseSnapshot ¶
func (s *Analyzer) ReleaseSnapshot(snap analyze.PlumbingSnapshot)
ReleaseSnapshot releases UAST trees owned by the snapshot.
func (*Analyzer) SnapshotPlumbing ¶
func (s *Analyzer) SnapshotPlumbing() analyze.PlumbingSnapshot
SnapshotPlumbing captures the current plumbing output state for parallel execution.
func (*Analyzer) WriteToStore ¶
func (s *Analyzer) WriteToStore(ctx context.Context, ticks []analyze.TICK, w analyze.ReportWriter) error
WriteToStore implements analyze.StoreWriter. It merges per-tick node data, builds the co-change matrix, and streams pre-computed results as individual records:
- "node_data": per-node NodeStoreRecord records (sorted by node key).
- "aggregate": single AggregateData record.
type CommitData ¶
type CommitData struct {
// NodesTouched maps node key to its delta for this commit.
NodesTouched map[string]NodeDelta
}
CommitData is the per-commit TC payload emitted by Consume(). It captures per-commit node touch deltas; coupling pairs are derived inline by the aggregator from NodesTouched keys to avoid O(N²) allocation.
type CommitSummary ¶
type CommitSummary struct {
NodesTouched int `json:"nodes_touched"`
CouplingPairs int `json:"coupling_pairs"`
}
CommitSummary holds per-commit summary data for timeseries output.
type ComputedMetrics ¶
type ComputedMetrics struct {
NodeHotness []NodeHotnessData `json:"node_hotness" yaml:"node_hotness"`
NodeCoupling []NodeCouplingData `json:"node_coupling" yaml:"node_coupling"`
HotspotNodes []HotspotNodeData `json:"hotspot_nodes" yaml:"hotspot_nodes"`
Aggregate AggregateData `json:"aggregate" yaml:"aggregate"`
}
ComputedMetrics holds all computed metric results for the shotness analyzer.
func ComputeAllMetrics ¶
func ComputeAllMetrics(report analyze.Report) (*ComputedMetrics, error)
ComputeAllMetrics runs all shotness metrics and returns the results.
func (*ComputedMetrics) AnalyzerName ¶
func (m *ComputedMetrics) AnalyzerName() string
AnalyzerName returns the analyzer identifier.
func (*ComputedMetrics) ToJSON ¶
func (m *ComputedMetrics) ToJSON() any
ToJSON returns the metrics in JSON-serializable format.
func (*ComputedMetrics) ToYAML ¶
func (m *ComputedMetrics) ToYAML() any
ToYAML returns the metrics in YAML-serializable format.
type HotspotNodeData ¶
type HotspotNodeData struct {
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"`
File string `json:"file" yaml:"file"`
ChangeCount int `json:"change_count" yaml:"change_count"`
RiskLevel string `json:"risk_level" yaml:"risk_level"`
}
HotspotNodeData identifies hot nodes that change frequently.
type NodeCouplingData ¶
type NodeCouplingData struct {
Node1Name string `json:"node1_name" yaml:"node1_name"`
Node1File string `json:"node1_file" yaml:"node1_file"`
Node2Name string `json:"node2_name" yaml:"node2_name"`
Node2File string `json:"node2_file" yaml:"node2_file"`
CoChanges int `json:"co_changes" yaml:"co_changes"`
Strength float64 `json:"coupling_strength" yaml:"coupling_strength"`
}
NodeCouplingData contains coupling between code nodes.
type NodeDelta ¶
type NodeDelta struct {
// Summary identifies the node (type, name, file).
Summary NodeSummary
// CountDelta is the change count increment (1 for first touch in a commit, 0 otherwise).
CountDelta int
}
NodeDelta represents a single node's contribution in one commit.
type NodeHotnessData ¶
type NodeHotnessData struct {
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"`
File string `json:"file" yaml:"file"`
ChangeCount int `json:"change_count" yaml:"change_count"`
CoupledNodes int `json:"coupled_nodes" yaml:"coupled_nodes"`
HotnessScore float64 `json:"hotness_score" yaml:"hotness_score"`
}
NodeHotnessData contains hotness information for a code node.
type NodeStoreRecord ¶
type NodeStoreRecord struct {
Summary NodeSummary
Counter map[int]int
}
NodeStoreRecord holds a single node's summary and co-change counter map. Counter keys are node indices into the ordered node list; counter values are co-change counts; counter[self] is the node's self-change count.
type NodeSummary ¶
NodeSummary holds identifying information for a code node.
func (*NodeSummary) String ¶
func (ns *NodeSummary) String() string
type ReportData ¶
type ReportData struct {
Nodes []NodeSummary
Counters []map[int]int
}
ReportData is the parsed input data for shotness metrics computation.
func ParseReportData ¶
func ParseReportData(report analyze.Report) (*ReportData, error)
ParseReportData extracts ReportData from an analyzer report.
type TickData ¶
type TickData struct {
// Nodes maps node key to accumulated node data.
Nodes map[string]*nodeShotnessData
// CommitStats holds per-commit summary data for timeseries output.
CommitStats map[string]*CommitSummary
}
TickData is the per-tick aggregated payload stored in analyze.TICK.Data.