Skip to content

Repository files navigation

Performance Tracker

A TypeScript utility for tracking timing of events in a digital assistant pipeline. This utility helps identify delays between speech-to-text, LLM processing, and text-to-speech operations in a multi-session environment.

Installation

npm install performance-tracker

Usage

import { PerformanceTracker } from 'performance-tracker';

// Reset the timer for a session
PerformanceTracker.resetTimer('user123');

// Log events with timestamps
PerformanceTracker.logEvent('user123', 'STT_START');
// ... speech-to-text processing happens ...
PerformanceTracker.logEvent('user123', 'STT_END');

// Log events with custom details
PerformanceTracker.logEvent('user123', 'LLM_START', { 
  model: 'gpt-4', 
  promptTokens: 125 
});

// Generate a timing report
const report = PerformanceTracker.generateReport('user123');
console.log(report);

Features

  • Singleton design for application-wide access
  • Session-based timing for multi-user environments
  • Automatic duration calculation between start/end events
  • Detailed reporting of all timing events
  • Support for custom event metadata
  • JSON export for integration with analytics systems

Example Output

Timing Report for Session: user123
Started at: 2025-04-14T08:37:51.835Z
--------------------------------------------------
Event                   | Time (ms) | Duration (ms)
--------------------------------------------------
VOICE_RECEIVED           | 0         | -
STT_START                | 10        | -
STT_END                  | 330       | 320
LLM_START                | 345       | -
LLM_REPLY_1              | 595       | -
TTS_REQUEST_1            | 605       | -
TTS_RESPONSE_1           | 785       | 180
LLM_REPLY_2              | 915       | -
TTS_REQUEST_2            | 925       | -
TTS_RESPONSE_2           | 1105      | 180
LLM_REPLY_3              | 1205      | -
LLM_END                  | 1210      | 865
TTS_REQUEST_3            | 1215      | -
TTS_RESPONSE_3           | 1395      | 180
INTERACTION_COMPLETE     | 1400      | -
--------------------------------------------------
TOTAL TIME:              | 1400ms

Typical Event Names

Here are some standard event names you might use:

  • VOICE_RECEIVED - When voice input is received
  • STT_START - Start of speech-to-text processing
  • STT_END - End of speech-to-text processing
  • LLM_START - Start of LLM request
  • LLM_REPLY_1, LLM_REPLY_2, etc. - When chunks of the LLM response are received
  • LLM_END - When LLM processing completes
  • TTS_REQUEST_1, TTS_REQUEST_2, etc. - When text-to-speech requests are sent
  • TTS_RESPONSE_1, TTS_RESPONSE_2, etc. - When text-to-speech responses are received
  • INTERACTION_COMPLETE - When the entire interaction completes

Advanced Usage

Export Data for Analytics

// Get JSON data for external analysis
const data = PerformanceTracker.exportData('user123');
saveToAnalyticsSystem(data);

Tracking Multiple Sessions

The tracker automatically handles multiple concurrent sessions by session ID:

// Session 1
PerformanceTracker.logEvent('user123', 'STT_START');

// Session 2 (concurrent)
PerformanceTracker.logEvent('user456', 'STT_START');

// Continue tracking separately
PerformanceTracker.logEvent('user123', 'STT_END');
PerformanceTracker.logEvent('user456', 'STT_END');

License

MIT

About

A small utility to track frontend-to-backend interaction timing sequence

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages