aboutsummaryrefslogtreecommitdiffstats
path: root/trace-graph.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2009-12-17 17:34:33 -0500
committerSteven Rostedt <rostedt@goodmis.org>2009-12-17 22:55:27 -0500
commit0e861e7f795e33abb4d20e191ba97c36525ed0b3 (patch)
treec8b6a33b5ef10877d74420360a06dbc5830524ac /trace-graph.c
parent540cf9cdbfaa7190f07d5c20a4a2d720601858b4 (diff)
trace-graph: Add labels when enough room permits
Add labels to the graph if there's enough room to show them. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'trace-graph.c')
-rw-r--r--trace-graph.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/trace-graph.c b/trace-graph.c
index b2ff3b2..1f5e4cf 100644
--- a/trace-graph.c
+++ b/trace-graph.c
@@ -654,17 +654,88 @@ static void set_color_by_pid(GtkWidget *widget, GdkGC *gc, gint pid)
654 gdk_gc_set_foreground(gc, &color); 654 gdk_gc_set_foreground(gc, &color);
655} 655}
656 656
657static void draw_event_label(struct graph_info *ginfo, gint cpu,
658 gint event_id, gint pid,
659 gint p1, gint p2, gint p3,
660 gint width_16, PangoFontDescription *font)
661{
662 struct event *event;
663 PangoLayout *layout;
664 struct trace_seq s;
665 gint text_width;
666 gint text_height;
667 gint x, y;
668
669
670 /* No room to print */
671 if (((p3 - p2) < width_16 / 2 ||
672 (p2 - p1) < width_16 / 2))
673 return;
674
675 /* Check if we can show some data */
676
677 event = pevent_data_event_from_type(ginfo->pevent, event_id);
678
679 trace_seq_init(&s);
680 trace_seq_printf(&s, "%s-%d\n%s\n",
681 pevent_data_comm_from_pid(ginfo->pevent, pid),
682 pid, event->name);
683
684 layout = gtk_widget_create_pango_layout(ginfo->draw, s.buffer);
685 pango_layout_set_font_description(layout, font);
686
687 pango_layout_get_pixel_size(layout, &text_width, &text_height);
688
689 if ((p3 - p2) < text_width / 2 ||
690 (p2 - p1) < text_width / 2) {
691 g_object_unref(layout);
692 return;
693 }
694
695 x = p2 - text_width / 2;
696 y = (CPU_TOP(cpu) - text_height + 5);
697 gdk_draw_layout(ginfo->curr_pixmap, ginfo->draw->style->black_gc,
698 x, y, layout);
699
700
701 gdk_draw_line(ginfo->curr_pixmap, ginfo->draw->style->black_gc,
702 p2, CPU_TOP(cpu) - 5, p2, CPU_TOP(cpu) - 1);
703
704 g_object_unref(layout);
705}
706
657static void draw_cpu(struct graph_info *ginfo, gint cpu, 707static void draw_cpu(struct graph_info *ginfo, gint cpu,
658 gint new_width) 708 gint new_width)
659{ 709{
710 static PangoFontDescription *font;
711 PangoLayout *layout;
660 gint height = CPU_MIDDLE(cpu); 712 gint height = CPU_MIDDLE(cpu);
661 struct record *record; 713 struct record *record;
662 static GdkGC *gc; 714 static GdkGC *gc;
715 static gint width_16;
663 guint64 ts; 716 guint64 ts;
664 gint last_pid = -1; 717 gint last_pid = -1;
665 gint last_x = 0; 718 gint last_x = 0;
666 gint pid; 719 gint pid;
667 gint x; 720 gint x;
721 gint p1 = 0, p2 = 0, p3 = 0;
722 gint last_event_id = 0;
723 gint event_id;
724
725 /* Calculate the size of 16 characters */
726 if (!width_16) {
727 gchar buf[17];
728 gint text_height;
729
730 memset(buf, 'a', 16);
731 buf[16] = 0;
732
733 font = pango_font_description_from_string("Sans 8");
734 layout = gtk_widget_create_pango_layout(ginfo->draw, buf);
735 pango_layout_set_font_description(layout, font);
736 pango_layout_get_pixel_size(layout, &width_16, &text_height);
737 g_object_unref(layout);
738 }
668 739
669 if (!gc) 740 if (!gc)
670 gc = gdk_gc_new(ginfo->draw->window); 741 gc = gdk_gc_new(ginfo->draw->window);
@@ -689,6 +760,8 @@ static void draw_cpu(struct graph_info *ginfo, gint cpu,
689 if (!check_sched_switch(ginfo, record, &pid, NULL)) 760 if (!check_sched_switch(ginfo, record, &pid, NULL))
690 pid = pevent_data_pid(ginfo->pevent, record); 761 pid = pevent_data_pid(ginfo->pevent, record);
691 762
763 event_id = pevent_data_type(ginfo->pevent, record);
764
692 if (last_pid != pid) { 765 if (last_pid != pid) {
693 766
694 if (last_pid < 0) 767 if (last_pid < 0)
@@ -711,9 +784,29 @@ static void draw_cpu(struct graph_info *ginfo, gint cpu,
711 784
712 gdk_draw_line(ginfo->curr_pixmap, gc, // ginfo->draw->style->black_gc, 785 gdk_draw_line(ginfo->curr_pixmap, gc, // ginfo->draw->style->black_gc,
713 x, CPU_TOP(cpu), x, CPU_BOTTOM(cpu)); 786 x, CPU_TOP(cpu), x, CPU_BOTTOM(cpu));
787
788 /* Figure out if we can show the text for the previous record */
789
790 p3 = x;
791
792 /* Make sure p2 will be non-zero the next iteration */
793 if (!p3)
794 p3 = 1;
795
796 /* first record, continue */
797 if (p2)
798 draw_event_label(ginfo, cpu, last_event_id, last_pid,
799 p1, p2, p3, width_16, font);
800
801 p1 = p2;
802 p2 = p3;
803 last_event_id = event_id;
714 free(record); 804 free(record);
715 } 805 }
716 806
807 draw_event_label(ginfo, cpu, last_event_id, last_pid,
808 p1, p2, ginfo->draw_width, width_16, font);
809
717 810
718 if (last_pid > 0) { 811 if (last_pid > 0) {
719 x = ginfo->draw_width; 812 x = ginfo->draw_width;