diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 084d0ee..49e5c66 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -10,14 +10,16 @@ jobs: toolchain: stable components: clippy - name: Cargo Clippy Check - uses: actions-rs/clippy@master + uses: actions-rs/clippy-check@v1 with: + token: ${{ secrets.GITHUB_TOKEN }} args: --all-features --all-targets -- -D warnings fmt: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Cargo Fmt Check - uses: icepuma/rust-action@master + uses: actions-rs/cargo@v1 with: - args: cargo fmt --all -- --check + command: fmt + args: --all -- --check diff --git a/timed/src/hop.rs b/timed/src/hop.rs index 1acfb7a..1cdae99 100644 --- a/timed/src/hop.rs +++ b/timed/src/hop.rs @@ -31,9 +31,7 @@ impl Hop { pub fn to_chrome_trace(&self) -> String { format!( "{{ \"pid\": 0, \"ts\": {}, \"ph\": \"{}\", \"name\": \"{}\" }}", - self.timestamp, - self.phase.to_string(), - self.function_name + self.timestamp, self.phase, self.function_name ) } } diff --git a/timed/src/statistics.rs b/timed/src/statistics.rs index e35d5ad..41c04c6 100644 --- a/timed/src/statistics.rs +++ b/timed/src/statistics.rs @@ -22,15 +22,10 @@ impl StatisticsRecord { } } - pub fn nth_percentile_time(&self, percentile: f32) -> Option<&Duration> { - let mut calls = self.calls.clone(); - calls.sort(); - - let mut i = (percentile * self.calls.len() as f32).round() as usize; - if i > 0 { - i -= 1; - } + pub fn nth_percentile_time(&mut self, percentile: f32) -> Option<&Duration> { + self.calls.sort_by_cached_key(|a| a.as_nanos()); + let i = ((percentile * self.calls.len() as f32).round() - 1.).max(0.) as usize; self.calls.get(i) } @@ -50,7 +45,7 @@ impl Ord for StatisticsRecord { impl PartialOrd for StatisticsRecord { fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(&other)) + Some(self.cmp(other)) } } @@ -94,7 +89,7 @@ pub fn from(hops: &[Hop]) -> String { stats.sort_by(|a, b| b.overall_time.cmp(&a.overall_time)); - stats.iter().for_each(|sr| { + stats.iter_mut().for_each(|sr| { table.add_row(row![ sr.name, sr.calls.len(), diff --git a/timed_proc_macros/src/lib.rs b/timed_proc_macros/src/lib.rs index ab60b84..da83484 100644 --- a/timed_proc_macros/src/lib.rs +++ b/timed_proc_macros/src/lib.rs @@ -9,9 +9,9 @@ use syn::{AttributeArgs, ItemFn}; #[derive(Debug, FromMeta)] struct TracingArgs { #[darling(default)] - enabled: Option, + _enabled: Option, #[darling(default)] - main: Option, + _main: Option, } #[derive(Debug, FromMeta)] @@ -96,7 +96,7 @@ fn codegen_duration(options: &MacroArgs, function_name: &str) -> (Code, Code) { Some(options) => &options.printer, None => &None, }; - let printer = codegen_printer(&printer_options); + let printer = codegen_printer(printer_options); // Decide if we generate duration at all let disabled = match options.duration {