Browse Source

Show statistics

Serj Kalichev 10 years ago
parent
commit
14a06b2da8
7 changed files with 33 additions and 3 deletions
  1. 1 0
      birq.c
  2. 1 0
      cpu.h
  3. 3 0
      cpu_parse.c
  4. 2 0
      irq.h
  5. 1 0
      irq_parse.c
  6. 24 3
      statistics.c
  7. 1 0
      statistics.h

+ 1 - 0
birq.c

@@ -183,6 +183,7 @@ int main(int argc, char **argv)
 		if (opts->debug)
 			printf("Some balancing...\n");
 		parse_proc_stat(cpus, irqs);
+		show_statistics(cpus);
 	}
 
 end:

+ 1 - 0
cpu.h

@@ -12,6 +12,7 @@ struct cpu_s {
 	unsigned long long old_load_all;
 	unsigned long long old_load_irq;
 	float load;
+	lub_list_t *irqs;
 };
 typedef struct cpu_s cpu_t;
 

+ 3 - 0
cpu_parse.c

@@ -14,6 +14,7 @@
 #include "lub/list.h"
 #include "cpumask.h"
 #include "cpu.h"
+#include "irq.h"
 
 #define STR(str) ( str ? str : "" )
 
@@ -34,12 +35,14 @@ static cpu_t * cpu_new(unsigned int id)
 	new->old_load_all = 0;
 	new->old_load_irq = 0;
 	new->load = 0;
+	new->irqs = lub_list_new(irq_list_compare);
 
 	return new;
 }
 
 static void cpu_free(cpu_t *cpu)
 {
+	lub_list_free(cpu->irqs);
 	free(cpu);
 }
 

+ 2 - 0
irq.h

@@ -2,6 +2,7 @@
 #define _irq_h
 
 #include "cpumask.h"
+#include "cpu.h"
 
 struct irq_s {
 	unsigned int irq;
@@ -11,6 +12,7 @@ struct irq_s {
 	cpumask_t local_cpus;
 	unsigned long long intr;
 	unsigned long long old_intr;
+	cpu_t *cpu;
 };
 typedef struct irq_s irq_t;
 

+ 1 - 0
irq_parse.c

@@ -34,6 +34,7 @@ static irq_t * irq_new(int num)
 	new->refresh = 1;
 	new->old_intr = 0;
 	new->intr = 0;
+	new->cpu = NULL;
 	return new;
 }
 

+ 24 - 3
statistics.c

@@ -86,8 +86,6 @@ void parse_proc_stat(lub_list_t *cpus, lub_list_t *irqs)
 
 		cpu->old_load_all = load_all;
 		cpu->old_load_irq = load_irq;
-
-		printf("CPU %u %.2f%%\n", cpunr, cpu->load);
 	}
 
 	/* Parse "intr" line. Get number of interrupts. */
@@ -111,9 +109,32 @@ void parse_proc_stat(lub_list_t *cpus, lub_list_t *irqs)
 		else
 			irq->intr = intr - irq->old_intr;
 		irq->old_intr = intr;
-		printf("IRQ %u %llu %s\n", irq->irq, irq->intr, irq->desc);
 	}
 
 	fclose(file);
 	free(line);
 }
+
+void show_statistics(lub_list_t *cpus)
+{
+	lub_list_node_t *iter;
+
+	for (iter = lub_list_iterator_init(cpus); iter;
+		iter = lub_list_iterator_next(iter)) {
+		cpu_t *cpu;
+		lub_list_node_t *irq_iter;
+
+		cpu = (cpu_t *)lub_list_node__get_data(iter);
+		printf("--------------------------------------------------------------------------------\n");
+		printf("CPU%u package %u, core %u, load %.2f%%\n",
+			cpu->id, cpu->package_id, cpu->core_id, cpu->load);
+
+		for (irq_iter = lub_list_iterator_init(cpu->irqs); irq_iter;
+		irq_iter = lub_list_iterator_next(irq_iter)) {
+			irq_t *irq;
+			irq = (irq_t *)lub_list_node__get_data(irq_iter);
+			printf("IRQ %u %llu %s\n", irq->irq, irq->intr, irq->desc);
+		}
+	}
+}
+

+ 1 - 0
statistics.h

@@ -4,5 +4,6 @@
 #include "lub/list.h"
 
 void parse_proc_stat(lub_list_t *cpus, lub_list_t *irqs);
+void show_statistics(lub_list_t *cpus);
 
 #endif