develop.performance #
Performance Module
A simple V module for measuring and visualizing process performance using Redis for data storage.
Features
- Timestamp Management: Record timestamps for specific events during a process.
- Epoch Handling: Start and end measurement phases using epochs.
- Timeline Visualization: Display detailed timelines with duration bars and color-coded performance indicators.
Installation
Install the repository and import the module:
import performance
Usage
Create a Timer
mut timer := performance.new('my_process')
Add Timestamps
Record a timestamp for an event:
timer.new_timestamp('event_name')
Manage Epochs
Start or end a measurement phase:
timer.epoch() // Start a new epoch
timer.epoch_end() // End the current epoch
Visualize Timelines
Display the recorded timeline:
timer.timeline()
Dependencies
• Redis: Requires a Redis server for data storage. • Redis Client: Uses freeflowuniverse.crystallib.clients.redisclient.
Example
mut timer := performance.new('example_process')
timer.epoch()
timer.new_timestamp('start')
time.sleep(1 * time.second)
timer.new_timestamp('middle')
time.sleep(2 * time.second)
timer.new_timestamp('end')
timer.epoch_end()
timer.timeline()
This will output a detailed timeline with duration bars for each event.
fn new #
fn new(name string) ProcessTimer
Create a new ProcessTimer instance with a unique name including thread ID
struct ProcessTimer #
struct ProcessTimer {
pub:
name string // Name of the timer instance
}
Struct to represent a timer for measuring process performance
fn (ProcessTimer) new_timestamp #
fn (p ProcessTimer) new_timestamp(name_ string)
Add a new timestamp to the current epoch for a specific name or event
fn (ProcessTimer) epoch #
fn (p ProcessTimer) epoch()
Increment the epoch value, effectively starting a new measurement phase
fn (ProcessTimer) epoch_end #
fn (p ProcessTimer) epoch_end()
Increment the epoch value to signify the end of a measurement phase
fn (ProcessTimer) timeline #
fn (p ProcessTimer) timeline()
Generate and display a timeline of events and their durations for each epoch