Refactor timer module

This commit is contained in:
David Peter authored and David Peter committed 2022-02-22 10:51:06 +01:00
1 parent f029a46ff9
commit defafdf707
6 files changed
+18 -73

No files matched your search

+5 -18
View File
@@ -1,35 +1,22 @@
#![cfg(not(windows))]
use std::mem;
use std::process::Child;
use crate::timer::{CPUInterval, CPUTimes, TimerStart, TimerStop};
use crate::timer::{CPUInterval, CPUTimes};
use crate::util::units::Second;
pub fn get_cpu_timer() -> Box<dyn TimerStop<Result = (Second, Second)>> {
Box::new(CPUTimer::start())
}
struct CPUTimer {
pub struct CPUTimer {
start_cpu: CPUTimes,
}
impl TimerStart for CPUTimer {
fn start() -> Self {
impl CPUTimer {
pub fn start() -> Self {
CPUTimer {
start_cpu: get_cpu_times(),
}
}
fn start_for_process(_: &Child) -> Self {
Self::start()
}
}
impl TimerStop for CPUTimer {
type Result = (Second, Second);
fn stop(&self) -> Self::Result {
pub fn stop(&self) -> (Second, Second) {
let end_cpu = get_cpu_times();
let cpu_interval = cpu_time_interval(&self.start_cpu, &end_cpu);
(cpu_interval.user, cpu_interval.system)