Commit Graph

176 Commits

Author SHA1 Message Date
Wolfgang Bumiller
e128fc879f sys: Add TryFrom<Pid> for PidStat
Since nix's Pid type is a strong type, we can add a TryFrom
implementation here as well.
This can later also have the equivalent TryFrom<PidFd>
variant.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-14 12:05:04 +01:00
Wolfgang Bumiller
42a155668e sys: change PidStat API
Rather than standalone functions, `PidStat` now provides a
`read_for_pid` and `parse` method. Both are public.
One side effect is that the documentation of PidStat's
contents are on the same page as the ways to retrieve it.

Additionally, we deprecate `read_proc_starttime` as it was
reading the entire contents to then filter out one value, in
order to promote caching.

The standalone `read_proc_pid_stat` method is now also
deprecated.

Once we add pid-fds the API will feel cleaner this way.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-14 12:01:06 +01:00
Wolfgang Bumiller
e3b41dc815 sys: extend proc_pid_stat parsing
Rename `ProcFsPidStat` to `PidStat`. It's already in a
procfs submodule anyway. (We have currently no public users
of this type by name.)

Further add pid, ppid and num_threads to PidStat.

Public API change.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-14 11:49:33 +01:00
Wolfgang Bumiller
43682dd416 version bump
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-02 14:42:28 +01:00
Wolfgang Bumiller
b659584f23 sys: add a bunch of error helpers
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-02 13:47:53 +01:00
Wolfgang Bumiller
568ce10624 sys: add some helpful macros
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-01-02 13:47:53 +01:00
Wolfgang Bumiller
1a2aaad5a1 more versioning fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-12-30 12:33:13 +01:00
Fabian Grünbichler
d6bf884814 proxmox-sys: initial packaging
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2019-12-20 09:39:45 +01:00
Fabian Grünbichler
f4d9e8157c proxmox-sys: update lazy-static to 1.4
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2019-12-20 09:39:45 +01:00
Thomas Lamprecht
cfae8ae3d2 linux/procfs: add read_proc_stat
For now we just parse the CPU "time-spent" counters and calculate the
CPU usage of the whole system. As we do not want a total average we
use a state-full implementation, which calculates the usage since the
last request (if older than 1 second).

Somewhat modeled after our Perl version of this. But for the "total"
we do not use the:
> ($ctime - $last_proc_stat->{ctime}) * $clock_ticks * $cpucount;
calculation, but just add _all_ fields together, as that is the total
of CPU time.

Use a Reader-Writer lock to sync updating. First check under the
reader lock if the data is recent enough, else update it under the
writer lock.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-12-18 17:00:51 +01:00
Wolfgang Bumiller
6cf330c9d2 add tools::parse submodule, move hex_nibble to it
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-14 09:59:04 +01:00
Wolfgang Bumiller
db83a675f0 sys: get rid of Regex dependency
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-13 14:49:11 +01:00
Wolfgang Bumiller
b294fb1314 sys: add read_proc_pid_stat test
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-13 14:49:11 +01:00
Wolfgang Bumiller
a11f6e88f8 [clippy] sys: simplifications and optimizations
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-22 09:28:44 +02:00
Wolfgang Bumiller
45b5839e7e replace std::mem::uninitialized
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-21 16:49:12 +02:00
Wolfgang Bumiller
aadb47a292 update nix to 0.15 for mkdirat
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-21 11:51:45 +02:00
Wolfgang Bumiller
ccce46eba4 formatting fixup
make fmt
(cargo fmt --all)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 14:14:23 +02:00
Wolfgang Bumiller
863a16a5bc whitespace cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 14:13:37 +02:00
Wolfgang Bumiller
4c9a8b5c88 cleanup use statements
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 14:12:49 +02:00
Wolfgang Bumiller
f074a9e60b cleanup Cargo.toml files
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 14:09:54 +02:00
Wolfgang Bumiller
1f11c4adf9 sys: rustfmt workaround
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 12:46:21 +02:00
Dietmar Maurer
d6d65be42e add nodename helper (copied from proxmox-backup) 2019-08-03 17:00:02 +02:00
Dietmar Maurer
ce18d8c035 src/linux/procfs.rs: moved from proxmox-backup 2019-08-03 16:19:11 +02:00
Dietmar Maurer
909520d191 add src/linux/magic.rs - moved from proxmox-backup 2019-08-03 09:19:32 +02:00
Wolfgang Bumiller
024930f63c cargo fmt --all
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Dietmar Maurer
71f2d48c2e start proxmox-sys module 2019-06-07 18:03:07 +02:00