qemu_command_builder/
icount.rs

1use std::path::PathBuf;
2
3use bon::Builder;
4
5use crate::common::OnOff;
6use crate::to_command::{ToArg, ToCommand};
7
8#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
9pub enum Shift {
10    N(usize),
11    Auto,
12}
13
14#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
15pub enum RecordReplay {
16    Record,
17    Replay,
18}
19
20impl ToArg for RecordReplay {
21    fn to_arg(&self) -> &str {
22        match self {
23            RecordReplay::Record => "record",
24            RecordReplay::Replay => "replay",
25        }
26    }
27}
28#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Builder)]
29pub struct Icount {
30    shift: Option<Shift>,
31    align: Option<OnOff>,
32    sleep: Option<OnOff>,
33    rr: Option<RecordReplay>,
34    rrfile: Option<PathBuf>,
35    rrsnapshot: Option<String>,
36}
37
38impl ToCommand for Icount {
39    fn to_command(&self) -> Vec<String> {
40        let mut cmd = vec![];
41
42        cmd.push("-icount".to_string());
43
44        let mut args = vec![];
45
46        if let Some(shift) = &self.shift {
47            match shift {
48                Shift::N(size) => {
49                    args.push(format!("shift={}", size));
50                }
51                Shift::Auto => {
52                    args.push("shift=auto".to_string());
53                }
54            }
55        }
56        if let Some(align) = &self.align {
57            args.push(format!("align={}", align.to_arg()));
58        }
59        if let Some(sleep) = &self.sleep {
60            args.push(format!("sleep={}", sleep.to_arg()));
61        }
62        if let Some(rr) = &self.rr {
63            args.push(format!("rr={}", rr.to_arg()));
64        }
65        if let Some(rrfile) = &self.rrfile {
66            args.push(format!("rrfile={}", rrfile.display()));
67        }
68        if let Some(rrsnapshot) = &self.rrsnapshot {
69            args.push(format!("rrsnapshot={}", rrsnapshot));
70        }
71        cmd.push(args.join(","));
72        cmd
73    }
74}