@@ -97,102 +97,6 @@ public SensorMetadata metadata() {
9797 return cpu .metadata ();
9898 }
9999
100- private static class ProcessRecord {
101- final double cpu ;
102- final double gpu ;
103- final String pid ;
104-
105- public ProcessRecord (String line ) throws IllegalArgumentException {
106- // Expected normal output:
107- //Name ID CPU ms/s samp ms/s User% Deadlines (<2 ms, 2-5 ms) Wakeups (Intr, Pkg idle) GPU ms/s
108- //iTerm2 1008 46.66 46.91 83.94 0.00 0.00 30.46 0.00 0.00
109- // Expected summary output:
110- //Name ID CPU ms/s samp ms/s [total] User% Deadlines/s [total] (<2 ms, 2-5 ms) Wakeups/s [total] (Intr, Pkg idle) Dead GPU ms/s
111- //WindowServer 406 493.74 493.96 [5165.88 ] 64.82 65.95 [690 ] 0.00 [0 ] 656.62 [6870 ] 4.21 [44 ] N 0.00
112-
113- try {
114- // Trim leading/trailing whitespace
115- line = line .trim ();
116-
117- // Find first whitespace block after process name (marks start of ID)
118- int idStart = findFirstWhitespace (line );
119- if (idStart == -1 ) {
120- throw new IllegalArgumentException ("Cannot find ID in line: " + line );
121- }
122-
123- // Skip whitespace to get to ID
124- idStart = skipWhitespace (line , idStart );
125- int idEnd = findNextWhitespace (line , idStart );
126- pid = RegisteredPID .prepare (line .substring (idStart , idEnd ));
127-
128- // Skip CPU ms/s column (skip whitespace, then number, then whitespace)
129- int pos = skipWhitespace (line , idEnd );
130- pos = skipNumber (line , pos );
131-
132- // Now at samp ms/s
133- pos = skipWhitespace (line , pos );
134- int sampStart = pos ;
135- int sampEnd = skipNumber (line , sampStart );
136- cpu = Double .parseDouble (line .substring (sampStart , sampEnd ));
137-
138- // Skip to end and work backwards to find GPU ms/s
139- // The GPU value is the last numeric value on the line
140- int lastNumEnd = line .length ();
141- while (lastNumEnd > 0 && Character .isWhitespace (line .charAt (lastNumEnd - 1 ))) {
142- lastNumEnd --;
143- }
144-
145- int lastNumStart = lastNumEnd ;
146- while (lastNumStart > 0 && isNumberChar (line .charAt (lastNumStart - 1 ))) {
147- lastNumStart --;
148- }
149-
150- if (lastNumStart < lastNumEnd ) {
151- gpu = Double .parseDouble (line .substring (lastNumStart , lastNumEnd ));
152- } else {
153- throw new IllegalArgumentException ("Cannot find GPU value in line: " + line );
154- }
155-
156- } catch (Exception e ) {
157- throw new IllegalArgumentException ("Received line doesn't conform to expected format: " + line , e );
158- }
159- }
160-
161- private static int findFirstWhitespace (String line ) {
162- for (int i = 0 ; i < line .length (); i ++) {
163- if (Character .isWhitespace (line .charAt (i ))) {
164- return i ;
165- }
166- }
167- return -1 ;
168- }
169-
170- private static int skipWhitespace (String line , int pos ) {
171- while (pos < line .length () && Character .isWhitespace (line .charAt (pos ))) {
172- pos ++;
173- }
174- return pos ;
175- }
176-
177- private static int findNextWhitespace (String line , int pos ) {
178- while (pos < line .length () && !Character .isWhitespace (line .charAt (pos ))) {
179- pos ++;
180- }
181- return pos ;
182- }
183-
184- private static int skipNumber (String line , int pos ) {
185- while (pos < line .length () && isNumberChar (line .charAt (pos ))) {
186- pos ++;
187- }
188- return pos ;
189- }
190-
191- private static boolean isNumberChar (char c ) {
192- return Character .isDigit (c ) || c == '.' || c == '-' || c == 'e' || c == 'E' ;
193- }
194- }
195-
196100 Measures extractPowerMeasure (InputStream powerMeasureInput , Long tick ) {
197101 final long start = System .currentTimeMillis ();
198102 try {
0 commit comments