aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-02-10 16:10:10 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-02-10 16:10:10 -0500
commit6386dc2ff83f321883f5eecb40f0b6ab414f9e46 (patch)
treed0f2e424e7775953eeda6b722357cb41495579a8
parentdba6a8c6df54f095f31c14190a1a524710be3606 (diff)
trace-graph: Add destructor routine to plot callbacks
Added a destructor routine to the plot callbacks to be called before the plot is destroyed. This allows the plot to clean up any resources that it allocated before it is freed. Also did some other minor clean ups and freeing. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-graph.h4
-rw-r--r--trace-plot-cpu.c10
-rw-r--r--trace-plot-task.c8
-rw-r--r--trace-plot.c7
4 files changed, 24 insertions, 5 deletions
diff --git a/trace-graph.h b/trace-graph.h
index 57d3c3b..8e75dbb 100644
--- a/trace-graph.h
+++ b/trace-graph.h
@@ -53,6 +53,9 @@ struct graph_plot;
53 * display_info: 53 * display_info:
54 * display information about a given time. A resolution is 54 * display information about a given time. A resolution is
55 * passed in to show how much time is in 1 pixel. 55 * passed in to show how much time is in 1 pixel.
56 *
57 * destroy:
58 * destructor routine. Cleans up all resourses that the plot allocated.
56 */ 59 */
57struct plot_callbacks { 60struct plot_callbacks {
58 int (*match_time)(struct graph_info *, struct graph_plot *, 61 int (*match_time)(struct graph_info *, struct graph_plot *,
@@ -74,6 +77,7 @@ struct plot_callbacks {
74 int (*display_info)(struct graph_info *, struct graph_plot *, 77 int (*display_info)(struct graph_info *, struct graph_plot *,
75 struct trace_seq *s, 78 struct trace_seq *s,
76 unsigned long long time); 79 unsigned long long time);
80 void (*destroy)(struct graph_info *, struct graph_plot *);
77}; 81};
78 82
79struct graph_plot { 83struct graph_plot {
diff --git a/trace-plot-cpu.c b/trace-plot-cpu.c
index 6918ae4..7fd9ecc 100644
--- a/trace-plot-cpu.c
+++ b/trace-plot-cpu.c
@@ -4,7 +4,6 @@
4 4
5struct cpu_plot_info { 5struct cpu_plot_info {
6 int cpu; 6 int cpu;
7 struct record *record;
8 unsigned long long last_time; 7 unsigned long long last_time;
9 int last_pid; 8 int last_pid;
10}; 9};
@@ -177,7 +176,6 @@ static void cpu_plot_start(struct graph_info *ginfo, struct graph_plot *plot,
177 int cpu; 176 int cpu;
178 177
179 cpu = cpu_info->cpu; 178 cpu = cpu_info->cpu;
180 cpu_info->record = NULL;
181 cpu_info->last_time = 0ULL; 179 cpu_info->last_time = 0ULL;
182 cpu_info->last_pid = -1; 180 cpu_info->last_pid = -1;
183 181
@@ -396,6 +394,13 @@ int cpu_plot_display_info(struct graph_info *ginfo,
396 return 1; 394 return 1;
397} 395}
398 396
397void cpu_plot_destroy(struct graph_info *ginfo, struct graph_plot *plot)
398{
399 struct cpu_plot_info *cpu_info = plot->private;
400
401 free(cpu_info);
402}
403
399static const struct plot_callbacks cpu_plot_cb = { 404static const struct plot_callbacks cpu_plot_cb = {
400 .match_time = cpu_plot_match_time, 405 .match_time = cpu_plot_match_time,
401 .plot_event = cpu_plot_event, 406 .plot_event = cpu_plot_event,
@@ -403,6 +408,7 @@ static const struct plot_callbacks cpu_plot_cb = {
403 .display_last_event = cpu_plot_display_last_event, 408 .display_last_event = cpu_plot_display_last_event,
404 .find_record = cpu_plot_find_record, 409 .find_record = cpu_plot_find_record,
405 .display_info = cpu_plot_display_info, 410 .display_info = cpu_plot_display_info,
411 .destroy = cpu_plot_destroy
406}; 412};
407 413
408void graph_plot_init_cpus(struct graph_info *ginfo, int cpus) 414void graph_plot_init_cpus(struct graph_info *ginfo, int cpus)
diff --git a/trace-plot-task.c b/trace-plot-task.c
index f3b0c01..abe4025 100644
--- a/trace-plot-task.c
+++ b/trace-plot-task.c
@@ -532,6 +532,13 @@ int task_plot_display_info(struct graph_info *ginfo,
532 return 1; 532 return 1;
533} 533}
534 534
535void task_plot_destroy(struct graph_info *ginfo, struct graph_plot *plot)
536{
537 struct task_plot_info *task_info = plot->private;
538
539 free(task_info);
540}
541
535static const struct plot_callbacks task_plot_cb = { 542static const struct plot_callbacks task_plot_cb = {
536 .match_time = task_plot_match_time, 543 .match_time = task_plot_match_time,
537 .plot_event = task_plot_event, 544 .plot_event = task_plot_event,
@@ -539,6 +546,7 @@ static const struct plot_callbacks task_plot_cb = {
539 .display_last_event = task_plot_display_last_event, 546 .display_last_event = task_plot_display_last_event,
540 .find_record = task_plot_find_record, 547 .find_record = task_plot_find_record,
541 .display_info = task_plot_display_info, 548 .display_info = task_plot_display_info,
549 .destroy = task_plot_destroy
542}; 550};
543 551
544void graph_plot_init_tasks(struct graph_info *ginfo) 552void graph_plot_init_tasks(struct graph_info *ginfo)
diff --git a/trace-plot.c b/trace-plot.c
index 6531a5e..c6f7e7a 100644
--- a/trace-plot.c
+++ b/trace-plot.c
@@ -111,10 +111,11 @@ void trace_graph_plot_remove(struct graph_info *ginfo, struct graph_plot *plot)
111 int pos = plot->pos; 111 int pos = plot->pos;
112 int i; 112 int i;
113 113
114 if (pos < 0 || pos >= ginfo->plots || !ginfo->plots) 114 if (plot->cb->destroy)
115 return; 115 plot->cb->destroy(ginfo, plot);
116 116
117 free(ginfo->plot_array[pos]); 117 free(plot->label);
118 free(plot);
118 119
119 ginfo->plots--; 120 ginfo->plots--;
120 121