-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: impl custom timer to track latency. add metrics for bundler pro… (
#910)
- Loading branch information
Showing
6 changed files
with
77 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// This file is part of Rundler. | ||
// | ||
// Rundler is free software: you can redistribute it and/or modify it under the | ||
// terms of the GNU Lesser General Public License as published by the Free Software | ||
// Foundation, either version 3 of the License, or (at your option) any later version. | ||
// | ||
// Rundler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with Rundler. | ||
// If not, see https://www.gnu.org/licenses/. | ||
|
||
//! Utilities for track scoped method timer. | ||
use std::time::Instant; | ||
|
||
use metrics::Histogram; | ||
|
||
/// A customized guard to measure duration and record to metric. | ||
/// | ||
/// exmaple usage: | ||
/// ``` | ||
/// fn bala() { | ||
/// let _timer = CustomTimerGuard::new(metric); | ||
/// ... | ||
/// } // _timer will automatically dropped and record the duration. | ||
/// ``` | ||
pub struct CustomTimerGuard { | ||
timer: Instant, | ||
metric: Histogram, | ||
} | ||
|
||
impl CustomTimerGuard { | ||
/// initialzie instance. | ||
pub fn new(metric: Histogram) -> Self { | ||
Self { | ||
timer: Instant::now(), | ||
metric, | ||
} | ||
} | ||
} | ||
|
||
impl Drop for CustomTimerGuard { | ||
fn drop(&mut self) { | ||
self.metric.record(self.timer.elapsed().as_millis() as f64); | ||
} | ||
} |
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