MCPcopy Create free account
hub / github.com/esnet/iperf / cpu_util

Function cpu_util

src/iperf_util.c:189–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187}
188
189void
190cpu_util(double pcpu[3])
191{
192 static struct iperf_time last;
193 static clock_t clast;
194 static struct rusage rlast;
195 struct iperf_time now, temp_time;
196 clock_t ctemp;
197 struct rusage rtemp;
198 double timediff;
199 double userdiff;
200 double systemdiff;
201
202 if (pcpu == NULL) {
203 iperf_time_now(&last);
204 clast = clock();
205 getrusage(RUSAGE_SELF, &rlast);
206 return;
207 }
208
209 iperf_time_now(&now);
210 ctemp = clock();
211 getrusage(RUSAGE_SELF, &rtemp);
212
213 iperf_time_diff(&now, &last, &temp_time);
214 timediff = iperf_time_in_usecs(&temp_time);
215
216 userdiff = ((rtemp.ru_utime.tv_sec * 1000000.0 + rtemp.ru_utime.tv_usec) -
217 (rlast.ru_utime.tv_sec * 1000000.0 + rlast.ru_utime.tv_usec));
218 systemdiff = ((rtemp.ru_stime.tv_sec * 1000000.0 + rtemp.ru_stime.tv_usec) -
219 (rlast.ru_stime.tv_sec * 1000000.0 + rlast.ru_stime.tv_usec));
220
221 pcpu[0] = (((ctemp - clast) * 1000000.0 / CLOCKS_PER_SEC) / timediff) * 100;
222 pcpu[1] = (userdiff / timediff) * 100;
223 pcpu[2] = (systemdiff / timediff) * 100;
224}
225
226const char *
227get_system_info(void)

Callers 5

iperf_got_sigendFunction · 0.85
iperf_run_clientFunction · 0.85
iperf_run_serverFunction · 0.85

Calls 3

iperf_time_nowFunction · 0.85
iperf_time_diffFunction · 0.85
iperf_time_in_usecsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…