1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix #397, the USER_HZ maybe not 100. 2.0.165

This commit is contained in:
winlin 2015-05-22 17:08:26 +08:00
parent c17a1198cb
commit 6ca46e84bc
3 changed files with 13 additions and 10 deletions

View file

@ -418,15 +418,13 @@ bool get_proc_self_stat(SrsProcSelfStat& r)
void srs_update_proc_stat()
{
// always assert the USER_HZ is 1/100ths
// @see: http://stackoverflow.com/questions/7298646/calculating-user-nice-sys-idle-iowait-irq-and-sirq-from-proc-stat/7298711
static bool user_hz_assert = false;
if (!user_hz_assert) {
user_hz_assert = true;
int USER_HZ = sysconf(_SC_CLK_TCK);
srs_trace("USER_HZ=%d", USER_HZ);
srs_assert(USER_HZ == 100);
// @see https://github.com/simple-rtmp-server/srs/issues/397
static int user_hz = 0;
if (user_hz <= 0) {
user_hz = sysconf(_SC_CLK_TCK);
srs_trace("USER_HZ=%d", user_hz);
srs_assert(user_hz > 0);
}
// system cpu stat
@ -471,7 +469,7 @@ void srs_update_proc_stat()
int64_t total = r.sample_time - o.sample_time;
int64_t usage = (r.utime + r.stime) - (o.utime + o.stime);
if (total > 0) {
r.percent = (float)(usage * 1000 / (double)total / 100);
r.percent = (float)(usage * 1000 / (double)total / user_hz);
}
// upate cache.