European Parliament MCP Server API - v1.0.1
    Preparing search index...

    Class PerformanceMonitor

    Performance monitor for tracking operation metrics

    Tracks duration of operations and provides statistical analysis. Useful for identifying performance regressions and bottlenecks.

    const monitor = new PerformanceMonitor();

    // Record operation durations
    monitor.recordDuration('api_call', 150);
    monitor.recordDuration('api_call', 200);

    // Get statistics
    const stats = monitor.getStats('api_call');
    console.log(`p95: ${stats.p95}ms`);
    Index

    Constructors

    • Creates a new performance monitor.

      Parameters

      • maxSamples: number = 1000

        Maximum number of duration samples to retain per operation name. Older samples are evicted when the limit is reached (sliding window). Default: 1000.

      Returns PerformanceMonitor

      If maxSamples is not a positive finite integer

      const monitor = new PerformanceMonitor(500);
      

      0.8.0

    Properties

    maxSamples: number
    metrics: Map<string, number[]> = ...

    Methods

    • Clears all recorded duration samples for every tracked operation.

      Useful for resetting state between test cases or at the start of a new monitoring window.

      Returns void

      // Reset metrics after each test
      afterEach(() => {
      monitor.clear();
      });

      0.8.0

    • Clears recorded duration samples for a single operation.

      Parameters

      • operation: string

        Operation name whose samples should be discarded

      Returns void

      monitor.clearOperation('api_call');
      

      0.8.0

    • Returns all operation names currently being tracked.

      Returns string[]

      Array of operation name strings, in insertion order

      const operations = monitor.getOperations();
      operations.forEach(op => {
      const stats = monitor.getStats(op);
      console.log(`${op}: p95=${stats?.p95}ms`);
      });

      0.8.0

    • Returns aggregated performance statistics for a named operation.

      Calculates percentiles (p50 / p95 / p99), average, min, and max from the stored duration samples. Returns null when no samples have been recorded for the operation yet.

      Parameters

      • operation: string

        Operation name / identifier to query

      Returns PerformanceStats | null

      PerformanceStats object, or null if no data exists

      If operation is not a string

      const stats = monitor.getStats('api_call');
      if (stats && stats.p95 > 1000) {
      console.warn('API calls are slow (p95 > 1s)');
      }

      0.8.0

    • Records a duration sample for the named operation.

      When the number of stored samples reaches maxSamples, the oldest entries are evicted in bulk (sliding window). Use getStats to retrieve aggregated statistics after recording samples.

      Parameters

      • operation: string

        Unique operation name / identifier (e.g., 'ep_api_call')

      • durationMs: number

        Observed duration in milliseconds (should be ≥ 0)

      Returns void

      If operation is not a string

      const start = performance.now();
      await doWork();
      monitor.recordDuration('work', performance.now() - start);

      0.8.0