valpackett / systemstat Goto Github PK
View Code? Open in Web Editor NEWRust library for getting system information | also on https://codeberg.org/valpackett/systemstat
Home Page: https://crates.io/crates/systemstat
License: The Unlicense
Rust library for getting system information | also on https://codeberg.org/valpackett/systemstat
Home Page: https://crates.io/crates/systemstat
License: The Unlicense
Upon running cargo run
from terminal the call to system.cpu_temp()
returns the error message: Not supported
for Windows 10. Even though it says on the crates.io page that there should be support for Windows.
Attached code where i tried to get cpu_temp:
extern crate systemstat;
use std::thread;
use std::time::Duration;
use systemstat::{System, Platform, saturating_sub_bytes};
fn main() {
let system = System::new();
match system.cpu_temp() {
Ok(cpu_temp) => println!("\nCPU temp: {}", cpu_temp),
Err(ex) => println!("\nCPU temp: {}", ex)
}
}
I loved that added some support for macOS. Is this already stable to release a new version?
This code :
let sys = System::new();
let memory_usage = sys.memory().unwrap()
Panic with this error message :
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "Not supported" }', src/main.rs:36:24
Compiling c27e070 on Linux:
Compiling systemstat v0.1.2 (https://github.com/myfreeweb/systemstat#c27e070b)
error[E0308]: mismatched types
--> /home/ploppz/.cargo/git/checkouts/systemstat-39467158cd685114/c27e070/src/platform/linux.rs:365:30
|
365 | .and_then(|data| data.parse::<f32>())
| ^^^^^^^^^^^^^^^^^^^ expected struct `std::io::Error`, found struct `std::num::ParseFloatError`
|
= note: expected type `std::result::Result<_, std::io::Error>`
found type `std::result::Result<f32, std::num::ParseFloatError>`
error: aborting due to previous error
I personally changed it to .and_then(|data| Ok(data.parse::<f32>().unwrap()))
because I'm not sure how to convert to another error type sensibly. It would be easier with error_chain
, don't you think? Or at least a custom error type that encompasses io::Error
and num::ParseFloatError
and whatever is needed.
When building my application which use systemstat from a Linux host to a windows target (cargo build --target=x86_64-pc-windows-gnu
the linker failed ( /usr/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lIphlpapi
).
The problem is that the library in mingw is in totally in lowercase (iphlpapi) but the linker attribute (in socket.rs and network_interfaces.rs) has the first letter in uppercase (Iphlpapi).
Could you change the linker attributes to make the build succeed.
It shouldn't change the Windows behavior because the filename are case insensitive in Windows.
Regards
When executing the System::mounts()
function on Windows Server 2008, it returns the following error:
The device is not ready. (os error 21)
I tried debugging the application but because this is a production machine, I am not able to install rust and therefore the backtrace generated is just a bunch of <unknown>
s.
λ cargo --version
cargo 1.34.0 (6789d8a0a 2019-04-01)
λ rustc --version
rustc 1.34.1 (fc50f328b 2019-04-24)
Windows Version: Windows Server 2008 R2
Hi,
Would it be possible to add support for NetBSD, starship/starship#4076 ?
I thought this was already done when I wrote #22. I'd be interested in adding it.
I'd propose adding an os-specific field to CpuLoad
to track this quantity (since I don't believe it's readily available on BSD).
Does crates.io automatically update,, or has the crate version with feature serde not been uploaded yet?
Hello.
The network code for FreeBSD also works for Linux, so that would be great to add it for Linux.
The current Linux code for the battery, however, does not work on my computer since I do not have the same files.
Perhaps there is an API similar to the one used for FreeBSD.
Thanks.
Sorry to bother you with an issue, but I was wondering if there were plans for a new release? It seems that the master
branch has quite a few new things while the latest release e.g. doesn't support macOS yet :)
Currently you can get Filename::files
which holds the number files (inodes) in use for a filesystem. (On FreeBSD; in Linux it holds the total capacity which I think may be an error, see #28 )
In order to be able to report this as a percentage of the whole, it would be nice to be able to also get the total number of files a filesystem can have (e.g. files_total
).
Also Linux has both "free" and "available" counts for files. It would be nice to be able to get both numbers, as the latter is often more relevant. Since FreeBSD doesn't seem to have "available" we could just map the same value as for "free".
So I'd like to add as follows
struct Filesystem {
files: usize,
files_total: usize, // definitely this
files_avail: usize, // also this, if possible
/* ... */
}
We are currently using this crate and are implementing the Platform
trait for a dummy/test platform for our unit tests.
The trait provides methods uptime
and boot_time
, but they each call each other, leading to a stack overflow unless one overrides either of them (as is done in the implementation for Linux where uptime
is overridden).
See also: https://github.com/myfreeweb/systemstat/blob/master/src/platform/common.rs#L37 and https://github.com/myfreeweb/systemstat/blob/master/src/platform/common.rs#L45.
In our opinion, the uptime
method should not be provided but required or this should be documented at the minimum.
Using master at commit 59929b2d7f5d4e520e6dec03499d71c2460fd866
and using FreeBSD 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC amd64
with rustc 1.36.0-nightly (d35181ad8 2019-05-20)
I get the following error when running cargo test
:
# cargo test
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running target/debug/deps/systemstat-29c6b1a37a7b0b74
running 10 tests
test platform::tests::test_battery_life ... ok
test platform::tests::test_cpu_measurement_is_send ... ok
test platform::tests::test_memory ... ok
test platform::tests::test_load_average ... ok
test platform::tests::test_mount_at ... FAILED
test platform::tests::test_networks ... ok
test platform::tests::test_on_ac_power ... FAILED
test platform::tests::test_mounts ... FAILED
test platform::tests::test_cpu_load ... ok
test platform::tests::test_cpu_load_aggregate ... ok
failures:
---- platform::tests::test_mount_at stdout ----
thread 'platform::tests::test_mount_at' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: StringError("statfs() failed") }', src/libcore/result.rs:999:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
---- platform::tests::test_on_ac_power stdout ----
thread 'platform::tests::test_on_ac_power' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: StringError("sysctl() failed") }', src/libcore/result.rs:999:5
---- platform::tests::test_mounts stdout ----
thread 'platform::tests::test_mounts' panicked at 'attempt to subtract with overflow', src/platform/freebsd.rs:220:20
failures:
platform::tests::test_mount_at
platform::tests::test_mounts
platform::tests::test_on_ac_power
test result: FAILED. 7 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out
error: test failed, to rerun pass '--lib'
(I encountered this problem when I tried to run https://github.com/rabite0/hunter).
I read that there is a WinAPI function called GetTickCount64 which "retrieves the number of milliseconds that have elapsed since the system was started."
This appears to be implemented in kernel32 as kernel32::GetTickCount64()
but I'm not sure that's the best thing to use. I see winapi::um::sysinfoapi::GetTickCount64()
in winapi
, too.
This could be the solution or at least a starting point for implementing the unimplemented Windows uptime function.
I really like your library!! I noticed there is an issue with cpu_temp()
let sys = System::new(); let temp = sys.cpu_temp().unwrap(); println!("{:?}", temp);
Returns
Err(Custom { kind: Other, error: StringError("Could not parse float") })
Hey there,
When putting the example code into a loop
I only get 0% usage reporting.
The Idle and temp values seem to reflect what a cat /proc/stat
and glances
readout are giving me...
Adding a video as probably it's more illustrative:
https://imgur.com/a/ybisqaa
(Manjaro Linux 64bit / Linux 5.4.34-1-MANJARO)
It is generous that you have decided to dedicate systemstat to the public domain, but unfortunately, there is a flip side to this also: Even permissively licensed code, which constitutes the vast majority of all crates available today, cannot be reused in systemstat.
This prevents code from the MIT-licensed sysinfo crate from being used to improve systemstat. Most notably, sysinfo has full macOS support while systemstat has basically none at this point, and Windows support seems to be a lot better as well. I have studied both crates and prefer systemstat's design overall, but of course there are a few things that sysinfo does better and that could be shared.
My request is therefore that you consider changing this repository's license to one that allows inclusion of MIT-licensed code. I realize that since there are currently no license restrictions at all, I could do this myself in a fork, but I would prefer not to have to fork just for that. Also, I use neither macOS nor Windows myself, so I can't make the relevant changes anyway.
/ref p-e-w/hegemon#3
fn main() {
let sys_stat = systemstat::System::new();
do_something(&sys_stat);
}
fn do_something(sys_stat: &systemstat::System) {
let net = sys_stat.networks(); // crash (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
}
platform: windows 11
version: 0.1.10
My 4 CPU cores
are in 100%
load but the cpu_load_aggregate
output rarely goes to 10%
of usage. Most of the times all of them are 0
.
Following code is called every 250ms
:
let sys = System::new();
match sys.cpu_load_aggregate() {
Ok(cpu) => {
let cpu = cpu.done().unwrap();
Some(
SystemStat {
user: cpu.user * 100.0,
nice: cpu.nice * 100.0,
system: cpu.system * 100.0,
interrupt: cpu.interrupt * 100.0,
idle: cpu.idle * 100.0,
}
.into(),
)
}
Err(x) => {
println!("\nCPU load: error: {}", x);
None
}
}
I have a project I'm working on that I think I'm about to incorporate your crate for. The goal is to get the name and clock rate of the CPU and GPU, the amount of RAM and its clock rate, and the total storage size of attached SSDs and HDDs, and to display them on the screen in a screensaver kind of fashion. I'm having a hard time finding a way to do this. It looks like your crate will work great for the RAM and other useful info, but right now I'm resorting to using command line output from wmic on windows to get the proper name of the processor and it feels hacky. It works, but I want it to compile and run on any system, not just windows. It tells me I have an Intel Core i5, etc., which is true, but there has to be a way to get that same string without resorting to the command line.
In summary... PLEASE! PLEASE PLEASE PLEASE!
I'm sorry, I lost it there for a minute.
Tried using latest stable build. It managed to crash my PC while compiling. Even if you want to assume it wasn't this library's fault, the library cannot compile in its current state.
Hello,
In trying to compile my code, I'm getting the following:
Compiling systemstat v0.1.2
error[E0432]: unresolved import `self::platform::PlatformImpl`
--> C:\Users\#####\.cargo\registry\src\github.com-1ecc6299db9ec823\systemstat-0.1.2\src\lib.rs:14:9
|
14 | pub use self::platform::PlatformImpl as System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `PlatformImpl` in `platform`. Did you mean to use `Platform`?
error[E0412]: cannot find type `PlatformMemory` in this scope
--> C:\Users\#####\.cargo\registry\src\github.com-1ecc6299db9ec823\systemstat-0.1.2\src\data.rs:92:26
|
92 | pub platform_memory: PlatformMemory,
| ^^^^^^^^^^^^^^ not found in this scope
error: aborting due to previous error(s)
error: Could not compile `systemstat`.
I'm using the stable windows toolchain with MSVC, although the error also happens if I switch to the gnu toolset.
Any ideas on what could be causing this?
I'm using systemstat as a library for one my project. The project uses rust 2018 edition. While systemstat as a standalone crate compiles properly, when included as a dep it fails to compile with a bunch of errors like:
error[E0597]: `data` does not live long enough
--> /home/nick/Nextcloud/src/systemstat/src/platform/linux.rs:109:29
|
109 | proc_stat_cpu_times(data.as_bytes())
| ^^^^ borrowed value does not live long enough
...
112 | })
| - borrowed value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
Might be related to new borrow checking algos in rust 2018.
I have a patch to fix this, can submit it as a pull request later today.
Although the first call to mounts() returns all the system's mounts, repeated calls return only a subset and rather unpredictably.
I've traced this down to here:
fn stat_mount(mount: ProcMountsData) -> io::Result<Filesystem> {
let mut info: statvfs = unsafe { std::mem::zeroed() };
let result = unsafe { statvfs(mount.target.as_ptr() as *const c_char, &mut info) };
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
match result {
0 => Ok(Filesystem {
I think the indicated part needs to be a null terminated string, and isn't. So this works for a while until memory begins to get reused and is not initialized with zeros.
This fixes it:
fn stat_mount(mount: ProcMountsData) -> io::Result<Filesystem> {
let mut info: statvfs = unsafe { std::mem::zeroed() };
let target = format!("{}\0", mount.target); // null terminated string
let result = unsafe { statvfs(target.as_ptr() as *const c_char, &mut info) };
match result {
0 => Ok(Filesystem {
Hello! I'm trying to use your crate for retrieving system uptime and received the following errors when trying to compile version 0.1.2
upon running cargo build
:
Compiling systemstat v0.1.2
error[E0432]: unresolved import `self::platform::PlatformImpl`
--> /Users/natalie/.cargo/registry/src/github.com-1ecc6299db9ec823/systemstat-0.1.2/src/lib.rs:14:9
|
14 | pub use self::platform::PlatformImpl as System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `PlatformImpl` in `platform`. Did you mean to use `Platform`?
error[E0412]: cannot find type `PlatformMemory` in this scope
--> /Users/natalie/.cargo/registry/src/github.com-1ecc6299db9ec823/systemstat-0.1.2/src/data.rs:92:26
|
92 | pub platform_memory: PlatformMemory,
| ^^^^^^^^^^^^^^ not found in this scope
error: aborting due to 2 previous errors
error: Could not compile `systemstat`.
If the problem is as simple as switching out Platform
for PlatformImpl
, I'd be happy to submit a patch!
It's only returning 3 for me on a 4-core system.
Here's the contents of my /proc/stat
:
cpu 301439 3431 227659 131840429 103226 131240 368724 0 0 0
cpu0 79479 749 60245 32813939 49566 48200 184931 0 0 0
cpu1 76930 862 57391 32892308 19437 40731 153489 0 0 0
cpu2 71106 889 55988 33042231 19820 27443 24650 0 0 0
cpu3 73923 930 54032 33091950 14401 14865 5653 0 0 0
intr 129549542 7 0 0 0 0 0 0 0 1 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btime 1612511454
processes 31382
procs_running 1
procs_blocked 0
softirq 130779335 6933 13070143 953419 91889261 1493492 0 730179 17947091 1372 4687445
and the return value from cpu_load()
after waiting and calling .done()
:
Ok(
[
CPULoad {
user: 0.02,
nice: 0.0,
system: 0.01,
interrupt: 0.0,
idle: 0.97,
platform: PlatformCpuLoad {
iowait: 0.0,
},
},
CPULoad {
user: 0.02970297,
nice: 0.0,
system: 0.01980198,
interrupt: 0.0,
idle: 0.95049506,
platform: PlatformCpuLoad {
iowait: 0.0,
},
},
CPULoad {
user: 0.01,
nice: 0.0,
system: 0.01,
interrupt: 0.01,
idle: 0.97,
platform: PlatformCpuLoad {
iowait: 0.0,
},
},
],
)
This would be useful - I would be looking to add this functionality myself if it's deemed useful for the project.
I noticed that the other
field on CpuTime
is only used in the linux implementation to provide iowait
statistics.
Is there any reason to keep it this way, or might I propose changing it to iowait
?. It looks like it might also be possible to have OS specific struct fields using the cfg
macro, which could also be an option.
What's your take on this? Again, happy to do the work.
All the best,
Richard
I tried playing around with your library and was surprised to see one of the few segfaults i've seen in rust and running your demo file too.
Running `target/debug/bin`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Custom(Custom { kind: Other, error: StringError("Not supported") }) }', ../src/libcore/result.rs:785
stack backtrace:
1: 0x55a355aeafef - std::sys::backtrace::tracing::imp::write::h6528da8103c51ab9
2: 0x55a355aed3eb - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hbe741a5cc3c49508
3: 0x55a355aed06f - std::panicking::default_hook::he0146e6a74621cb4
4: 0x55a355ae4f3e - std::panicking::rust_panic_with_hook::h983af77c1a2e581b
5: 0x55a355aed631 - std::panicking::begin_panic::he426e15a3766089a
6: 0x55a355ae58aa - std::panicking::begin_panic_fmt::hdddb415186c241e7
7: 0x55a355aed5ce - rust_begin_unwind
8: 0x55a355b22aaf - core::panicking::panic_fmt::hf4e16cb7f0d41a25
9: 0x55a355ad9f1b - core::result::unwrap_failed::hf40cb93f6f31ec3d
at ../src/libcore/macros.rs:29
10: 0x55a355ad9551 - _<core..result..Result<T, E>>::unwrap::ha10f31560a1ef478
at ../src/libcore/result.rs:723
11: 0x55a355ad81ba - bin::main::h526525808e6ff144
at src/main.rs:10
12: 0x55a355aecca8 - std::panicking::try::call::h852b0d5f2eec25e4
13: 0x55a355af6cbb - __rust_try
14: 0x55a355af6c5e - __rust_maybe_catch_panic
15: 0x55a355aec74e - std::rt::lang_start::hfe4efe1fc39e4a30
16: 0x55a355ae1cf9 - main
17: 0x7f9fa817d740 - __libc_start_main
18: 0x55a355ad7ce8 - _start
19: 0x0 - <unknown>
error: Process didn't exit successfully: `target/debug/bin` (exit code: 101)
Since I rarely run into segfaults im unsure of how to continue, do you have any ideas as to what could be causeing this?
I have used this library to write a simple diskspace
utility to display available (and optionally, total) disk space. The utility works fine on Debian (and with #53, on macOS), but reports what seem to be wildly incorrect results on Raspbian. I have tested this with the following script:
diskspace --bytes; py -c 'import shutil; print(shutil.disk_usage("/").free)'
On my Debian server, this produced:
20506071040
20506071040
And on my MacBook:
55125647360
55125647360
On my Raspberry Pi however:
1290358784
9880293376
The df
utility agrees with the Python script.
In addition to memory()
-usage also report swap usage. I would be willing to implement this myself.
Would you prefer this as a separate swap()
function or as a part of memory()
? Some platform-APIs will return memory and swap information together.
hello, when I build this crate or cargo run example I will get that error
➜ systemstat git:(master) cargo build --release
Compiling autocfg v1.0.1
Compiling bitflags v1.2.1
Compiling radium v0.5.3
Compiling ryu v1.0.5
Compiling libc v0.2.82
Compiling version_check v0.9.2
Compiling lexical-core v0.7.4
Compiling memchr v2.3.4
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: could not compile `lexical-core`
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: build failed
➜ systemstat git:(master) uname -a
Linux ubuntu 5.8.0-40-generic #45~20.04.1-Ubuntu SMP Fri Jan 15 11:35:04 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
macOS has a concept of purgeable space. It can be treated like free space for most purposes, because the OS deletes from it if space gets too low. As such, it would make sense to either include it in Filesystem.avail
or add it as a separate API.
Attempting to use this library yields many compiler warnings. Here is what I get when i try to compile this on Windows 10 with the latest stable:
warning: unused `#[macro_use]` import
--> src\lib.rs:10:1
|
10 | #[macro_use]
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: use of deprecated item 'std::mem::uninitialized': use `mem::MaybeUninit` instead
--> src\platform\windows\disk.rs:133:46
|
133 | let mut avail: ULARGE_INTEGER = unsafe { mem::uninitialized() };
| ^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
warning: use of deprecated item 'std::mem::uninitialized': use `mem::MaybeUninit` instead
--> src\platform\windows\disk.rs:134:46
|
134 | let mut total: ULARGE_INTEGER = unsafe { mem::uninitialized() };
| ^^^^^^^^^^^^^^^^^^
warning: use of deprecated item 'std::mem::uninitialized': use `mem::MaybeUninit` instead
--> src\platform\windows\disk.rs:135:45
|
135 | let mut free: ULARGE_INTEGER = unsafe { mem::uninitialized() };
| ^^^^^^^^^^^^^^^^^^
warning: use of deprecated item 'libc::uint8_t': Use u8 instead.
--> src\platform\windows\network_interfaces.rs:1:42
|
1 | use libc::{c_void, free, malloc, size_t, uint8_t};
| ^^^^^^^
warning: use of deprecated item 'libc::uint8_t': Use u8 instead.
--> src\platform\windows\network_interfaces.rs:59:28
|
59 | on_link_prefix_length: uint8_t,
| ^^^^^^^
warning: use of deprecated item 'libc::uint8_t': Use u8 instead.
--> src\platform\windows\network_interfaces.rs:199:60
|
199 | fn parse_addr_and_netmask(aptr: *const SOCKADDR, net_bits: uint8_t) -> NetworkAddrs {
| ^^^^^^^
warning: unused variable: `path`
--> src\platform\windows\mod.rs:295:46
|
295 | fn mount_at<P: AsRef<path::Path>>(&self, path: P) -> io::Result<Filesystem> {
| ^^^^ help: consider prefixing with an underscore: `_path`
|
= note: `#[warn(unused_variables)]` on by default
warning: unused variable: `interface`
--> src\platform\windows\mod.rs:307:29
|
307 | fn network_stats(&self, interface: &str) -> io::Result<NetworkStats> {
| ^^^^^^^^^ help: consider prefixing with an underscore: `_interface`
warning: unused variable: `rhs`
--> src\data.rs:58:26
|
58 | pub fn avg_add(self, rhs: &Self) -> Self {
| ^^^ help: consider prefixing with an underscore: `_rhs`
warning: unused variable: `input`
--> src\data.rs:86:17
|
86 | pub fn from(input: f32) -> Self {
| ^^^^^ help: consider prefixing with an underscore: `_input`
warning: function is never used: `physical_address_to_string`
--> src\platform\windows\network_interfaces.rs:186:4
|
186 | fn physical_address_to_string(array: &[u8; 8], length: DWORD) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
Finished dev [unoptimized + debuginfo] target(s) in 5.61s
I think the worst thing here is the use of std::mem::uninitialized
. Regardless, all the warnings should probably be fixed at some point.
serde-feature-hack
has been marked as deprecated by it's maintainer, with a "workaround" provided by Cargo itself, since version 1.31. So unless you want to actually support MSRV lower than 1.31, I would consider to moving to depending directly on serde
itself.
Is get_sys_info a fork?
I just want to know which is the original crate.
I am calling socket stat exactly like in examples
match sys.socket_stats() {
Ok(stats) => trace!("\nSystem socket statistics: {:?}", stats),
Err(x) => error!("\nSystem socket statistics: error: {}", x.to_string()),
}
It is runnning on ARM ( raspberry pi 4 ) and it worked correctly, but suddenly it gives this Parsing Error
Parsing Error: Error { input: "\nTCP: inuse 7 orphan 0 tw 5 alloc 12 mem 0\nUDP: inuse 3 mem 3\nUDPLITE: inuse 0\nRAW: inuse 0\nFRAG: inuse 0 memory 0\n", code: Tag }
Using this version:
[[package]]
name = "systemstat"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1f726379f0c746ad672b7e932bd390b5faae073f502e37d314950ced761ac3e"
Winapi 0.3 is about to be released and the maintainer is looking for people to test against it as it's a large refactoring. Since I saw you were using 0.2 I'd recommend you test against the git winapi-rs version now or even better switch to the git dependency so that any issues you run into can be resolved.
While implementing a CI solution for the hunter file manager, I've come across a bug in systemstat
that prevents it from compiling under 32-bit BSD and 32-bit MacOS systems.
chrono::NaiveDateTime::from_timestamp() expects its secs
parameter to always be an i64
. However, in /src/platform/macos.rs:Platform:boot_time()
and /src/platform/freebsd.rs:Platform:boot_time()
, the tv_sec
field of the libc::timeval
struct is passed without casting it to an i64
.
We're using the cross crate by the Rust Embedded Devices Working Group to build binaries for foreign architectures.
Here is the build log for 32-bit MacOS:
$ cross build --target i686-apple-darwin --release
info: downloading component 'rust-std' for 'i686-apple-darwin'
info: installing component 'rust-std' for 'i686-apple-darwin'
51.5 MiB / 51.5 MiB (100 %) 12.4 MiB/s ETA: 0 s
Compiling systemstat v0.1.4
error[E0308]: mismatched types
--> /Users/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/systemstat-0.1.4/src/platform/macos.rs:65:68
|
65 | Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(data.tv_sec, data.tv_usec as u32), Utc))
| ^^^^^^^^^^^ expected i64, found i32
help: you can cast an `i32` to `i64`, which will sign-extend the source value
|
65 | Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(data.tv_sec.into(), data.tv_usec as u32), Utc))
| ^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
Here is the build log for 32-bit FreeBSD:
$ cross build --target i686-unknown-freebsd --release
info: downloading component 'rust-std' for 'i686-unknown-freebsd'
info: installing component 'rust-std' for 'i686-unknown-freebsd'
62.9 MiB / 62.9 MiB (100 %) 13.9 MiB/s ETA: 0 s
Unable to find image 'japaric/i686-unknown-freebsd:v0.1.14' locally
v0.1.14: Pulling from japaric/i686-unknown-freebsd
Status: Downloaded newer image for japaric/i686-unknown-freebsd:v0.1.14
Compiling systemstat v0.1.4
error[E0308]: mismatched types
--> /cargo/registry/src/github.com-1ecc6299db9ec823/systemstat-0.1.4/src/platform/freebsd.rs:109:68
|
109 | Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(data.tv_sec, data.tv_usec as u32), Utc))
| ^^^^^^^^^^^ expected i64, found i32
help: you can cast an `i32` to `i64`, which will sign-extend the source value
|
109 | Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(data.tv_sec.into(), data.tv_usec as u32), Utc))
| ^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
When this is called, the function only returns with an error saying it's not supported.
But I believe there's actually some way to get the idel time, system time, user time, etc with performance counter or PDH APIs.
And I think here's the example that may be useful.
http://dostf.blogspot.com/2012/02/measuure-cpu-usage-on-windows-with-pdh.html
At least windows can provide:
"Processor({index})\% {type} Time" performance counter, and this should be exactly similar to the definitions of the value in the CpuLoad.
FreeBSD is implemented like this:
Filesystem {
files: self.f_files as usize - self.f_ffree as usize,
/* ... */
}
Linux is implemented like this:
Filesystem {
files: info.f_files as usize,
/* ... */
}
So the same field, Filesystem::files
, actually has different meanings in each platform. I assume Linux is wrong here because it isn't actually very useful to have only the capacity. I plan to submit a PR for this
@biluohc trying to run on Server 2016:
thread 'main' panicked at 'attempt to shift left with overflow', src\platform\windows\network_interfaces.rs:280:28
data.rs:
pub use std::time::Duration;
pub use std::net::{Ipv4Addr, Ipv6Addr};
pub use std::collections::BTreeMap;
Hi,
Do you plan to support Mac arm64 ?
Thanks
Hi Team,
I am new to Rust. I just cloned the repo and did a cargo build, it fails and gives the following message on console:
`_error[E0432]: unresolved import self::platform::PlatformImpl
--> src/lib.rs:14:9
|
14 | pub use self::platform::PlatformImpl as System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no PlatformImpl in platform. Did you mean to use Platform?
error[E0412]: cannot find type PlatformMemory in this scope
--> src/data.rs:92:26
|
92 | pub platform_memory: PlatformMemory,
| ^^^^^^^^^^^^^^ not found in this scope
error: aborting due to previous error(s)
error: Could not compile systemstat._`
Could you please look into this?
should be a matter of just enabling the linux implementation for android?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.