Skip to content

Commit

Permalink
ci: Make clippy happy in all targets (#144)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Jun 27, 2022
1 parent 1b19478 commit 6b64aea
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ jobs:
uses: actions-rs/[email protected]
with:
command: clippy
args: --features flamegraph,prost-codec -- -D warnings
args: --all-targets --features flamegraph,prost-codec -- -D warnings

- name: Run cargo clippy protobuf
uses: actions-rs/[email protected]
with:
command: clippy
args: --features flamegraph,protobuf-codec -- -D warnings
args: --all-targets --features flamegraph,protobuf-codec -- -D warnings

build:
name: Build
Expand Down
12 changes: 4 additions & 8 deletions examples/backtrace_while_sampling.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.

use pprof;
use std::fs::File;

fn deep_recursive(depth: i32) {
Expand All @@ -22,13 +21,10 @@ fn main() {
deep_recursive(20);
}

match guard.report().build() {
Ok(report) => {
let file = File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();
if let Ok(report) = guard.report().build() {
let file = File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();

println!("report: {:?}", &report);
}
Err(_) => {}
println!("report: {:?}", &report);
};
}
22 changes: 8 additions & 14 deletions examples/flamegraph.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use pprof;
use std::fs::File;

#[inline(never)]
Expand Down Expand Up @@ -67,8 +66,8 @@ fn prepare_prime_numbers() -> Vec<usize> {
}
}
let mut prime_numbers = vec![];
for i in 2..10000 {
if prime_number_table[i] {
for (i, exist) in prime_number_table.iter().enumerate().skip(2) {
if *exist {
prime_numbers.push(i);
}
}
Expand All @@ -91,22 +90,17 @@ fn main() {
if is_prime_number2(i, &prime_numbers) {
v += 1;
}
} else {
if is_prime_number3(i, &prime_numbers) {
v += 1;
}
} else if is_prime_number3(i, &prime_numbers) {
v += 1;
}
}

println!("Prime numbers: {}", v);

match guard.report().build() {
Ok(report) => {
let file = File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();
if let Ok(report) = guard.report().build() {
let file = File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();

println!("report: {:?}", &report);
}
Err(_) => {}
println!("report: {:?}", &report);
};
}
5 changes: 2 additions & 3 deletions examples/malloc_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

extern crate libc;

use pprof;
use std::ffi::c_void;

#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
Expand Down Expand Up @@ -78,8 +77,8 @@ fn prepare_prime_numbers() -> Vec<usize> {
}
}
let mut prime_numbers = vec![];
for i in 2..10000 {
if prime_number_table[i] {
for (i, exist) in prime_number_table.iter().enumerate().skip(2) {
if *exist {
prime_numbers.push(i);
}
}
Expand Down
14 changes: 5 additions & 9 deletions examples/multithread.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use pprof;
use std::sync::Arc;

#[inline(never)]
Expand Down Expand Up @@ -35,8 +34,8 @@ fn prepare_prime_numbers() -> Vec<usize> {
}
}
let mut prime_numbers = vec![];
for i in 2..10000 {
if prime_number_table[i] {
for (i, exist) in prime_number_table.iter().enumerate().skip(2) {
if *exist {
prime_numbers.push(i);
}
}
Expand Down Expand Up @@ -76,7 +75,7 @@ fn main() {
})
.unwrap();

let p3 = prime_numbers.clone();
let p3 = prime_numbers;
std::thread::spawn(move || loop {
let mut _v = 0;

Expand All @@ -88,11 +87,8 @@ fn main() {
});

loop {
match guard.report().build() {
Ok(report) => {
println!("{:?}", report);
}
Err(_) => {}
if let Ok(report) = guard.report().build() {
println!("{:?}", report);
};
std::thread::sleep(std::time::Duration::from_secs(1))
}
Expand Down
18 changes: 7 additions & 11 deletions examples/multithread_flamegraph.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use pprof;
use std::fs::File;
use std::sync::Arc;

Expand Down Expand Up @@ -36,8 +35,8 @@ fn prepare_prime_numbers() -> Vec<usize> {
}
}
let mut prime_numbers = vec![];
for i in 2..10000 {
if prime_number_table[i] {
for (i, exist) in prime_number_table.iter().enumerate().skip(2) {
if *exist {
prime_numbers.push(i);
}
}
Expand Down Expand Up @@ -78,7 +77,7 @@ fn main() {
})
.unwrap();

let p3 = prime_numbers.clone();
let p3 = prime_numbers;
std::thread::spawn(move || loop {
let mut _v = 0;

Expand All @@ -90,14 +89,11 @@ fn main() {
});

std::thread::sleep(std::time::Duration::from_secs(5));
match guard.report().build() {
Ok(report) => {
let file = File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();
if let Ok(report) = guard.report().build() {
let file = File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();

println!("{:?}", report);
}
Err(_) => {}
println!("{:?}", report);
};

// pprof::PROFILER.lock().unwrap().stop();
Expand Down
14 changes: 5 additions & 9 deletions examples/post_processor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use pprof;
use std::sync::Arc;

#[inline(never)]
Expand Down Expand Up @@ -35,8 +34,8 @@ fn prepare_prime_numbers() -> Vec<usize> {
}
}
let mut prime_numbers = vec![];
for i in 2..10000 {
if prime_number_table[i] {
for (i, exist) in prime_number_table.iter().enumerate().skip(2) {
if *exist {
prime_numbers.push(i);
}
}
Expand Down Expand Up @@ -77,7 +76,7 @@ fn main() {
})
.unwrap();

let p3 = prime_numbers.clone();
let p3 = prime_numbers;
std::thread::spawn(move || loop {
let mut _v = 0;

Expand All @@ -89,17 +88,14 @@ fn main() {
});

loop {
match guard
if let Ok(report) = guard
.report()
.frames_post_processor(|frames| {
frames.thread_name = "PROCESSED".to_string();
})
.build()
{
Ok(report) => {
println!("{:?}", report);
}
Err(_) => {}
println!("{:?}", report);
};
std::thread::sleep(std::time::Duration::from_secs(1))
}
Expand Down
13 changes: 4 additions & 9 deletions examples/prime_number.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use pprof;

#[inline(never)]
fn is_prime_number(v: usize, prime_numbers: &[usize]) -> bool {
if v < 10000 {
Expand Down Expand Up @@ -34,8 +32,8 @@ fn prepare_prime_numbers() -> Vec<usize> {
}
}
let mut prime_numbers = vec![];
for i in 2..10000 {
if prime_number_table[i] {
for (i, exist) in prime_number_table.iter().enumerate().skip(2) {
if *exist {
prime_numbers.push(i);
}
}
Expand All @@ -58,11 +56,8 @@ fn main() {

println!("Prime numbers: {}", v);

match guard.report().build() {
Ok(report) => {
println!("{:?}", report);
}
Err(_) => {}
if let Ok(report) = guard.report().build() {
println!("{:?}", report);
};
}
}
34 changes: 14 additions & 20 deletions examples/profile_proto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use pprof;
use pprof::protos::Message;
use std::fs::File;
use std::io::Write;
Expand Down Expand Up @@ -69,8 +68,8 @@ fn prepare_prime_numbers() -> Vec<usize> {
}
}
let mut prime_numbers = vec![];
for i in 2..10000 {
if prime_number_table[i] {
for (i, exist) in prime_number_table.iter().enumerate().skip(2) {
if *exist {
prime_numbers.push(i);
}
}
Expand All @@ -93,29 +92,24 @@ fn main() {
if is_prime_number2(i, &prime_numbers) {
v += 1;
}
} else {
if is_prime_number3(i, &prime_numbers) {
v += 1;
}
} else if is_prime_number3(i, &prime_numbers) {
v += 1;
}
}

println!("Prime numbers: {}", v);

match guard.report().build() {
Ok(report) => {
let mut file = File::create("profile.pb").unwrap();
let profile = report.pprof().unwrap();
if let Ok(report) = guard.report().build() {
let mut file = File::create("profile.pb").unwrap();
let profile = report.pprof().unwrap();

let mut content = Vec::new();
#[cfg(not(feature = "protobuf-codec"))]
profile.encode(&mut content).unwrap();
#[cfg(feature = "protobuf-codec")]
profile.write_to_vec(&mut content).unwrap();
file.write_all(&content).unwrap();
let mut content = Vec::new();
#[cfg(not(feature = "protobuf-codec"))]
profile.encode(&mut content).unwrap();
#[cfg(feature = "protobuf-codec")]
profile.write_to_vec(&mut content).unwrap();
file.write_all(&content).unwrap();

println!("report: {:?}", report);
}
Err(_) => {}
println!("report: {:?}", report);
};
}
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
edition = "2021"
reorder_imports = true
8 changes: 4 additions & 4 deletions src/addr_validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ mod test {
fn validate_stack() {
let i = 0;

assert_eq!(validate(&i as *const _ as *const libc::c_void), true);
assert!(validate(&i as *const _ as *const libc::c_void));
}

#[test]
fn validate_heap() {
let vec = vec![0; 1000];

for i in vec.iter() {
assert_eq!(validate(i as *const _ as *const libc::c_void), true);
assert!(validate(i as *const _ as *const libc::c_void));
}
}

#[test]
fn failed_validate() {
assert_eq!(validate(0 as *const libc::c_void), false);
assert_eq!(validate((-1 as i32) as usize as *const libc::c_void), false)
assert!(!validate(std::ptr::null::<libc::c_void>()));
assert!(!validate(-1_i32 as usize as *const libc::c_void))
}
}

0 comments on commit 6b64aea

Please sign in to comment.