aboutsummaryrefslogtreecommitdiffstats
path: root/trace-plot-cpu.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-02-18 09:59:42 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-02-18 09:59:42 -0500
commitdf49e6a44d60740e6730e2b5255b53c900adc9a7 (patch)
tree381e23b44acdd509ca46ba749b9eb2ca578079e3 /trace-plot-cpu.c
parentea645651cdc0ab38fddeb9f81b13eccc9a22d98d (diff)
trace-graph: Added CPU plotting menu
Added menu for adding and removing CPU plots and Tasks. Only CPU updates have been implemented in this change set. Task updates will follow. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'trace-plot-cpu.c')
-rw-r--r--trace-plot-cpu.c111
1 files changed, 102 insertions, 9 deletions
diff --git a/trace-plot-cpu.c b/trace-plot-cpu.c
index e591f04..e99fec8 100644
--- a/trace-plot-cpu.c
+++ b/trace-plot-cpu.c
@@ -21,6 +21,7 @@
21#include <string.h> 21#include <string.h>
22 22
23#include "trace-graph.h" 23#include "trace-graph.h"
24#include "cpu.h"
24 25
25struct cpu_plot_info { 26struct cpu_plot_info {
26 int cpu; 27 int cpu;
@@ -385,7 +386,7 @@ int cpu_plot_display_info(struct graph_info *ginfo,
385 return 1; 386 return 1;
386} 387}
387 388
388void cpu_plot_destroy(struct graph_info *ginfo, struct graph_plot *plot) 389static void cpu_plot_destroy(struct graph_info *ginfo, struct graph_plot *plot)
389{ 390{
390 struct cpu_plot_info *cpu_info = plot->private; 391 struct cpu_plot_info *cpu_info = plot->private;
391 392
@@ -403,20 +404,112 @@ static const struct plot_callbacks cpu_plot_cb = {
403 .destroy = cpu_plot_destroy 404 .destroy = cpu_plot_destroy
404}; 405};
405 406
406void graph_plot_init_cpus(struct graph_info *ginfo, int cpus) 407static void add_cpu_plot(struct graph_info *ginfo, gint cpu)
407{ 408{
408 struct cpu_plot_info *cpu_info; 409 struct cpu_plot_info *cpu_info;
409 struct graph_plot *plot; 410 struct graph_plot *plot;
410 char label[100]; 411 char label[100];
411 long cpu;
412 412
413 for (cpu = 0; cpu < cpus; cpu++) { 413 cpu_info = malloc_or_die(sizeof(*cpu_info));
414 cpu_info = malloc_or_die(sizeof(*cpu_info)); 414 cpu_info->cpu = cpu;
415 cpu_info->cpu = cpu; 415
416 snprintf(label, 100, "CPU %d", cpu);
417
418 plot = trace_graph_plot_append(ginfo, label, PLOT_TYPE_CPU,
419 &cpu_plot_cb, cpu_info);
420 trace_graph_plot_add_cpu(ginfo, plot, cpu);
421}
422
423void graph_plot_cpus_update_callback(gboolean accept,
424 gboolean all_cpus,
425 guint64 *selected_cpu_mask,
426 gpointer data)
427{
428 struct graph_info *ginfo = data;
429 struct cpu_plot_info *cpu_info;
430 struct graph_plot *plot;
431 gboolean old_all_cpus;
432 guint64 *old_cpu_mask;
433 int i;
434
435 if (!accept)
436 return;
437
438 /* Get the current status */
439 graph_plot_cpus_plotted(ginfo, &old_all_cpus, &old_cpu_mask);
440
441 if (old_all_cpus == all_cpus ||
442 (selected_cpu_mask &&
443 cpus_equal(old_cpu_mask, selected_cpu_mask, ginfo->cpus))) {
444 /* Nothing to do */
445 g_free(old_cpu_mask);
446 return;
447 }
416 448
417 snprintf(label, 100, "CPU %ld", cpu); 449 if (!all_cpus) {
450 /*
451 * Remove any plots not selected.
452 * Go backwards, since removing a plot shifts the
453 * array from current position back.
454 */
455 for (i = ginfo->plots - 1; i >= 0; i--) {
456 plot = ginfo->plot_array[i];
457 if (plot->type != PLOT_TYPE_CPU)
458 continue;
459 cpu_info = plot->private;
460 if (!cpu_isset(selected_cpu_mask, cpu_info->cpu))
461 trace_graph_plot_remove(ginfo, plot);
462 }
463 }
418 464
419 plot = trace_graph_plot_append(ginfo, label, &cpu_plot_cb, cpu_info); 465 /* Now add any plots not set */
420 trace_graph_plot_add_cpu(ginfo, plot, cpu); 466 for (i = 0; i < ginfo->cpus; i++) {
467 if (!all_cpus && !cpu_isset(selected_cpu_mask, i))
468 continue;
469 if (cpu_isset(old_cpu_mask, i))
470 continue;
471 add_cpu_plot(ginfo, i);
421 } 472 }
473
474 g_free(old_cpu_mask);
475
476 trace_graph_refresh(ginfo);
477}
478
479/**
480 * graph_plot_cpus_plotted - return what CPUs are plotted
481 * @ginfo: the graph info structure
482 * @all_cpus: returns true if all CPUS are currently plotted
483 * @cpu_mask: returns an allocated mask of what cpus are set
484 *
485 * @cpu_mask must be freed with g_free() after this is called.
486 */
487void graph_plot_cpus_plotted(struct graph_info *ginfo,
488 gboolean *all_cpus, guint64 **cpu_mask)
489{
490 struct cpu_plot_info *cpu_info;
491 struct graph_plot *plot;
492 int i;
493
494 *cpu_mask = g_new0(guint64, (ginfo->cpus >> 6) + 1);
495 g_assert(*cpu_mask);
496
497 for (i = 0; i < ginfo->plots; i++) {
498 plot = ginfo->plot_array[i];
499 if (plot->type != PLOT_TYPE_CPU)
500 continue;
501 cpu_info = plot->private;
502 cpu_set(*cpu_mask, cpu_info->cpu);
503 }
504
505 *all_cpus = cpu_weight(*cpu_mask, ginfo->cpus) == ginfo->cpus ?
506 TRUE : FALSE;
507}
508
509void graph_plot_init_cpus(struct graph_info *ginfo, int cpus)
510{
511 long cpu;
512
513 for (cpu = 0; cpu < cpus; cpu++)
514 add_cpu_plot(ginfo, cpu);
422} 515}