Browse Source

Save old_load for CPU

Serj Kalichev 10 years ago
parent
commit
4e2ee94f13
3 changed files with 5 additions and 2 deletions
  1. 1 0
      cpu.h
  2. 1 0
      cpu_parse.c
  3. 3 2
      statistics.c

+ 1 - 0
cpu.h

@@ -11,6 +11,7 @@ struct cpu_s {
 	cpumask_t cpumask; /* Mask with one bit set - current CPU. */
 	cpumask_t cpumask; /* Mask with one bit set - current CPU. */
 	unsigned long long old_load_all; /* Previous whole load from /proc/stat */
 	unsigned long long old_load_all; /* Previous whole load from /proc/stat */
 	unsigned long long old_load_irq; /* Previous IRQ, softIRQ load */
 	unsigned long long old_load_irq; /* Previous IRQ, softIRQ load */
+	float old_load; /* Previous CPU load in percents. */
 	float load; /* Current CPU load in percents. */
 	float load; /* Current CPU load in percents. */
 	lub_list_t *irqs; /* List of IRQs belong to this CPU. */
 	lub_list_t *irqs; /* List of IRQs belong to this CPU. */
 };
 };

+ 1 - 0
cpu_parse.c

@@ -39,6 +39,7 @@ static cpu_t * cpu_new(unsigned int id)
 	new->id = id;
 	new->id = id;
 	new->old_load_all = 0;
 	new->old_load_all = 0;
 	new->old_load_irq = 0;
 	new->old_load_irq = 0;
+	new->old_load = 0;
 	new->load = 0;
 	new->load = 0;
 	new->irqs = lub_list_new(irq_list_compare);
 	new->irqs = lub_list_new(irq_list_compare);
 	cpus_clear(new->cpumask);
 	cpus_clear(new->cpumask);

+ 3 - 2
statistics.c

@@ -76,6 +76,7 @@ void gather_statistics(lub_list_t *cpus, lub_list_t *irqs)
 			l_irq + l_softirq + l_steal + l_guest + l_guest_nice;
 			l_irq + l_softirq + l_steal + l_guest + l_guest_nice;
 		load_irq = l_irq + l_softirq;
 		load_irq = l_irq + l_softirq;
 
 
+		cpu->old_load = cpu->load;
 		if (cpu->old_load_all == 0) {
 		if (cpu->old_load_all == 0) {
 			/* When old_load_all = 0 - it's first iteration */
 			/* When old_load_all = 0 - it's first iteration */
 			cpu->load = 0;
 			cpu->load = 0;
@@ -126,9 +127,9 @@ void show_statistics(lub_list_t *cpus, int verbose)
 		lub_list_node_t *irq_iter;
 		lub_list_node_t *irq_iter;
 
 
 		cpu = (cpu_t *)lub_list_node__get_data(iter);
 		cpu = (cpu_t *)lub_list_node__get_data(iter);
-		printf("CPU%u package %u, core %u, irqs %d, load %.2f%%\n",
+		printf("CPU%u package %u, core %u, irqs %d, old %.2f%%, load %.2f%%\n",
 			cpu->id, cpu->package_id, cpu->core_id,
 			cpu->id, cpu->package_id, cpu->core_id,
-			lub_list_len(cpu->irqs), cpu->load);
+			lub_list_len(cpu->irqs), cpu->old_load, cpu->load);
 
 
 		if (!verbose)
 		if (!verbose)
 			continue;
 			continue;