Skip to content

Commit

Permalink
add stopwatch (#3970)
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas authored and neysofu committed Sep 26, 2022
1 parent a538b9e commit 56db982
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions core/src/subgraph/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ impl<S: SubgraphStore> SubgraphInstanceManager<S> {
let subgraph_metrics = Arc::new(SubgraphInstanceMetrics::new(
registry.cheap_clone(),
deployment.hash.as_str(),
stopwatch_metrics.clone(),
));
let subgraph_metrics_unregister = subgraph_metrics.clone();
let host_metrics = Arc::new(HostMetrics::new(
Expand Down
20 changes: 12 additions & 8 deletions core/src/subgraph/trigger_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ where

let mut host_mapping: Vec<(&T::Host, TriggerWithHandler<MappingTrigger<C>>)> = vec![];

for host in hosts {
let mapping_trigger = match host.match_and_decode(trigger, block, logger)? {
// Trigger matches and was decoded as a mapping trigger.
Some(mapping_trigger) => mapping_trigger,
{
let _section = subgraph_metrics.stopwatch.start_section("match_and_decode");

// Trigger does not match, do not process it.
None => continue,
};
for host in hosts {
let mapping_trigger = match host.match_and_decode(trigger, block, logger)? {
// Trigger matches and was decoded as a mapping trigger.
Some(mapping_trigger) => mapping_trigger,

host_mapping.push((&host, mapping_trigger));
// Trigger does not match, do not process it.
None => continue,
};

host_mapping.push((&host, mapping_trigger));
}
}

if host_mapping.is_empty() {
Expand Down
10 changes: 9 additions & 1 deletion graph/src/components/metrics/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ use crate::prelude::{Gauge, Histogram, HostMetrics, MetricsRegistry};
use std::collections::HashMap;
use std::sync::Arc;

use super::stopwatch::StopwatchMetrics;

pub struct SubgraphInstanceMetrics {
pub block_trigger_count: Box<Histogram>,
pub block_processing_duration: Box<Histogram>,
pub block_ops_transaction_duration: Box<Histogram>,

pub stopwatch: StopwatchMetrics,
trigger_processing_duration: Box<Histogram>,
}

impl SubgraphInstanceMetrics {
pub fn new(registry: Arc<dyn MetricsRegistry>, subgraph_hash: &str) -> Self {
pub fn new(
registry: Arc<dyn MetricsRegistry>,
subgraph_hash: &str,
stopwatch: StopwatchMetrics,
) -> Self {
let block_trigger_count = registry
.new_deployment_histogram(
"deployment_block_trigger_count",
Expand Down Expand Up @@ -51,6 +58,7 @@ impl SubgraphInstanceMetrics {
block_processing_duration,
trigger_processing_duration,
block_ops_transaction_duration,
stopwatch,
}
}

Expand Down

0 comments on commit 56db982

Please sign in to comment.