-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move-vm][aptos-vm] Basic execution counters (#15086)
- Loading branch information
1 parent
b77229c
commit f8c5a60
Showing
11 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "move-vm-metrics" | ||
description = "MoveVM metrics" | ||
version = "0.1.0" | ||
|
||
# Workspace inherited keys | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
publish = { workspace = true } | ||
repository = { workspace = true } | ||
rust-version = { workspace = true } | ||
|
||
[dependencies] | ||
once_cell = { workspace = true } | ||
prometheus = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) The Move Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use once_cell::sync::Lazy; | ||
use prometheus::{register_histogram_vec, HistogramTimer, HistogramVec}; | ||
|
||
/// Helper trait to encapsulate [HistogramVec] functionality. Users can use this trait to time | ||
/// different VM parts collecting metrics for different labels. Use wisely as timers do introduce | ||
/// an overhead, so using on a hot path is not recommended. | ||
pub trait Timer { | ||
/// Returns a new timer for the specified label. | ||
fn timer_with_label(&self, label: &str) -> HistogramTimer; | ||
} | ||
|
||
impl Timer for HistogramVec { | ||
fn timer_with_label(&self, label: &str) -> HistogramTimer { | ||
self.with_label_values(&[label]).start_timer() | ||
} | ||
} | ||
|
||
/// Timer that can be used to instrument the VM to collect metrics for different parts of the code. | ||
/// To access and view the metrics, set up where to send them, e.g., `PUSH_METRICS_NAMESPACE` and | ||
/// `PUSH_METRICS_ENDPOINT`. Then, metrics can be seen on Grafana dashboard, for instance. | ||
/// | ||
/// Note: the timer uses "exponential" buckets with a factor of 2. | ||
pub static VM_TIMER: Lazy<HistogramVec> = Lazy::new(|| { | ||
let factor = 2.0; | ||
let num_buckets = 32; | ||
|
||
let mut next = 1e-9; | ||
let mut buckets = Vec::with_capacity(num_buckets); | ||
for _ in 0..num_buckets { | ||
buckets.push(next); | ||
next *= factor; | ||
} | ||
|
||
register_histogram_vec!( | ||
// Metric name: | ||
"vm_timer_seconds", | ||
// Metric description: | ||
"VM timers", | ||
&["name"], | ||
buckets, | ||
) | ||
.expect("Registering the histogram should always succeed") | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters