Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions timed/src/hop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
15 changes: 5 additions & 10 deletions timed/src/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@ impl StatisticsRecord {
}
}

pub fn nth_percentile_time(&self, percentile: f32) -> Option<&Duration> {
let mut calls = self.calls.clone();
calls.sort();
Comment on lines -26 to -27
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem was that I cloned the calls vec, sorted it, and then called self.calls.get(i) instead of just calls.get(i) (on the cloned vec).

I decided to fix it by removing the call for clone, changing the signature to receive a mutable reference to self and sort the calls vec in place (on self).
This way its more readable, less error prune and less memcps.
Wdyt?


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)
}

Expand All @@ -50,7 +45,7 @@ impl Ord for StatisticsRecord {

impl PartialOrd for StatisticsRecord {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(&other))
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions timed_proc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use syn::{AttributeArgs, ItemFn};
#[derive(Debug, FromMeta)]
struct TracingArgs {
#[darling(default)]
enabled: Option<bool>,
_enabled: Option<bool>,
#[darling(default)]
main: Option<String>,
_main: Option<String>,
Comment on lines -12 to +14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 fields are never read according to clippy, I didn't want to delete them because it'll be a breaking change. Wdyt?

}

#[derive(Debug, FromMeta)]
Expand Down Expand Up @@ -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 {
Expand Down