annotate.c (89da393c171926d3372f573d752be5ced98038eb) annotate.c (f048d548f803b57ee1dbf66702f398ba69657450)
1/*
2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3 *
4 * Parts came from builtin-annotate.c, see those files for further
5 * copyright notes.
6 *
7 * Released under the GPL v2. (and only v2, not any later version)
8 */

--- 1056 unchanged lines hidden (view full) ---

1065 struct source_line *src_line = notes->src->lines;
1066 size_t sizeof_src_line;
1067 int i;
1068
1069 sizeof_src_line = sizeof(*src_line) +
1070 (sizeof(src_line->p) * (src_line->nr_pcnt - 1));
1071
1072 for (i = 0; i < len; i++) {
1/*
2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3 *
4 * Parts came from builtin-annotate.c, see those files for further
5 * copyright notes.
6 *
7 * Released under the GPL v2. (and only v2, not any later version)
8 */

--- 1056 unchanged lines hidden (view full) ---

1065 struct source_line *src_line = notes->src->lines;
1066 size_t sizeof_src_line;
1067 int i;
1068
1069 sizeof_src_line = sizeof(*src_line) +
1070 (sizeof(src_line->p) * (src_line->nr_pcnt - 1));
1071
1072 for (i = 0; i < len; i++) {
1073 free(src_line->path);
1073 free_srcline(src_line->path);
1074 src_line = (void *)src_line + sizeof_src_line;
1075 }
1076
1077 free(notes->src->lines);
1078 notes->src->lines = NULL;
1079}
1080
1081/* Get the filename:line for the colored entries */
1082static int symbol__get_source_line(struct symbol *sym, struct map *map,
1083 struct perf_evsel *evsel,
1084 struct rb_root *root, int len,
1085 const char *filename)
1086{
1087 u64 start;
1088 int i, k;
1089 int evidx = evsel->idx;
1074 src_line = (void *)src_line + sizeof_src_line;
1075 }
1076
1077 free(notes->src->lines);
1078 notes->src->lines = NULL;
1079}
1080
1081/* Get the filename:line for the colored entries */
1082static int symbol__get_source_line(struct symbol *sym, struct map *map,
1083 struct perf_evsel *evsel,
1084 struct rb_root *root, int len,
1085 const char *filename)
1086{
1087 u64 start;
1088 int i, k;
1089 int evidx = evsel->idx;
1090 char cmd[PATH_MAX * 2];
1091 struct source_line *src_line;
1092 struct annotation *notes = symbol__annotation(sym);
1093 struct sym_hist *h = annotation__histogram(notes, evidx);
1094 struct rb_root tmp_root = RB_ROOT;
1095 int nr_pcnt = 1;
1096 u64 h_sum = h->sum;
1097 size_t sizeof_src_line = sizeof(struct source_line);
1098

--- 11 unchanged lines hidden (view full) ---

1110
1111 src_line = notes->src->lines = calloc(len, sizeof_src_line);
1112 if (!notes->src->lines)
1113 return -1;
1114
1115 start = map__rip_2objdump(map, sym->start);
1116
1117 for (i = 0; i < len; i++) {
1090 struct source_line *src_line;
1091 struct annotation *notes = symbol__annotation(sym);
1092 struct sym_hist *h = annotation__histogram(notes, evidx);
1093 struct rb_root tmp_root = RB_ROOT;
1094 int nr_pcnt = 1;
1095 u64 h_sum = h->sum;
1096 size_t sizeof_src_line = sizeof(struct source_line);
1097

--- 11 unchanged lines hidden (view full) ---

1109
1110 src_line = notes->src->lines = calloc(len, sizeof_src_line);
1111 if (!notes->src->lines)
1112 return -1;
1113
1114 start = map__rip_2objdump(map, sym->start);
1115
1116 for (i = 0; i < len; i++) {
1118 char *path = NULL;
1119 size_t line_len;
1120 u64 offset;
1117 u64 offset;
1121 FILE *fp;
1122 double percent_max = 0.0;
1123
1124 src_line->nr_pcnt = nr_pcnt;
1125
1126 for (k = 0; k < nr_pcnt; k++) {
1127 h = annotation__histogram(notes, evidx + k);
1128 src_line->p[k].percent = 100.0 * h->addr[i] / h->sum;
1129
1130 if (src_line->p[k].percent > percent_max)
1131 percent_max = src_line->p[k].percent;
1132 }
1133
1134 if (percent_max <= 0.5)
1135 goto next;
1136
1137 offset = start + i;
1118 double percent_max = 0.0;
1119
1120 src_line->nr_pcnt = nr_pcnt;
1121
1122 for (k = 0; k < nr_pcnt; k++) {
1123 h = annotation__histogram(notes, evidx + k);
1124 src_line->p[k].percent = 100.0 * h->addr[i] / h->sum;
1125
1126 if (src_line->p[k].percent > percent_max)
1127 percent_max = src_line->p[k].percent;
1128 }
1129
1130 if (percent_max <= 0.5)
1131 goto next;
1132
1133 offset = start + i;
1138 sprintf(cmd, "addr2line -e %s %016" PRIx64, filename, offset);
1139 fp = popen(cmd, "r");
1140 if (!fp)
1141 goto next;
1142
1143 if (getline(&path, &line_len, fp) < 0 || !line_len)
1144 goto next_close;
1145
1146 src_line->path = path;
1134 src_line->path = get_srcline(filename, offset);
1147 insert_source_line(&tmp_root, src_line);
1148
1135 insert_source_line(&tmp_root, src_line);
1136
1149 next_close:
1150 pclose(fp);
1151 next:
1152 src_line = (void *)src_line + sizeof_src_line;
1153 }
1154
1155 resort_source_line(root, &tmp_root);
1156 return 0;
1157}
1158

--- 24 unchanged lines hidden (view full) ---

1183 color_fprintf(stdout, color, " %7.2f", percent);
1184
1185 if (percent > percent_max)
1186 percent_max = percent;
1187 }
1188
1189 path = src_line->path;
1190 color = get_percent_color(percent_max);
1137 next:
1138 src_line = (void *)src_line + sizeof_src_line;
1139 }
1140
1141 resort_source_line(root, &tmp_root);
1142 return 0;
1143}
1144

--- 24 unchanged lines hidden (view full) ---

1169 color_fprintf(stdout, color, " %7.2f", percent);
1170
1171 if (percent > percent_max)
1172 percent_max = percent;
1173 }
1174
1175 path = src_line->path;
1176 color = get_percent_color(percent_max);
1191 color_fprintf(stdout, color, " %s", path);
1177 color_fprintf(stdout, color, " %s\n", path);
1192
1193 node = rb_next(node);
1194 }
1195}
1196
1197static void symbol__annotate_hits(struct symbol *sym, struct perf_evsel *evsel)
1198{
1199 struct annotation *notes = symbol__annotation(sym);

--- 179 unchanged lines hidden ---
1178
1179 node = rb_next(node);
1180 }
1181}
1182
1183static void symbol__annotate_hits(struct symbol *sym, struct perf_evsel *evsel)
1184{
1185 struct annotation *notes = symbol__annotation(sym);

--- 179 unchanged lines hidden ---