trident_fuzz/trident/
metrics.rs

1use crate::trident::Trident;
2use solana_sdk::pubkey::Pubkey;
3
4impl Trident {
5    /// Records a value in a histogram metric
6    ///
7    /// Histogram metrics track the distribution of values over time,
8    /// useful for measuring performance characteristics like execution times,
9    /// gas usage, or other numerical distributions.
10    ///
11    /// # Arguments
12    /// * `metric_name` - Name of the histogram metric
13    /// * `value` - The value to record in the histogram
14    ///
15    /// # Note
16    /// Metrics are only recorded when the FUZZING_METRICS environment variable is set
17    pub fn record_histogram(&mut self, metric_name: &str, value: f64) {
18        let metrics = std::env::var("FUZZING_METRICS");
19        if metrics.is_ok() {
20            self.fuzzing_data.add_to_histogram(metric_name, value);
21        }
22    }
23
24    /// Records a value in an accumulator metric
25    ///
26    /// Accumulator metrics sum up values over time, useful for tracking
27    /// totals like total gas consumed, total tokens transferred, etc.
28    ///
29    /// # Arguments
30    /// * `metric_name` - Name of the accumulator metric
31    /// * `value` - The value to add to the accumulator
32    ///
33    /// # Note
34    /// Metrics are only recorded when the FUZZING_METRICS environment variable is set
35    pub fn record_accumulator(&mut self, metric_name: &str, value: f64) {
36        let metrics = std::env::var("FUZZING_METRICS");
37        if metrics.is_ok() {
38            self.fuzzing_data.add_to_accumulator(metric_name, value);
39        }
40    }
41
42    /// Tracks account state for regression testing
43    ///
44    /// This method captures the current state of an account for regression
45    /// analysis, allowing you to detect when account states change unexpectedly
46    /// between fuzzing runs.
47    ///
48    /// # Arguments
49    /// * `account` - The public key of the account to track
50    /// * `account_name` - A descriptive name for the account
51    ///
52    /// # Note
53    /// Account tracking is only enabled when the FUZZING_REGRESSION environment variable is set
54    pub fn track_account_regression(&mut self, account: &Pubkey, account_name: &str) {
55        let regression = std::env::var("FUZZING_REGRESSION");
56        if regression.is_ok() {
57            let account_shared_data = self.client.get_account(account).unwrap_or_default();
58            self.fuzzing_data.add_to_regression(
59                &hex::encode(self.rng.get_seed()),
60                account_name,
61                &account_shared_data,
62            );
63        }
64    }
65}