@@ -20,19 +20,52 @@ impl MetricsHandler {
2020
2121 /// Starts tracking a new block building task.
2222 pub ( crate ) fn start_block_building_recording ( & mut self ) {
23- if self . block_building_meter . start . is_some ( ) {
23+ if self . block_building_meter . block_building_start . is_some ( ) {
2424 tracing:: warn!( target: "scroll::chain_orchestrator" , "block building recording is already ongoing, overwriting" ) ;
2525 }
26- self . block_building_meter . start = Some ( Instant :: now ( ) ) ;
26+ self . block_building_meter . block_building_start = Some ( Instant :: now ( ) ) ;
2727 }
2828
2929 /// The duration of the current block building task if any.
30- pub ( crate ) fn finish_block_building_recording ( & mut self ) {
31- let duration = self . block_building_meter . start . take ( ) . map ( |start| start. elapsed ( ) ) ;
30+ pub ( crate ) fn finish_no_empty_block_building_recording ( & mut self ) {
31+ let duration = self
32+ . block_building_meter
33+ . block_building_start
34+ . take ( )
35+ . map ( |block_building_start| block_building_start. elapsed ( ) ) ;
3236 if let Some ( duration) = duration {
3337 self . block_building_meter . metric . block_building_duration . record ( duration. as_secs_f64 ( ) ) ;
3438 }
3539 }
40+
41+ pub ( crate ) fn finish_all_block_building_recording ( & mut self ) {
42+ let duration = self
43+ . block_building_meter
44+ . block_building_start
45+ . take ( )
46+ . map ( |block_building_start| block_building_start. elapsed ( ) ) ;
47+ if let Some ( duration) = duration {
48+ self . block_building_meter
49+ . metric
50+ . all_block_building_duration
51+ . record ( duration. as_secs_f64 ( ) ) ;
52+ }
53+ }
54+
55+ pub ( crate ) fn finish_block_building_interval_recording ( & mut self ) {
56+ let interval = self
57+ . block_building_meter
58+ . last_block_building_time
59+ . take ( )
60+ . map ( |last_block_building_time| last_block_building_time. elapsed ( ) ) ;
61+ if let Some ( interval) = interval {
62+ self . block_building_meter
63+ . metric
64+ . consecutive_block_interval
65+ . record ( interval. as_secs_f64 ( ) ) ;
66+ }
67+ self . block_building_meter . last_block_building_time = Some ( Instant :: now ( ) ) ;
68+ }
3669}
3770
3871impl Default for MetricsHandler {
@@ -104,13 +137,18 @@ pub(crate) struct ChainOrchestratorMetrics {
104137#[ derive( Debug , Default ) ]
105138pub ( crate ) struct BlockBuildingMeter {
106139 metric : BlockBuildingMetric ,
107- start : Option < Instant > ,
140+ block_building_start : Option < Instant > ,
141+ last_block_building_time : Option < Instant > ,
108142}
109143
110144/// Block building related metric.
111145#[ derive( Metrics , Clone ) ]
112146#[ metrics( scope = "chain_orchestrator" ) ]
113147pub ( crate ) struct BlockBuildingMetric {
114- /// The duration of the block building task.
148+ /// The duration of the block building task without empty block
115149 block_building_duration : Histogram ,
150+ /// The duration of the block building task for all blocks include empty block
151+ all_block_building_duration : Histogram ,
152+ /// The duration of the block interval include empty block
153+ consecutive_block_interval : Histogram ,
116154}
0 commit comments