MCPcopy Create free account
hub / github.com/Tencent/phxqueue / GetCpuRate

Function GetCpuRate

phxqueue/comm/utils/load_util.cpp:159–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157
158
159void GetCpuRate(CpuInfo &oldinfo, CpuInfo &newinfo, CpuRate &rate) {
160 int64_t alldiff = newinfo.use - oldinfo.use +
161 newinfo.nice - oldinfo.nice +
162 newinfo.sys - oldinfo.sys +
163 newinfo.idle - oldinfo.idle +
164 newinfo.iowait - oldinfo.iowait +
165 newinfo.hardirq - oldinfo.hardirq +
166 newinfo.softirq - oldinfo.softirq;
167 if ( alldiff > 0 )
168 {
169 rate.userate = 100*(newinfo.use - oldinfo.use)/alldiff;
170 rate.sysrate = 100*(newinfo.sys - oldinfo.sys)/alldiff;
171 rate.iowaitrate = 100*(newinfo.iowait - oldinfo.iowait)/alldiff;
172 rate.hardirqrate = 100*(newinfo.hardirq - oldinfo.hardirq)/alldiff;
173 rate.softirqrate = 100*(newinfo.softirq - oldinfo.softirq)/alldiff;
174 oldinfo = newinfo;
175 NLInfo("use %llu sys %llu soft %llu", rate.userate, rate.sysrate, rate.softirqrate);
176 }
177}
178
179int GetCpu() {
180 static int cpu = 0;

Callers 1

GetCpuFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected