1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Partial port of `linux/PressureStallMeter.c` — htop's Linux PSI
//! (Pressure Stall Information) meters.
//!
//! C names are preserved verbatim (htop uses `CamelCase_snake`), so
//! `non_snake_case` is allowed for the whole module — matching the spec
//! name-for-name is the point of the port. The C `static void
//! PressureStallMeter_display(const Object* cast, RichString* out)` casts
//! `cast` back to `const Meter*` and reads `this->values[...]`, so it ports
//! to a free fn `pub fn PressureStallMeter_display(this: &Meter, out: &mut
//! RichString)` — the `cast` → `this` down-cast collapses into the typed
//! `&Meter` parameter. The shared `Meter` model is
//! [`crate::ported::meter::Meter`], reused because it already carries the
//! `values` slot the display function reads.
//!
//! `CRT_colors[X]` (C's active-scheme row `const int* CRT_colors`, set by
//! `CRT_setColors` to point at `CRT_colorSchemes[colorScheme]`) is
//! reproduced as `ColorElements::X.packed(ColorScheme::active())`
//! (`CRT_colorSchemes[CRT_colorScheme][X]`), the same mapping
//! `loadaveragemeter.rs` uses for its ported display functions.
//! `xSnprintf(buffer, 20, "%5.2lf%% ", v)` becomes `format!("{:5.2}% ", v)`
//! — width 5, precision 2, a literal `%` (C's `%%`), then a trailing space;
//! the returned `len` is the string's byte length. The C `char buffer[20]`
//! does not truncate a PSI percentage (a handful of bytes), so the
//! fixed-buffer cap is not modeled (the reasoning `loadaveragemeter.rs`
//! applies to its buffer).
//!
//! Ported (self-contained: `RichString` + `CRT_colors` are ported):
//! - [`PressureStallMeter_display`] (`PressureStallMeter.c:57`) — appends
//! the 10s/60s/300s figures, each colored `PRESSURE_STALL_TEN` /
//! `PRESSURE_STALL_SIXTY` / `PRESSURE_STALL_THREEHUNDRED`.
//!
//! Stubbed (blocked on unported substrate — keeps its `todo!()`):
//! - `PressureStallMeter_updateValues` (`PressureStallMeter.c:30`) — the
//! C body selects the `/proc/pressure` file and the some/full flavor via
//! `Meter_name(this)` (`As_Meter(this)->name`, the concrete meter class's
//! internal name), then fills `this->values[0..2]` and formats
//! `this->txtBuffer`. The ported [`Meter`] carries no `name` field and no
//! per-instance concrete `MeterClass` (no concrete PSI meter type is
//! migrated), so `Meter_name(this)` has no faithful source — there is no
//! way to know which of the six `PressureStall*Meter_class`es a given
//! `Meter` instance is. The value reader `Platform_getPressureStall` is
//! ported and would feed the values, but the `file`/`some` selection it
//! needs cannot be reproduced without the class name.
use crate;
use crateMeter;
use crate;
/// TODO: port of `static void PressureStallMeter_updateValues(Meter* this)`
/// from `PressureStallMeter.c:30`. Blocked: the C body dispatches on
/// `Meter_name(this)` (`As_Meter(this)->name`, the concrete meter class's
/// internal name — "PressureStallCPUSome", "PressureStallIOFull", …) to pick
/// the `/proc/pressure` file (`cpu`/`io`/`irq`/`memory`) and the some/full
/// flavor, then calls `Platform_getPressureStall(file, some, &this->values[0],
/// …)` and formats `this->txtBuffer`. The ported [`Meter`] has no `name` field
/// and holds no per-instance concrete `MeterClass` (no concrete PSI meter type
/// is migrated), so `Meter_name(this)` has no faithful data source; the
/// `file`/`some` selection cannot be reproduced. (`Platform_getPressureStall`
/// itself is ported.)
/// Port of `static void PressureStallMeter_display(const Object* cast,
/// RichString* out)` from `PressureStallMeter.c:57`. Appends the three PSI
/// figures — the 10-, 60-, and 300-second averages — each as `"%5.2lf%% "`,
/// colored `PRESSURE_STALL_TEN`, `PRESSURE_STALL_SIXTY`, and
/// `PRESSURE_STALL_THREEHUNDRED` respectively. `CRT_colors[X]` is
/// `ColorElements::X.packed(scheme)`; the active scheme is read once (a
/// process-global that does not change mid-call), matching the C global
/// `CRT_colors`.