winlin

refine the disk iops stat, get cpu info.

@@ -74,9 +74,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -74,9 +74,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74 74
75 // update the disk iops interval: 75 // update the disk iops interval:
76 // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_DISK_STAT_RESOLUTION_TIMES 76 // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_DISK_STAT_RESOLUTION_TIMES
77 -// @remark, depends on SRS_SYS_CPU_STAT_RESOLUTION_TIMES, for the disk util  
78 -// depends on cpu time, so the disk stat times must be times of cpu stat time.  
79 -// for example, when cpu is 30, disk must be 30*1 or 30*2 ..., 30*N is ok.  
80 #define SRS_SYS_DISK_STAT_RESOLUTION_TIMES 60 77 #define SRS_SYS_DISK_STAT_RESOLUTION_TIMES 60
81 78
82 // update rusage interval: 79 // update rusage interval:
@@ -490,6 +490,9 @@ void srs_update_disk_stat() @@ -490,6 +490,9 @@ void srs_update_disk_stat()
490 if (!srs_get_disk_diskstats_stat(r)) { 490 if (!srs_get_disk_diskstats_stat(r)) {
491 return; 491 return;
492 } 492 }
  493 + if (!get_proc_system_stat(r.cpu)) {
  494 + return;
  495 + }
493 496
494 SrsDiskStat& o = _srs_disk_stat; 497 SrsDiskStat& o = _srs_disk_stat;
495 if (!o.ok) { 498 if (!o.ok) {
@@ -513,16 +516,16 @@ void srs_update_disk_stat() @@ -513,16 +516,16 @@ void srs_update_disk_stat()
513 } 516 }
514 517
515 // diskstats 518 // diskstats
516 - if (true) {  
517 - SrsProcSystemStat* cpu = srs_get_system_proc_stat(); 519 + if (r.cpu.ok && o.cpu.ok) {
518 SrsCpuInfo* cpuinfo = srs_get_cpuinfo(); 520 SrsCpuInfo* cpuinfo = srs_get_cpuinfo();
  521 + r.cpu.total_delta = r.cpu.total() - o.cpu.total();
519 522
520 - if (cpu->ok && cpu->total_delta > 0 523 + if (r.cpu.ok && r.cpu.total_delta > 0
521 && cpuinfo->ok && cpuinfo->nb_processors > 0 524 && cpuinfo->ok && cpuinfo->nb_processors > 0
522 && o.ticks < r.ticks 525 && o.ticks < r.ticks
523 ) { 526 ) {
524 // @see: print_partition_stats() of iostat.c 527 // @see: print_partition_stats() of iostat.c
525 - double delta_ms = cpu->total_delta * 10 / cpuinfo->nb_processors; 528 + double delta_ms = r.cpu.total_delta * 10 / cpuinfo->nb_processors;
526 unsigned int ticks = r.ticks - o.ticks; 529 unsigned int ticks = r.ticks - o.ticks;
527 530
528 // busy in [0, 1], where 0.1532 means 15.32% 531 // busy in [0, 1], where 0.1532 means 15.32%
@@ -341,6 +341,8 @@ public: @@ -341,6 +341,8 @@ public:
341 // @see: print_partition_stats() of iostat.c 341 // @see: print_partition_stats() of iostat.c
342 // but its value is [0, +], for instance, 0.1532 means 15.32%. 342 // but its value is [0, +], for instance, 0.1532 means 15.32%.
343 float busy; 343 float busy;
  344 + // for stat the busy%
  345 + SrsProcSystemStat cpu;
344 346
345 public: 347 public:
346 // @see: cat /proc/vmstat 348 // @see: cat /proc/vmstat