Improve OnDiskTOMLMonitor
(#2125)
* Allow for more frequent updates of TOML monitor * Don't skip first client * Reduce code duplication * Immediately write first TOML file * Rust fmt * Use same client numbering as other monitors * Fmt
This commit is contained in:
parent
b49ab999e3
commit
61ac4ea7be
@ -22,6 +22,7 @@ where
|
|||||||
base: M,
|
base: M,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
last_update: Duration,
|
last_update: Duration,
|
||||||
|
update_interval: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M> Monitor for OnDiskTOMLMonitor<M>
|
impl<M> Monitor for OnDiskTOMLMonitor<M>
|
||||||
@ -55,7 +56,7 @@ where
|
|||||||
fn display(&mut self, event_msg: &str, sender_id: ClientId) {
|
fn display(&mut self, event_msg: &str, sender_id: ClientId) {
|
||||||
let cur_time = current_time();
|
let cur_time = current_time();
|
||||||
|
|
||||||
if (cur_time - self.last_update).as_secs() >= 60 {
|
if cur_time - self.last_update >= self.update_interval {
|
||||||
self.last_update = cur_time;
|
self.last_update = cur_time;
|
||||||
|
|
||||||
let mut file = File::create(&self.filename).expect("Failed to open the TOML file");
|
let mut file = File::create(&self.filename).expect("Failed to open the TOML file");
|
||||||
@ -80,7 +81,7 @@ exec_sec = {}
|
|||||||
)
|
)
|
||||||
.expect("Failed to write to the TOML file");
|
.expect("Failed to write to the TOML file");
|
||||||
|
|
||||||
for (i, client) in self.client_stats_mut().iter_mut().skip(1).enumerate() {
|
for (i, client) in self.client_stats_mut().iter_mut().enumerate() {
|
||||||
let exec_sec = client.execs_per_sec(cur_time);
|
let exec_sec = client.execs_per_sec(cur_time);
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
@ -92,11 +93,7 @@ objectives = {}
|
|||||||
executions = {}
|
executions = {}
|
||||||
exec_sec = {}
|
exec_sec = {}
|
||||||
",
|
",
|
||||||
i + 1,
|
i, client.corpus_size, client.objective_size, client.executions, exec_sec
|
||||||
client.corpus_size,
|
|
||||||
client.objective_size,
|
|
||||||
client.executions,
|
|
||||||
exec_sec
|
|
||||||
)
|
)
|
||||||
.expect("Failed to write to the TOML file");
|
.expect("Failed to write to the TOML file");
|
||||||
|
|
||||||
@ -125,13 +122,23 @@ where
|
|||||||
/// Create new [`OnDiskTOMLMonitor`]
|
/// Create new [`OnDiskTOMLMonitor`]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new<P>(filename: P, base: M) -> Self
|
pub fn new<P>(filename: P, base: M) -> Self
|
||||||
|
where
|
||||||
|
P: Into<PathBuf>,
|
||||||
|
{
|
||||||
|
Self::with_update_interval(filename, base, Duration::from_secs(60))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create new [`OnDiskTOMLMonitor`] with custom update interval
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_update_interval<P>(filename: P, base: M, update_interval: Duration) -> Self
|
||||||
where
|
where
|
||||||
P: Into<PathBuf>,
|
P: Into<PathBuf>,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
base,
|
base,
|
||||||
filename: filename.into(),
|
filename: filename.into(),
|
||||||
last_update: current_time(),
|
last_update: current_time() - update_interval,
|
||||||
|
update_interval,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user