Skip to content

feat(metrics): add performance timing helpers #12

@CalvinAllen

Description

@CalvinAllen

Summary

Add simple, ergonomic helpers for timing operations and recording durations to histograms. Reduces boilerplate for the common pattern of measuring how long something takes.

Proposed API

// Simple timing with auto-record to histogram
var timing = VsixTelemetry.StartTiming();
// ... do work ...
timing.Record("MyOperation"); // Records to vs.extension.operation.duration

// Timing with custom histogram
var timing = VsixTelemetry.StartTiming();
// ... do work ...
timing.RecordTo(myCustomHistogram, tags);

// One-liner for sync operations
var result = VsixTelemetry.Timed("LoadData", () => LoadDataFromDatabase());

// Async version
var result = await VsixTelemetry.TimedAsync("LoadData", async () => 
    await LoadDataFromDatabaseAsync());

// With automatic span creation
var result = VsixTelemetry.TimedWithSpan("LoadData", () => 
{
    // Creates span AND records duration
    return LoadDataFromDatabase();
});

Timing Class

public class OperationTiming
{
    public TimeSpan Elapsed { get; }
    public void Record(string operationName, params KeyValuePair<string, object>[] tags);
    public void RecordTo<T>(Histogram<T> histogram, params KeyValuePair<string, object>[] tags);
    public void AddTag(string key, object value);
}

Benefits

  • Less boilerplate than manual Stopwatch usage
  • Consistent metric naming and tagging
  • Easy to add timing to existing code
  • Combines well with span creation

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions