Skip to main content

flamegraph.go

flamegraph.go - Overview

This file contains functions related to generating flamegraphs from trace data. It includes functionalities for traversing traces, selecting spans, and sampling spans for visualization.

Detailed Documentation

SPAN_LIMIT_PER_REQUEST_FOR_FLAMEGRAPH float64

var (
SPAN_LIMIT_PER_REQUEST_FOR_FLAMEGRAPH float64 = 50
SPAN_LIMIT_PER_LEVEL int = 100
TIMESTAMP_SAMPLING_BUCKET_COUNT int = 50
)
  • Purpose: Defines constants for limiting the number of spans in flamegraphs.
    • SPAN_LIMIT_PER_REQUEST_FOR_FLAMEGRAPH: Maximum number of spans to include in a flamegraph request.
    • SPAN_LIMIT_PER_LEVEL: Maximum number of spans per level in the flamegraph.
    • TIMESTAMP_SAMPLING_BUCKET_COUNT: Number of buckets to use for timestamp sampling.

ContainsFlamegraphSpan(slice []*model.FlamegraphSpan, item *model.FlamegraphSpan) bool

func ContainsFlamegraphSpan(slice []*model.FlamegraphSpan, item *model.FlamegraphSpan) bool { ... }
  • Purpose: Checks if a model.FlamegraphSpan exists in a slice of model.FlamegraphSpan pointers.
    • Parameters:
      • slice: Slice of *model.FlamegraphSpan to search within.
      • item: *model.FlamegraphSpan to search for.
    • Returns: true if the item is found in the slice, false otherwise.

BfsTraversalForTrace(span *model.FlamegraphSpan, level int64) map[int64][]*model.FlamegraphSpan

func BfsTraversalForTrace(span *model.FlamegraphSpan, level int64) map[int64][]*model.FlamegraphSpan { ... }
  • Purpose: Performs a Breadth-First Search (BFS) traversal of a trace to organize spans by level.
    • Parameters:
      • span: The starting *model.FlamegraphSpan for the traversal.
      • level: The level of the starting span (typically 0 for root).
    • Returns: A map where keys are levels (int64) and values are slices of *model.FlamegraphSpan at that level.

FindIndexForSelectedSpan(spans [][]*model.FlamegraphSpan, selectedSpanId string) int

func FindIndexForSelectedSpan(spans [][]*model.FlamegraphSpan, selectedSpanId string) int { ... }
  • Purpose: Finds the level index of a selected span ID within a 2D slice of spans.
    • Parameters:
      • spans: 2D slice of *model.FlamegraphSpan organized by level.
      • selectedSpanId: The SpanID to search for.
    • Returns: The level index of the selected span, or 0 if not found.

GetSelectedSpansForFlamegraph(traceRoots []*model.FlamegraphSpan, spanIdToSpanNodeMap map[string]*model.FlamegraphSpan) [][]*model.FlamegraphSpan

func GetSelectedSpansForFlamegraph(traceRoots []*model.FlamegraphSpan, spanIdToSpanNodeMap map[string]*model.FlamegraphSpan) [][]*model.FlamegraphSpan { ... }
  • Purpose: Retrieves selected spans for flamegraph generation, organized by level.
    • Parameters:
      • traceRoots: Slice of root spans (*model.FlamegraphSpan) for the traces.
      • spanIdToSpanNodeMap: Map of SpanID to *model.FlamegraphSpan for quick lookup.
    • Returns: A 2D slice of *model.FlamegraphSpan, organized by level.

getLatencyAndTimestampBucketedSpans(spans []*model.FlamegraphSpan, selectedSpanID string, isSelectedSpanIDPresent bool, startTime uint64, endTime uint64) []*model.FlamegraphSpan

func getLatencyAndTimestampBucketedSpans(spans []*model.FlamegraphSpan, selectedSpanID string, isSelectedSpanIDPresent bool, startTime uint64, endTime uint64) []*model.FlamegraphSpan { ... }
  • Purpose: Samples spans based on latency and timestamp bucketing to reduce the number of spans.
    • Parameters:
      • spans: Slice of *model.FlamegraphSpan to sample.
      • selectedSpanID: The ID of the selected span (if any).
      • isSelectedSpanIDPresent: Whether the selected span ID is present in the current set of spans.
      • startTime: Start time of the trace.
      • endTime: End time of the trace.
    • Returns: A slice of sampled *model.FlamegraphSpan.

GetSelectedSpansForFlamegraphForRequest(selectedSpanID string, selectedSpans [][]*model.FlamegraphSpan, startTime uint64, endTime uint64) [][]*model.FlamegraphSpan

func GetSelectedSpansForFlamegraphForRequest(selectedSpanID string, selectedSpans [][]*model.FlamegraphSpan, startTime uint64, endTime uint64) [][]*model.FlamegraphSpan { ... }
  • Purpose: Retrieves a limited set of spans for a flamegraph request, focusing on spans around a selected span and applying latency/timestamp bucketing.
    • Parameters:
      • selectedSpanID: The ID of the selected span (if any).
      • selectedSpans: 2D slice of *model.FlamegraphSpan, organized by level.
      • startTime: Start time of the trace.
      • endTime: End time of the trace.
    • Returns: A 2D slice of *model.FlamegraphSpan for the flamegraph request.

Include in Getting Started: NO