Skip to content

Commit 9f7dfed

Browse files
committed
Add status output for platform profile
1 parent 3ea5850 commit 9f7dfed

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

src/cli/status.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl DynCommand for Command {
3131

3232
struct Stats {
3333
perf: PerfStats,
34+
prof: ProfileStats,
3435
dgpu: DgpuStats,
3536
dtx: DtxStats,
3637
}
@@ -39,6 +40,11 @@ struct PerfStats {
3940
mode: Option<sys::perf::Mode>,
4041
}
4142

43+
struct ProfileStats {
44+
current: String,
45+
supported: Vec<String>,
46+
}
47+
4248
struct DgpuStats {
4349
vendor: Option<u16>,
4450
device: Option<u16>,
@@ -58,14 +64,16 @@ struct DtxStats {
5864
impl Stats {
5965
fn load() -> Self {
6066
let perf = PerfStats::load();
67+
let prof = ProfileStats::load();
6168
let dgpu = DgpuStats::load();
6269
let dtx = DtxStats::load();
6370

64-
Stats { perf, dgpu, dtx }
71+
Stats { perf, prof, dgpu, dtx }
6572
}
6673

6774
fn available(&self) -> bool {
6875
self.perf.available()
76+
|| self.prof.available()
6977
|| self.dgpu.available()
7078
|| self.dtx.available()
7179
}
@@ -84,6 +92,24 @@ impl PerfStats {
8492
}
8593
}
8694

95+
impl ProfileStats {
96+
fn load() -> Self {
97+
let dev = sys::profile::Device::open().ok();
98+
99+
let current = dev.as_ref().and_then(|d| d.get().ok());
100+
let supported = dev.as_ref().and_then(|d| d.get_supported().ok());
101+
102+
ProfileStats {
103+
current: current.unwrap_or_else(String::new),
104+
supported: supported.unwrap_or_else(Vec::new),
105+
}
106+
}
107+
108+
fn available(&self) -> bool {
109+
!self.supported.is_empty() && !self.current.is_empty()
110+
}
111+
}
112+
87113
impl DgpuStats {
88114
fn load() -> Self {
89115
let dev = crate::cli::dgpu::find_dgpu_device().ok().and_then(|x| x);
@@ -137,7 +163,7 @@ impl DtxStats {
137163

138164
impl std::fmt::Display for Stats {
139165
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
140-
write!(f, "{}{}{}", self.perf, self.dgpu, self.dtx)
166+
write!(f, "{}{}{}{}", self.perf, self.prof, self.dgpu, self.dtx)
141167
}
142168
}
143169

@@ -151,6 +177,31 @@ impl std::fmt::Display for PerfStats {
151177
}
152178
}
153179

180+
impl std::fmt::Display for ProfileStats {
181+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
182+
if !self.available() {
183+
return Ok(());
184+
}
185+
186+
let mut profiles = String::new();
187+
for (i, profile) in self.supported.iter().enumerate() {
188+
if i > 0 {
189+
profiles += " ";
190+
}
191+
192+
if *profile == self.current {
193+
profiles += "[";
194+
profiles += &profile;
195+
profiles += "]";
196+
} else {
197+
profiles += &profile;
198+
}
199+
}
200+
201+
writeln!(f, "Platform Profile: {}\n", profiles)
202+
}
203+
}
204+
154205
impl std::fmt::Display for DgpuStats {
155206
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
156207
if !self.available() {

0 commit comments

Comments
 (0)