Documentation
¶
Index ¶
- func CompareMemoryStats(before, after MemoryStats, label string)
- func LogMemoryStats(label string)
- type ExecutionMetrics
- func (m *ExecutionMetrics) ClientOverhead() *time.Duration
- func (m *ExecutionMetrics) GCCount() int32
- func (m *ExecutionMetrics) MemoryUsedMB() float64
- func (m *ExecutionMetrics) RowIterationTime() *time.Duration
- func (m *ExecutionMetrics) TTFB() *time.Duration
- func (m *ExecutionMetrics) TotalAllocatedMB() float64
- func (m *ExecutionMetrics) TotalElapsed() time.Duration
- type MemoryStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareMemoryStats ¶
func CompareMemoryStats(before, after MemoryStats, label string)
CompareMemoryStats compares two memory snapshots
Types ¶
type ExecutionMetrics ¶
type ExecutionMetrics struct {
// Core timing points
QueryStartTime time.Time // When executeSQL started (before sending query to server)
FirstRowTime *time.Time // Time to First Byte (TTFB) - when first row arrived from server
LastRowTime *time.Time // When last row was received/processed by the client
CompletionTime time.Time // When entire operation completed (including cleanup)
// Row statistics
RowCount int64 // Total number of rows processed
// Server-side statistics (from QueryStats)
ServerElapsedTime string // Server-reported elapsed time (actual query execution time on server)
ServerCPUTime string // Server-reported CPU time used on server
// Memory statistics (client-side)
MemoryBefore *MemoryStats // Memory snapshot before query execution
MemoryAfter *MemoryStats // Memory snapshot after query execution
// Execution mode
IsStreaming bool // Whether streaming mode was used
// Profile flag
Profile bool // Whether profiling is enabled (controls display in template)
}
ExecutionMetrics captures timing and performance metrics for query execution. This supports both streaming and buffered modes with unified metrics collection.
Timeline of events:
QueryStartTime -> [server processing] -> FirstRowTime -> [row iteration] -> LastRowTime -> [cleanup] -> CompletionTime
func (*ExecutionMetrics) ClientOverhead ¶
func (m *ExecutionMetrics) ClientOverhead() *time.Duration
ClientOverhead estimates the client-side overhead beyond server processing time. This includes network latency, client-side processing, and any buffering. Returns nil if server elapsed time is not available.
func (*ExecutionMetrics) GCCount ¶
func (m *ExecutionMetrics) GCCount() int32
GCCount returns the number of garbage collections during execution, or -1 if not available.
func (*ExecutionMetrics) MemoryUsedMB ¶
func (m *ExecutionMetrics) MemoryUsedMB() float64
MemoryUsedMB returns the memory used during query execution in MB, or -1 if not available.
func (*ExecutionMetrics) RowIterationTime ¶
func (m *ExecutionMetrics) RowIterationTime() *time.Duration
RowIterationTime returns the time spent iterating through rows, or nil if not available. This is the duration from when the first row arrived to when the last row was processed. Note: This is NOT the actual network transfer time, but rather the time span during which rows were being received and processed. It includes both network transfer and client processing for each row.
func (*ExecutionMetrics) TTFB ¶
func (m *ExecutionMetrics) TTFB() *time.Duration
TTFB returns the Time to First Byte duration, or nil if not available. This measures the time from when the query was sent to when the first row arrived. It includes network latency, server query planning, and time to produce the first row.
func (*ExecutionMetrics) TotalAllocatedMB ¶
func (m *ExecutionMetrics) TotalAllocatedMB() float64
TotalAllocatedMB returns the total memory allocated during execution in MB, or -1 if not available.
func (*ExecutionMetrics) TotalElapsed ¶
func (m *ExecutionMetrics) TotalElapsed() time.Duration
TotalElapsed returns the total elapsed time for the entire operation. This includes everything from query start to completion, including all network transfers, server processing, client processing, and cleanup.
type MemoryStats ¶
type MemoryStats struct {
AllocMB uint64 // Allocated memory in MB
TotalAllocMB uint64 // Total allocated memory in MB
SysMB uint64 // System memory in MB
NumGC uint32 // Number of GC cycles
}
MemoryStats captures memory usage statistics
func GetMemoryStats ¶
func GetMemoryStats() MemoryStats
GetMemoryStats returns current memory statistics Note: runtime.ReadMemStats() causes stop-the-world (STW) pause, so this should only be called when performance profiling is needed