aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-02-09 09:30:13 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-02-10 10:58:45 -0500
commitd01bb4f5a3a179f3ce83882ab87a81ef088eb12f (patch)
treeab240ef3a4633d14fa973aa1ce78759cce7def2a
parent09f0fff83bbe3fe5a8c6b256a9533c44e3d7f14e (diff)
trace-graph: Add trace_graph_plot_insert() and remove()
Add a way to insert a plot in between other plots. Also add the removal of a plot. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-graph.h5
-rw-r--r--trace-plot.c77
2 files changed, 79 insertions, 3 deletions
diff --git a/trace-graph.h b/trace-graph.h
index 22ae29b..3344f87 100644
--- a/trace-graph.h
+++ b/trace-graph.h
@@ -224,6 +224,11 @@ void trace_graph_plot_init(struct graph_info *ginfo);
224void trace_graph_plot_append(struct graph_info *ginfo, 224void trace_graph_plot_append(struct graph_info *ginfo,
225 const char *label, const struct plot_callbacks *cb, 225 const char *label, const struct plot_callbacks *cb,
226 void *data); 226 void *data);
227void trace_graph_plot_insert(struct graph_info *ginfo,
228 int pos,
229 const char *label, const struct plot_callbacks *cb,
230 void *data);
231void trace_graph_plot_remove(struct graph_info *ginfo, int pos);
227 232
228int trace_graph_plot_match_time(struct graph_info *ginfo, 233int trace_graph_plot_match_time(struct graph_info *ginfo,
229 struct graph_plot *plot, 234 struct graph_plot *plot,
diff --git a/trace-plot.c b/trace-plot.c
index a158745..e684621 100644
--- a/trace-plot.c
+++ b/trace-plot.c
@@ -26,9 +26,10 @@ void trace_graph_plot_init(struct graph_info *ginfo)
26 ginfo->plot_list = NULL; 26 ginfo->plot_list = NULL;
27} 27}
28 28
29void trace_graph_plot_append(struct graph_info *ginfo, 29static struct graph_plot *
30 const char *label, const struct plot_callbacks *cb, 30allocate_plot(struct graph_info *ginfo,
31 void *data) 31 const char *label, const struct plot_callbacks *cb,
32 void *data)
32{ 33{
33 struct graph_plot *plot; 34 struct graph_plot *plot;
34 char *name; 35 char *name;
@@ -47,6 +48,17 @@ void trace_graph_plot_append(struct graph_info *ginfo,
47 plot->next = ginfo->plot_list; 48 plot->next = ginfo->plot_list;
48 ginfo->plot_list = plot; 49 ginfo->plot_list = plot;
49 50
51 return plot;
52}
53
54void trace_graph_plot_append(struct graph_info *ginfo,
55 const char *label, const struct plot_callbacks *cb,
56 void *data)
57{
58 struct graph_plot *plot;
59
60 plot = allocate_plot(ginfo, label, cb, data);
61
50 if (!ginfo->plots) { 62 if (!ginfo->plots) {
51 ginfo->plot_array = malloc_or_die(sizeof(ginfo->plot_array[0])); 63 ginfo->plot_array = malloc_or_die(sizeof(ginfo->plot_array[0]));
52 ginfo->plot_array[0] = plot; 64 ginfo->plot_array[0] = plot;
@@ -64,6 +76,65 @@ void trace_graph_plot_append(struct graph_info *ginfo,
64 ginfo->plots++; 76 ginfo->plots++;
65} 77}
66 78
79void trace_graph_plot_insert(struct graph_info *ginfo,
80 int pos,
81 const char *label, const struct plot_callbacks *cb,
82 void *data)
83{
84 struct graph_plot *plot;
85
86 if (pos >= ginfo->plots)
87 return trace_graph_plot_append(ginfo, label, cb, data);
88
89 if (pos < 0)
90 pos = 0;
91
92 plot = allocate_plot(ginfo, label, cb, data);
93
94 ginfo->plot_array = realloc(ginfo->plot_array,
95 sizeof(ginfo->plot_array[0]) *
96 (ginfo->plots + 1));
97
98 if (!ginfo->plot_array)
99 die("unable to resize plot array");
100
101 memmove(&ginfo->plot_array[pos+1], &ginfo->plot_array[pos],
102 sizeof(ginfo->plot_array[0]) * (ginfo->plots - pos));
103
104 ginfo->plot_array[pos] = plot;
105
106 ginfo->plots++;
107}
108
109void trace_graph_plot_remove(struct graph_info *ginfo, int pos)
110{
111 struct graph_plot **pplot;
112
113 if (pos < 0 || pos >= ginfo->plots || !ginfo->plots)
114 return;
115
116 for (pplot = &ginfo->plot_list; *pplot; pplot = &((*pplot)->next)) {
117
118 if (*pplot != ginfo->plot_array[pos])
119 continue;
120
121 *pplot = (*pplot)->next;
122 break;
123 }
124
125 free(ginfo->plot_array[pos]);
126
127 ginfo->plots--;
128
129 if (ginfo->plots) {
130 memmove(&ginfo->plot_array[pos], &ginfo->plot_array[pos+1],
131 sizeof(ginfo->plot_array[0]) * (ginfo->plots - pos));
132 } else {
133 free(ginfo->plot_array);
134 ginfo->plot_array = NULL;
135 }
136}
137
67int trace_graph_plot_match_time(struct graph_info *ginfo, 138int trace_graph_plot_match_time(struct graph_info *ginfo,
68 struct graph_plot *plot, 139 struct graph_plot *plot,
69 unsigned long long time) 140 unsigned long long time)