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

get self proc and system proc stat

This commit is contained in:
winlin 2014-04-19 21:43:13 +08:00
parent 117fd67950
commit 951a93ab86
5 changed files with 156 additions and 20 deletions

View file

@ -81,30 +81,30 @@ void srs_update_system_rusage()
_srs_system_rusage.ok = true;
}
static SrsCpuSelfStat _srs_system_cpu_self_stat;
static SrsCpuSystemStat _srs_system_cpu_system_stat;
static SrsProcSelfStat _srs_system_cpu_self_stat;
static SrsProcSystemStat _srs_system_cpu_system_stat;
SrsCpuSelfStat::SrsCpuSelfStat()
SrsProcSelfStat::SrsProcSelfStat()
{
ok = false;
}
SrsCpuSystemStat::SrsCpuSystemStat()
SrsProcSystemStat::SrsProcSystemStat()
{
ok = false;
}
SrsCpuSelfStat* srs_get_self_cpu_stat()
SrsProcSelfStat* srs_get_self_proc_stat()
{
return &_srs_system_cpu_self_stat;
}
SrsCpuSystemStat* srs_get_system_cpu_stat()
SrsProcSystemStat* srs_get_system_proc_stat()
{
return &_srs_system_cpu_system_stat;
}
void srs_update_system_cpu_stat()
void srs_update_proc_stat()
{
// system cpu stat
if (true) {
@ -114,7 +114,7 @@ void srs_update_system_cpu_stat()
return;
}
SrsCpuSystemStat& r = _srs_system_cpu_system_stat;
SrsProcSystemStat& r = _srs_system_cpu_system_stat;
for (;;) {
int ret = fscanf(f, "%4s %lu %lu %lu %lu %lu "
"%lu %lu %lu %lu\n",
@ -143,7 +143,7 @@ void srs_update_system_cpu_stat()
return;
}
SrsCpuSelfStat& r = _srs_system_cpu_self_stat;
SrsProcSelfStat& r = _srs_system_cpu_self_stat;
int ret = fscanf(f, "%d %32s %c %d %d %d %d "
"%d %u %lu %lu %lu %lu "
"%lu %lu %ld %ld %ld %ld "

View file

@ -52,7 +52,7 @@ extern SrsRusage* srs_get_system_rusage();
extern void srs_update_system_rusage();
// @see: man 5 proc, /proc/[pid]/stat
struct SrsCpuSelfStat
struct SrsProcSelfStat
{
// whether the data is ok.
bool ok;
@ -195,11 +195,11 @@ struct SrsCpuSelfStat
// Guest time of the processs children, measured in clock ticks (divide by sysconf(_SC_CLK_TCK).
long cguest_time;
SrsCpuSelfStat();
SrsProcSelfStat();
};
// @see: man 5 proc, /proc/stat
struct SrsCpuSystemStat
struct SrsProcSystemStat
{
// whether the data is ok.
bool ok;
@ -238,14 +238,14 @@ struct SrsCpuSystemStat
// operating systems under the control of the Linux kernel.
unsigned long guest;
SrsCpuSystemStat();
SrsProcSystemStat();
};
// get system cpu stat, use cache to avoid performance problem.
extern SrsCpuSelfStat* srs_get_self_cpu_stat();
extern SrsProcSelfStat* srs_get_self_proc_stat();
// get system cpu stat, use cache to avoid performance problem.
extern SrsCpuSystemStat* srs_get_system_cpu_stat();
extern SrsProcSystemStat* srs_get_system_proc_stat();
// the deamon st-thread will update it.
extern void srs_update_system_cpu_stat();
extern void srs_update_proc_stat();
#endif