Skip to content

Commit

Permalink
trace-graph: Iterate over all records for all plots
Browse files Browse the repository at this point in the history
Change the code to iterate once down all records to create all plots.
Use the cpu_hash, task_hash and all_recs to find what plot cares about what
data.

Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
Steven Rostedt authored and rostedt committed Feb 11, 2010
1 parent d3e8c13 commit 05e14e9
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 172 deletions.
167 changes: 91 additions & 76 deletions trace-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1406,25 +1406,13 @@ static void draw_plot_box(struct graph_info *ginfo, int i,
x2 - x1, PLOT_BOX_SIZE);
}

static void draw_plot(struct graph_info *ginfo, gint i,
gint new_width, gboolean read_comms)
static void draw_plot(struct graph_info *ginfo, struct graph_plot *plot,
struct record *record)
{
static PangoFontDescription *font;
PangoLayout *layout;
gint height = PLOT_LINE(i);
struct graph_plot *plot = ginfo->plot_array[i];
static GdkGC *gc;
static gint width_16;
guint64 ts;
gint lcolor;
gint bcolor;
gint last_color = -1;
gboolean box;
gboolean line;
unsigned long long ltime;
unsigned long long bstart;
unsigned long long bend;
gint p1 = 0, p2 = 0, p3 = 0;
struct plot_info info;
gint x;

/* Calculate the size of 16 characters */
Expand All @@ -1442,87 +1430,117 @@ static void draw_plot(struct graph_info *ginfo, gint i,
g_object_unref(layout);
}

if (!gc)
gc = gdk_gc_new(ginfo->draw->window);
trace_graph_plot_event(ginfo, plot, record, &info);

gdk_draw_line(ginfo->curr_pixmap, ginfo->draw->style->black_gc,
0, height, new_width, height);
if (info.box) {
if (info.bcolor != plot->last_color) {
plot->last_color = info.bcolor;
set_color(ginfo->draw, plot->gc, plot->last_color);
}

ts = ginfo->view_start_time;
draw_plot_box(ginfo, plot->pos, info.bstart, info.bend, plot->gc);
}

trace_graph_plot_start(ginfo, plot, ts);
if (info.line) {
if (info.lcolor != plot->last_color) {
plot->last_color = info.lcolor;
set_color(ginfo->draw, plot->gc, plot->last_color);
}

set_color(ginfo->draw, gc, last_color);
x = draw_plot_line(ginfo, plot->pos, info.ltime, plot->gc);

while (trace_graph_plot_event(ginfo, plot,
&line, &lcolor, &ltime,
&box, &bcolor, &bstart, &bend)) {
/* Figure out if we can show the text for the previous record */

/* really should not happen */
if (!line && !box)
continue;
plot->p3 = x;

if (box) {
if (bcolor != last_color) {
last_color = bcolor;
set_color(ginfo->draw, gc, last_color);
}
/* Make sure p2 will be non-zero the next iteration */
if (!plot->p3)
plot->p3 = 1;

draw_plot_box(ginfo, i, bstart, bend, gc);
}
/* first record, continue */
if (plot->p2)
plot->p2 = draw_event_label(ginfo, plot->pos,
plot->p1, plot->p2, plot->p3, width_16, font);

if (line) {
plot->p1 = plot->p2;
plot->p2 = plot->p3;
}

if (lcolor != last_color) {
last_color = lcolor;
set_color(ginfo->draw, gc, last_color);
}
if (!record && plot->p2)
draw_event_label(ginfo, plot->pos,
plot->p1, plot->p2, ginfo->draw_width, width_16, font);
}

x = draw_plot_line(ginfo, i, ltime, gc);
static void draw_plots(struct graph_info *ginfo, gint new_width)
{
struct plot_list *list;
struct graph_plot *plot;
struct record *record;
struct plot_hash *hash;
gint pid;
gint cpu;
gint i;

/* Figure out if we can show the text for the previous record */
/* Initialize plots */
for (i = 0; i < ginfo->plots; i++) {
plot = ginfo->plot_array[i];

p3 = x;
if (!plot->gc)
plot->gc = gdk_gc_new(ginfo->draw->window);
plot->p1 = 0;
plot->p2 = 0;
plot->p3 = 0;
plot->last_color = -1;

/* Make sure p2 will be non-zero the next iteration */
if (!p3)
p3 = 1;
gdk_draw_line(ginfo->curr_pixmap, ginfo->draw->style->black_gc,
0, PLOT_LINE(i), new_width, PLOT_LINE(i));

/* first record, continue */
if (p2)
p2 = draw_event_label(ginfo, i,
p1, p2, p3, width_16, font);
trace_graph_plot_start(ginfo, plot, ginfo->view_start_time);

p1 = p2;
p2 = p3;
}
set_color(ginfo->draw, plot->gc, plot->last_color);
}

if (box) {
if (bcolor != last_color) {
last_color = bcolor;
set_color(ginfo->draw, gc, last_color);
/* Shortcut if we don't have any task plots */
if (!ginfo->nr_task_hash && !ginfo->all_recs) {
for (cpu = 0; cpu < ginfo->cpus; cpu++) {
hash = trace_graph_plot_find_cpu(ginfo, cpu);
if (!hash)
continue;

while ((record = tracecmd_read_data(ginfo->handle, cpu))) {
for (list = hash->plots; list; list = list->next)
draw_plot(ginfo, list->plot, record);
free_record(record);
}
}

draw_plot_box(ginfo, i, bstart, bend, gc);
goto out;
}

if (line) {
if (lcolor != last_color) {
last_color = lcolor;
set_color(ginfo->draw, gc, last_color);
while ((record = tracecmd_read_next_data(ginfo->handle, &cpu))) {
hash = trace_graph_plot_find_cpu(ginfo, cpu);
if (hash) {
for (list = hash->plots; list; list = list->next)
draw_plot(ginfo, list->plot, record);
}

draw_plot_line(ginfo, i, ltime, gc);
pid = pevent_data_pid(ginfo->pevent, record);
hash = trace_graph_plot_find_task(ginfo, pid);
if (hash) {
for (list = hash->plots; list; list = list->next)
draw_plot(ginfo, list->plot, record);
}
for (list = ginfo->all_recs; list; list = list->next)
draw_plot(ginfo, list->plot, record);
free_record(record);
}

if (p2)
draw_event_label(ginfo, i,
p1, p2, ginfo->draw_width, width_16, font);

trace_graph_plot_end(ginfo, plot);

return;
out:
for (i = 0; i < ginfo->plots; i++) {
plot = ginfo->plot_array[i];
draw_plot(ginfo, plot, NULL);
trace_graph_plot_end(ginfo, plot);
gdk_gc_unref(plot->gc);
plot->gc = NULL;
}
}


Expand Down Expand Up @@ -1614,8 +1632,6 @@ static void draw_timeline(struct graph_info *ginfo, gint width)
static void draw_info(struct graph_info *ginfo,
gint new_width)
{
gint i;

if (!ginfo->handle)
return;

Expand All @@ -1626,8 +1642,7 @@ static void draw_info(struct graph_info *ginfo,

draw_timeline(ginfo, new_width);

for (i = 0; i < ginfo->plots; i++)
draw_plot(ginfo, i, new_width, ginfo->read_comms);
draw_plots(ginfo, new_width);

ginfo->read_comms = FALSE;
}
Expand Down
38 changes: 25 additions & 13 deletions trace-graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ typedef void (graph_filter_cb)(struct graph_info *ginfo,

struct graph_plot;

struct plot_info {
gboolean line;
int lcolor;
unsigned long long ltime;
gboolean box;
int bcolor;
unsigned long long bstart;
unsigned long long bend;
};

/*
* match_time:
* Return true if a selected time should expose plot.
Expand All @@ -25,8 +35,7 @@ struct graph_plot;
* to start plotting.
*
* plot_event:
* This is called by the plotter. Return 1 to plot an event or
* 0 to stop the plotting.
* This is called by the plotter.
* color returns the color that should be printed.
* line returns 1 or 0 if a line should be drawn.
* ltime returns the time that the line should be drawn at
Expand All @@ -36,7 +45,6 @@ struct graph_plot;
* bend is the time the box ends at
* (bstart and bend are ignored if box is 0)
* time is the time of the current event
* (box and line can be true and processed even if the func returns 0)
*
* end:
* called at the end of the plotting in case the plotter needs to
Expand Down Expand Up @@ -64,11 +72,8 @@ struct plot_callbacks {
unsigned long long time);
int (*plot_event)(struct graph_info *ginfo,
struct graph_plot *plot,
gboolean *line, int *lcolor,
unsigned long long *ltime,
gboolean *box, int *bcolor,
unsigned long long *bstart,
unsigned long long *bend);
struct record *record,
struct plot_info *info);
void (*end)(struct graph_info *, struct graph_plot *);
int (*display_last_event)(struct graph_info *ginfo, struct graph_plot *plot,
struct trace_seq *s, unsigned long long time);
Expand All @@ -85,6 +90,11 @@ struct graph_plot {
char *label;
const struct plot_callbacks *cb;
void *private;

/* Used for drawing */
gint last_color;
gint p1, p2, p3;
GdkGC *gc;
};

struct graph_callbacks {
Expand Down Expand Up @@ -117,6 +127,7 @@ struct graph_info {
gint nr_task_hash;
struct plot_hash *task_hash[PLOT_HASH_SIZE];
struct plot_hash *cpu_hash[PLOT_HASH_SIZE];
struct plot_list *all_recs;

GtkWidget *widget; /* Box to hold graph */
GtkWidget *scrollwin; /* graph scroll window */
Expand Down Expand Up @@ -263,6 +274,10 @@ void trace_graph_plot_add_cpu(struct graph_info *ginfo, struct graph_plot *plot,
gint cpu);
void trace_graph_plot_remove_cpu(struct graph_info *ginfo, struct graph_plot *plot,
gint cpu);
void trace_graph_plot_add_all_recs(struct graph_info *ginfo,
struct graph_plot *plot);
void trace_graph_plot_remove_all_recs(struct graph_info *ginfo,
struct graph_plot *plot);

/* plot callbacks */
int trace_graph_plot_match_time(struct graph_info *ginfo,
Expand All @@ -280,11 +295,8 @@ void trace_graph_plot_start(struct graph_info *ginfo,

int trace_graph_plot_event(struct graph_info *ginfo,
struct graph_plot *plot,
gboolean *line, int *lcolor,
unsigned long long *ltime,
gboolean *box, int *bcolor,
unsigned long long *bstart,
unsigned long long *bend);
struct record *record,
struct plot_info *info);

void trace_graph_plot_end(struct graph_info *ginfo,
struct graph_plot *plot);
Expand Down
31 changes: 12 additions & 19 deletions trace-plot-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,10 @@ static void cpu_plot_start(struct graph_info *ginfo, struct graph_plot *plot,

static int cpu_plot_event(struct graph_info *ginfo,
struct graph_plot *plot,
gboolean *line, int *lcolor,
unsigned long long *ltime,
gboolean *box, int *bcolor,
unsigned long long *bstart,
unsigned long long *bend)
struct record *record,
struct plot_info *info)
{
struct cpu_plot_info *cpu_info = plot->private;
struct record *record;
int sched_pid;
int orig_pid;
int is_sched_switch;
Expand All @@ -222,14 +218,13 @@ static int cpu_plot_event(struct graph_info *ginfo,
int ret = 1;

cpu = cpu_info->cpu;
record = tracecmd_read_data(ginfo->handle, cpu);

if (!record) {
/* Finish a box if the last record was not idle */
if (cpu_info->last_pid > 0) {
*box = TRUE;
*bstart = cpu_info->last_time;
*bend = ginfo->view_end_time;
info->box = TRUE;
info->bstart = cpu_info->last_time;
info->bend = ginfo->view_end_time;
}
return 0;
}
Expand All @@ -255,28 +250,26 @@ static int cpu_plot_event(struct graph_info *ginfo,
box_filter = trace_graph_filter_on_task(ginfo, orig_pid);

if (!box_filter && cpu_info->last_pid) {
*bcolor = hash_pid(cpu_info->last_pid);
*box = TRUE;
*bstart = cpu_info->last_time;
*bend = record->ts;
info->bcolor = hash_pid(cpu_info->last_pid);
info->box = TRUE;
info->bstart = cpu_info->last_time;
info->bend = record->ts;
}

cpu_info->last_time = record->ts;
}

if (!filter && !trace_graph_filter_on_event(ginfo, record)) {
*line = TRUE;
*ltime = record->ts;
*lcolor = hash_pid(pid);
info->line = TRUE;
info->ltime = record->ts;
info->lcolor = hash_pid(pid);
}

cpu_info->last_pid = pid;

if (record->ts > ginfo->view_end_time)
ret = 0;

free_record(record);

return ret;
}

Expand Down
Loading

0 comments on commit 05e14e9

Please sign in to comment.