MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / start

Method start

libapp2sys/src/main/cpp/procutil.h:202–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200
201public:
202 int start(uint32_t linuxTid, uint64_t sampleRateMS = 15) {
203 m_startUnixTime = getMillisecond();
204 m_sumCpuLoad = 0;
205 m_linuxTid = linuxTid;
206 m_sampleRateUS = sampleRateMS * 1000;
207
208 if (CPU_COUNT <= 0 || m_linuxTid <= 0) {
209 return -1;
210 }
211
212 char buf[64];
213 m_ppCpuFfreqReader = new ProcFileReader *[CPU_COUNT];
214 for (int i = 0; i < CPU_COUNT; i++) {
215 sprintf(buf, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i);
216 m_ppCpuFfreqReader[i] = new ProcFileReader(buf);
217 }
218 sprintf(buf, "/proc/self/task/%d/stat", m_linuxTid);
219 m_pStatReader = new ProcFileReader(buf);
220 m_pStatReader->update();
221 m_lastJiffies = m_pStatReader->getValue(STAT_USER_JIFFIES_INDEX) + m_pStatReader->getValue(STAT_SYS_JIFFIES_INDEX);
222
223 if (m_lastJiffies < 0) {
224 return -2;
225 }
226
227 m_running = 1;
228 pthread_create(&m_thr, NULL, monitorThread, this);
229 return 0;
230 }
231
232 int stop(uint64_t &runUnixTime, uint64_t &cpuLoad) {
233 runUnixTime = getMillisecond() - m_startUnixTime;

Callers

nothing calls this directly

Calls 3

getMillisecondFunction · 0.85
getValueMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected