Skip to content

Commit

Permalink
Replace stopwatch with a builtin implementation to avoid extra depend…
Browse files Browse the repository at this point in the history
…encies

stopwatch crate has too much dependencies:

    $ cargo tree
    ...
    ├── stopwatch v0.0.7
    │   └── num v0.1.42
    │       ├── num-bigint v0.1.44
    │       │   ├── num-integer v0.1.46 (*)
    │       │   ├── num-traits v0.2.18 (*)
    │       │   ├── rand v0.4.6
    │       │   │   └── libc v0.2.153
    │       │   └── rustc-serialize v0.3.25
    │       ├── num-complex v0.1.43
    │       │   ├── num-traits v0.2.18 (*)
    │       │   └── rustc-serialize v0.3.25
    │       ├── num-integer v0.1.46 (*)
    │       ├── num-iter v0.1.44 (*)
    │       ├── num-rational v0.1.42
    │       │   ├── num-bigint v0.1.44 (*)
    │       │   ├── num-integer v0.1.46 (*)
    │       │   ├── num-traits v0.2.18 (*)
    │       │   └── rustc-serialize v0.3.25
    │       └── num-traits v0.2.18 (*)
    ...

And one of them after upgrading rust toolchain fail to compiles:

    Checking num-bigint v0.1.44
error[E0658]: use of unstable library feature 'libstd_sys_internals': used by the panic! macro
  --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/num-bigint-0.1.44/src/bigint.rs:41:64
   |
41 | #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
   |                                                                ^^^^^^^^^^^^^^
   |
   = help: add `#![feature(libstd_sys_internals)]` to the crate attributes to enable
   = note: this compiler was built on 2024-03-27; consider upgrading it if it is out of date
   = note: this error originates in the derive macro `RustcDecodable` (in Nightly builds, run with -Z macro-backtrace for more info)

So let's write our own implementation.
  • Loading branch information
azat committed Mar 30, 2024
1 parent d1a1f66 commit 9c15a0a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 114 deletions.
117 changes: 5 additions & 112 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ flexi_logger = { version = "0.27", default-features = false }
log = { version = "0.4", default-features = false }
futures-util = { version = "*", default-features = false }
semver = { version = "*", default-features = false }
stopwatch = { version = "*", default-features = false }
serde = { version = "*", features = ["derive"] }
serde_yaml = { version = "*", default-features = false }
quick-xml = { version = "*", features = ["serialize"] }
Expand Down
3 changes: 3 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod stopwatch;

pub use stopwatch::Stopwatch;
22 changes: 22 additions & 0 deletions src/common/stopwatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// Stupid and simple implementation of stopwatch.
use std::time::{Duration, Instant};

pub struct Stopwatch {
start_time: Instant,
}

impl Stopwatch {
pub fn start_new() -> Stopwatch {
Stopwatch {
start_time: Instant::now(),
}
}

pub fn elapsed_ms(&self) -> u64 {
return self.elapsed().as_millis() as u64;
}

pub fn elapsed(&self) -> Duration {
return self.start_time.elapsed();
}
}
2 changes: 1 addition & 1 deletion src/interpreter/worker.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
common::Stopwatch,
interpreter::clickhouse::{Columns, TraceType},
interpreter::{flamegraph, ContextArc},
view::{self, Navigation},
Expand All @@ -14,7 +15,6 @@ use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
use stopwatch::Stopwatch;

#[derive(Debug, Clone)]
pub enum Event {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use backtrace::Backtrace;
use flexi_logger::{LogSpecification, Logger};
use std::panic::{self, PanicInfo};

mod common;
mod interpreter;
mod view;

Expand Down

0 comments on commit 9c15a0a

Please sign in to comment.