Dataset Viewer
Auto-converted to Parquet Duplicate
created_at
stringclasses
8 values
test_patch
stringclasses
8 values
issue_numbers
sequencelengths
1
1
instance_id
stringclasses
8 values
repo
stringclasses
1 value
patch
stringclasses
8 values
base_commit
stringclasses
8 values
problem_statement
stringclasses
8 values
version
stringclasses
6 values
pull_number
int64
245
1.16k
hints_text
stringclasses
8 values
environment_setup_commit
stringclasses
6 values
FAIL_TO_PASS
sequencelengths
1
1
PASS_TO_PASS
sequencelengths
8
234
FAIL_TO_FAIL
sequencelengths
0
0
PASS_TO_FAIL
sequencelengths
0
0
2020-10-02T14:52:22Z
diff --git a/tests/process.rs b/tests/process.rs --- a/tests/process.rs +++ b/tests/process.rs @@ -104,3 +104,25 @@ fn test_process_disk_usage() { p.disk_usage().written_bytes ); } + +#[test] +fn cpu_usage_is_not_nan() { + let mut system = sysinfo::System::new(); + system.refresh_processes(); + + let first_pids = system.get_processes() + .iter() + .take(10) + .map(|(&pid, _)| pid) + .collect::<Vec<_>>(); + let mut checked = 0; + + first_pids.into_iter().for_each(|pid| { + system.refresh_process(pid); + if let Some(p) = system.get_process(pid) { + assert!(!p.cpu_usage().is_nan()); + checked += 1; + } + }); + assert!(checked > 0); +}
[ "366" ]
GuillaumeGomez__sysinfo-367
GuillaumeGomez/sysinfo
diff --git a/Cargo.toml b/Cargo.toml --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sysinfo" -version = "0.15.2" +version = "0.15.3" authors = ["Guillaume Gomez <guillaume1.gomez@gmail.com>"] description = "Library to get system information such as processes, processors, disks, components and networks" diff --git a/src/linux/system.rs b/src/linux/system.rs --- a/src/linux/system.rs +++ b/src/linux/system.rs @@ -377,7 +377,7 @@ impl SystemExt for System { if found && !self.processors.is_empty() { self.refresh_processors(Some(1)); let (new, old) = get_raw_times(&self.global_processor); - let total_time = (if old > new { 1 } else { new - old }) as f32; + let total_time = (if old >= new { 1 } else { new - old }) as f32; if let Some(p) = self.process_list.tasks.get_mut(&pid) { compute_cpu_usage(p, self.processors.len() as u64, total_time); diff --git a/src/windows/process.rs b/src/windows/process.rs --- a/src/windows/process.rs +++ b/src/windows/process.rs @@ -739,9 +739,10 @@ pub(crate) fn compute_cpu_usage(p: &mut Process, nb_processors: u64, now: ULARGE &mut fuser as *mut FILETIME as *mut c_void, size_of::<FILETIME>(), ); + let old = check_sub(*now.QuadPart(), p.old_cpu); p.cpu_usage = (check_sub(*sys.QuadPart(), p.old_sys_cpu) as f32 + check_sub(*user.QuadPart(), p.old_user_cpu) as f32) - / check_sub(*now.QuadPart(), p.old_cpu) as f32 + / if old == 0 { 1 } else { old } as f32 / nb_processors as f32 * 100.; p.old_cpu = *now.QuadPart();
f57031a38b0d527958a58605682c52e262f3f017
Process cpu_usage() returns NaN in some cases Hello, I'm using `sysinfo` on version `0.15.2` on Linux mint 19. `cargo -V` outputs `cargo 1.46.0 (149022b1d 2020-07-17)`. `rustc -V` outputs `rustc 1.46.0 (04488afe3 2020-08-24)`. When `system.refresh_process(pid)` is called too often, the cpu_usage() of this process becomes NaN (or sometimes inf). I have tried to understand where is this comes from, and I think that the bug is in `system.rs`, in the function `refresh_process` (line 380): ``` let total_time = (if old > new { 1 } else { new - old }) as f32; ``` If by any chance `new == old`, then `total_time` would be zero. `total_time` is then sent as an argument to `compute_cpu_usage`, which uses it in the denominator. The code to reproduce: ``` fn main() { let mut system: System = System::new(); system.refresh_processes(); let first_5_pids: Vec<Pid> = system.get_processes() .iter() .take(5) .map(|(pid, _)| *pid as Pid) .collect::<Vec<Pid>>(); first_5_pids.iter().for_each(|pid| { system.refresh_process(*pid as Pid); let proc = system.get_process(*pid as Pid).unwrap(); println!("pid: {}, cpu: {}", proc.pid(), proc.cpu_usage()); }); } ``` the output is as follows: ``` pid: 673, cpu: 0 pid: 1736, cpu: NaN pid: 58, cpu: NaN pid: 684, cpu: NaN pid: 52, cpu: NaN ```
0.15
367
This is indeed where the bug is coming from. However, I'm not too aware on how to compare floats and check if they're equal. If you have any directions, it'd be awesome! (You can also send a PR if you want to go faster :wink: ). I appreciate the quick reply :) there are some crates that handle this, like [float_cmp](https://docs.rs/float-cmp/0.8.0/float_cmp/). Alternatively, you can use `round()` or something like that. I don't know if I will have the time to send a PR though. Best regards I'd rather not add a dependency for such a specific case. I can always add a precision level to perform the comparison though. I think the best practice is to `abs` the 2 floats, `abs` the difference and check if its smaller than `std::f64:: EPSILON` for example
8c2b5a0583404120f1a910d9af32f40fd1dd9d08
[ "cpu_usage_is_not_nan" ]
[ "system::tests::test_refresh_system", "system::tests::check_if_send_and_sync", "test::check_memory_usage", "system::tests::test_get_process", "system::tests::test_refresh_process", "test::check_users", "test_disks", "test_processor", "test_process_refresh", "test_get_cmd_line", "test_process", "test_process_disk_usage", "test_send_sync", "test_uptime", "src/common.rs - common::DiskType (line 242) - compile", "src/common.rs - common::DiskUsage (line 389) - compile", "src/common.rs - common::LoadAvg (line 336) - compile", "src/common.rs - common::NetworksIter (line 205) - compile", "src/common.rs - common::RefreshKind::users_list (line 200)", "src/common.rs - common::RefreshKind::with_networks (line 187)", "src/common.rs - common::RefreshKind::without_cpu (line 193)", "src/common.rs - common::RefreshKind::without_disks_list (line 191)", "src/common.rs - common::RefreshKind::with_components_list (line 195)", "src/common.rs - common::RefreshKind::networks (line 187)", "src/common.rs - common::RefreshKind::with_disks_list (line 191)", "src/common.rs - common::RefreshKind::without_components (line 194)", "src/common.rs - common::RefreshKind::with_networks_list (line 188)", "src/common.rs - common::RefreshKind::disks_list (line 191)", "src/common.rs - common::RefreshKind::cpu (line 193)", "src/common.rs - common::RefreshKind::everything (line 154)", "src/common.rs - common::RefreshKind::components_list (line 195)", "src/linux/network.rs - linux::network::Networks (line 18) - compile", "src/common.rs - common::User (line 363) - compile", "src/common.rs - common::RefreshKind::new (line 132)", "src/common.rs - common::RefreshKind::with_cpu (line 193)", "src/common.rs - common::RefreshKind::with_processes (line 189)", "src/common.rs - common::RefreshKind::memory (line 192)", "src/common.rs - common::RefreshKind::without_memory (line 192)", "src/common.rs - common::RefreshKind::components (line 194)", "src/common.rs - common::RefreshKind::without_processes (line 189)", "src/common.rs - common::RefreshKind::disks (line 190)", "src/common.rs - common::RefreshKind::with_disks (line 190)", "src/common.rs - common::RefreshKind::without_components_list (line 195)", "src/common.rs - common::RefreshKind::without_networks (line 187)", "src/sysinfo.rs - set_open_files_limit (line 143) - compile", "src/traits.rs - traits::ComponentExt::refresh (line 1188) - compile", "src/traits.rs - traits::ComponentExt::get_label (line 1176) - compile", "src/traits.rs - traits::ComponentExt::get_max (line 1152) - compile", "src/traits.rs - traits::ComponentExt::get_temperature (line 1140) - compile", "src/common.rs - common::RefreshKind::without_networks_list (line 188)", "src/traits.rs - traits::DiskExt (line 24) - compile", "src/traits.rs - traits::ComponentExt::get_critical (line 1164) - compile", "src/traits.rs - traits::DiskExt::get_total_space (line 83) - compile", "src/traits.rs - traits::DiskExt::get_file_system (line 59) - compile", "src/traits.rs - traits::DiskExt::get_mount_point (line 71) - compile", "src/traits.rs - traits::NetworkExt::get_packets_received (line 995) - compile", "src/traits.rs - traits::DiskExt::get_name (line 47) - compile", "src/traits.rs - traits::DiskExt::get_available_space (line 95) - compile", "src/common.rs - common::RefreshKind::without_disks (line 190)", "src/traits.rs - traits::NetworkExt::get_errors_on_received (line 1047) - compile", "src/traits.rs - traits::DiskExt::get_type (line 35) - compile", "src/traits.rs - traits::DiskExt::refresh (line 107) - compile", "src/traits.rs - traits::NetworkExt::get_errors_on_transmitted (line 1073) - compile", "src/traits.rs - traits::NetworkExt::get_received (line 943) - compile", "src/traits.rs - traits::NetworkExt::get_total_received (line 956) - compile", "src/traits.rs - traits::NetworkExt::get_total_errors_on_received (line 1060) - compile", "src/traits.rs - traits::NetworkExt::get_total_transmitted (line 982) - compile", "src/traits.rs - traits::NetworkExt::get_total_packets_received (line 1008) - compile", "src/traits.rs - traits::NetworkExt::get_packets_transmitted (line 1021) - compile", "src/traits.rs - traits::ProcessExt::cmd (line 152) - compile", "src/traits.rs - traits::NetworksExt::refresh_networks_list (line 1115) - compile", "src/traits.rs - traits::NetworkExt::get_total_packets_transmitted (line 1034) - compile", "src/traits.rs - traits::NetworksExt::refresh (line 1126) - compile", "src/traits.rs - traits::NetworkExt::get_total_errors_on_transmitted (line 1086) - compile", "src/traits.rs - traits::NetworkExt::get_transmitted (line 969) - compile", "src/common.rs - common::RefreshKind::with_memory (line 192)", "src/traits.rs - traits::NetworksExt::iter (line 1102) - compile", "src/traits.rs - traits::ProcessExt::name (line 140) - compile", "src/traits.rs - traits::ProcessExt::disk_usage (line 304) - compile", "src/traits.rs - traits::ProcessExt::environ (line 190) - compile", "src/traits.rs - traits::ProcessExt::memory (line 230) - compile", "src/traits.rs - traits::ProcessExt::kill (line 128) - compile", "src/traits.rs - traits::ProcessExt::cpu_usage (line 290) - compile", "src/traits.rs - traits::ProcessExt::pid (line 176) - compile", "src/traits.rs - traits::ProcessExt::cwd (line 204) - compile", "src/traits.rs - traits::ProcessExt::exe (line 164) - compile", "src/traits.rs - traits::ProcessExt::parent (line 254) - compile", "src/traits.rs - traits::ProcessExt::root (line 218) - compile", "src/common.rs - common::RefreshKind::networks_list (line 188)", "src/common.rs - common::RefreshKind (line 104)", "src/common.rs - common::RefreshKind::processes (line 189)", "src/common.rs - common::RefreshKind::with_users_list (line 200)", "src/common.rs - common::RefreshKind::with_components (line 194)", "src/traits.rs - traits::ProcessorExt::get_name (line 342) - compile", "src/traits.rs - traits::ProcessorExt::get_frequency (line 378) - compile", "src/traits.rs - traits::ProcessExt::status (line 266) - compile", "src/traits.rs - traits::ProcessExt::virtual_memory (line 242) - compile", "src/traits.rs - traits::ProcessorExt::get_cpu_usage (line 330) - compile", "src/traits.rs - traits::ProcessorExt::get_brand (line 366) - compile", "src/traits.rs - traits::ProcessExt::start_time (line 278) - compile", "src/traits.rs - traits::SystemExt::get_boot_time (line 914) - compile", "src/traits.rs - traits::SystemExt::get_load_average (line 924) - compile", "src/traits.rs - traits::SystemExt::get_components_mut (line 832) - compile", "src/traits.rs - traits::SystemExt::get_global_processor_info (line 716) - compile", "src/traits.rs - traits::SystemExt::get_available_memory (line 770) - compile", "src/traits.rs - traits::SystemExt::get_components (line 820) - compile", "src/traits.rs - traits::SystemExt::get_disks_mut (line 868) - compile", "src/traits.rs - traits::SystemExt::get_networks (line 880) - compile", "src/traits.rs - traits::SystemExt::get_disks (line 844) - compile", "src/traits.rs - traits::ProcessorExt::get_vendor_id (line 354) - compile", "src/traits.rs - traits::SystemExt::get_networks_mut (line 893) - compile", "src/traits.rs - traits::SystemExt::get_process (line 684) - compile", "src/traits.rs - traits::SystemExt::get_free_swap (line 800) - compile", "src/traits.rs - traits::SystemExt::get_process_by_name (line 696) - compile", "src/traits.rs - traits::SystemExt::get_free_memory (line 754) - compile", "src/traits.rs - traits::SystemExt::get_processes (line 672) - compile", "src/traits.rs - traits::SystemExt::get_uptime (line 904) - compile", "src/traits.rs - traits::SystemExt::get_processors (line 726) - compile", "src/traits.rs - traits::SystemExt::get_total_memory (line 738) - compile", "src/traits.rs - traits::SystemExt::refresh_all (line 657) - compile", "src/traits.rs - traits::SystemExt::refresh_components (line 530) - compile", "src/traits.rs - traits::SystemExt::new_all (line 416) - compile", "src/traits.rs - traits::SystemExt::get_total_swap (line 790) - compile", "src/traits.rs - traits::SystemExt::get_users (line 856) - compile", "src/traits.rs - traits::SystemExt::get_used_memory (line 780) - compile", "src/traits.rs - traits::SystemExt::refresh_disks (line 575) - compile", "src/traits.rs - traits::SystemExt::new (line 401) - compile", "src/traits.rs - traits::SystemExt::get_used_swap (line 810) - compile", "src/traits.rs - traits::SystemExt::refresh_cpu (line 520) - compile", "src/traits.rs - traits::SystemExt::refresh_networks_list (line 632) - compile", "src/traits.rs - traits::SystemExt::refresh_networks_list (line 641) - compile", "src/traits.rs - traits::SystemExt::refresh_memory (line 510) - compile", "src/traits.rs - traits::SystemExt::refresh_components_list (line 544) - compile", "src/traits.rs - traits::SystemExt::refresh_networks (line 609) - compile", "src/sysinfo.rs - (line 215)", "src/traits.rs - traits::SystemExt::refresh_networks (line 618) - compile", "src/traits.rs - traits::SystemExt::refresh_system (line 496) - compile", "src/traits.rs - traits::SystemExt::refresh_disks_list (line 589) - compile", "src/traits.rs - traits::SystemExt::refresh_process (line 565) - compile", "src/traits.rs - traits::SystemExt::refresh_processes (line 554) - compile", "src/traits.rs - traits::SystemExt::refresh_users_list (line 599) - compile", "src/traits.rs - traits::UserExt (line 1203) - compile", "src/traits.rs - traits::UserExt::get_groups (line 1226) - compile", "src/traits.rs - traits::UserExt::get_name (line 1214) - compile", "src/utils.rs - utils::get_current_pid (line 67) - compile", "src/sysinfo.rs - (line 220)", "src/common.rs - common::RefreshKind::without_users_list (line 200)", "src/traits.rs - traits::SystemExt::new_with_specifics (line 430)", "src/sysinfo.rs - (line 117)", "src/traits.rs - traits::SystemExt::refresh_specifics (line 449)", "src/sysinfo.rs - (line 14)" ]
[]
[]
2020-01-26T22:19:43Z
"diff --git a/README.md b/README.md\n--- a/README.md\n+++ b/README.md\n@@ -15,7 +15,7 @@ Support the(...TRUNCATED)
[ "215" ]
GuillaumeGomez__sysinfo-245
GuillaumeGomez/sysinfo
"diff --git a/Cargo.toml b/Cargo.toml\n--- a/Cargo.toml\n+++ b/Cargo.toml\n@@ -16,17 +16,15 @@ build(...TRUNCATED)
4ae1791d21f84f911ca8a77e3ebc19996b7de808
"Feature Request: support retrieve CPU number and load info\nThanks for providing the awesome librar(...TRUNCATED)
0.10
245
"Ah indeed. I'll check if it's available as well on windows and OSX, otherwise I'll have a bit more (...TRUNCATED)
4ae1791d21f84f911ca8a77e3ebc19996b7de808
[ "system::tests::test_refresh_process" ]
["system::tests::test_refresh_system","system::tests::test_get_process","system::tests::check_if_sen(...TRUNCATED)
[]
[]
2022-01-17T17:26:04Z
"diff --git a/tests/process.rs b/tests/process.rs\n--- a/tests/process.rs\n+++ b/tests/process.rs\n@(...TRUNCATED)
[ "680" ]
GuillaumeGomez__sysinfo-681
GuillaumeGomez/sysinfo
"diff --git a/src/linux/process.rs b/src/linux/process.rs\n--- a/src/linux/process.rs\n+++ b/src/lin(...TRUNCATED)
c1a6c6f2c438d7cf4c947f555df3d6d408ef0fe4
"On Linux `ProcessExt::start_time()` does not return the time since the epoch as documented\nIt seem(...TRUNCATED)
0.22
681
"It's pretty bad in any case. Interested into sending a PR? Otherwise I'll try to fix it as soon as (...TRUNCATED)
c1a6c6f2c438d7cf4c947f555df3d6d408ef0fe4
[ "test_process_times" ]
["common::tests::check_display_impl_process_status","system::tests::check_hostname_has_no_nuls","lin(...TRUNCATED)
[]
[]
2022-01-14T22:08:03Z
"diff --git /dev/null b/tests/code_checkers/docs.rs\nnew file mode 100644\n--- /dev/null\n+++ b/test(...TRUNCATED)
[ "592" ]
GuillaumeGomez__sysinfo-679
GuillaumeGomez/sysinfo
"diff --git a/src/apple/macos/component.rs b/src/apple/macos/component.rs\n--- a/src/apple/macos/com(...TRUNCATED)
b1d66813b7a5f35832302e5ed3d4d85ab94e9464
"Add check to ensure that types are using common md files and not manual doc comments\nFor example `(...TRUNCATED)
0.22
679
c1a6c6f2c438d7cf4c947f555df3d6d408ef0fe4
[ "code_checkers::code_checks" ]
["common::tests::check_display_impl_process_status","system::tests::check_hostname_has_no_nuls","lin(...TRUNCATED)
[]
[]
2021-06-11T08:30:22Z
"diff --git a/src/system.rs b/src/system.rs\n--- a/src/system.rs\n+++ b/src/system.rs\n@@ -89,4 +89,(...TRUNCATED)
[ "508" ]
GuillaumeGomez__sysinfo-509
GuillaumeGomez/sysinfo
"diff --git a/src/linux/system.rs b/src/linux/system.rs\n--- a/src/linux/system.rs\n+++ b/src/linux/(...TRUNCATED)
5c69175f028a5608093d31597b93031d165774c5
"Uptime: To cache, or not to cache?\nI've been looking into FreeBSD support this week (#433), and wh(...TRUNCATED)
0.18
509
"Linux should be updated to look like the others. Gonna send a PR which will also enforce this behav(...TRUNCATED)
3aa83dc410ebe2f6d5063a095104ea6c6394507f
[ "system::tests::check_uptime" ]
["linux::network::test::refresh_networks_list_add_interface","linux::system::test::lsb_release_fallb(...TRUNCATED)
[]
[]
2023-11-29T15:55:10Z
"diff --git a/tests/process.rs b/tests/process.rs\n--- a/tests/process.rs\n+++ b/tests/process.rs\n@(...TRUNCATED)
[ "1141" ]
GuillaumeGomez__sysinfo-1161
GuillaumeGomez/sysinfo
"diff --git a/src/common.rs b/src/common.rs\n--- a/src/common.rs\n+++ b/src/common.rs\n@@ -221,13 +2(...TRUNCATED)
9fb48e65376a6b479e8f134d38c6b38068436804
"Should `exe` be included in default process retrieval (and removed from `ProcessRefreshKind`)?\nIt (...TRUNCATED)
0.29
1,161
Another solution would be to just remove `refresh_process[es]`.
3cc9cc814d21b7977a0e7bb8260a7b64529e6a1b
[ "test_process_refresh" ]
["common::tests::check_display_impl_mac_address","common::tests::check_mac_address_is_unspecified_tr(...TRUNCATED)
[]
[]
2022-12-07T10:58:49Z
"diff --git a/tests/code_checkers/docs.rs b/tests/code_checkers/docs.rs\n--- a/tests/code_checkers/d(...TRUNCATED)
[ "886" ]
GuillaumeGomez__sysinfo-887
GuillaumeGomez/sysinfo
"diff --git a/examples/simple.rs b/examples/simple.rs\n--- a/examples/simple.rs\n+++ b/examples/simp(...TRUNCATED)
abe8e369d0cee1cf85ddc2d864da875c6312d524
"linux: environ is truncated for long environ\n```\r\n$ wc -c /proc/882252/environ\r\n30417 /proc/88(...TRUNCATED)
0.26
887
"suspicious size matching truncation: https://github.com/GuillaumeGomez/sysinfo/blob/master/src/linu(...TRUNCATED)
abe8e369d0cee1cf85ddc2d864da875c6312d524
[ "test_big_environ" ]
["common::tests::check_display_impl_process_status","common::tests::check_uid_gid_from_impls","linux(...TRUNCATED)
[]
[]
2022-09-03T12:49:44Z
"diff --git a/src/lib.rs b/src/lib.rs\n--- a/src/lib.rs\n+++ b/src/lib.rs\n@@ -469,4 +469,19 @@ mod (...TRUNCATED)
[ "833" ]
GuillaumeGomez__sysinfo-835
GuillaumeGomez/sysinfo
"diff --git a/src/linux/process.rs b/src/linux/process.rs\n--- a/src/linux/process.rs\n+++ b/src/lin(...TRUNCATED)
c7046eb4e189afcfb140057caa581d835e1cc51d
"Obtaining linux command line requires ProcessRefreshKind::with_user() to be set\nIt seems retrievin(...TRUNCATED)
0.26
835
"This is intriguing. Thanks for opening this issue! I'll try to take a look in the next days but don(...TRUNCATED)
abe8e369d0cee1cf85ddc2d864da875c6312d524
[ "test::check_cmd_line" ]
["common::tests::check_display_impl_process_status","system::tests::check_hostname_has_no_nuls","lin(...TRUNCATED)
[]
[]
README.md exists but content is empty.
Downloads last month
1