aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2009-03-30 13:07:06 -0400
committerIngo Molnar <mingo@elte.hu>2009-04-06 03:30:39 -0400
commit3c1ba6fafecaed295017881f8863a18602f32c1d (patch)
tree753956bf0f2919c6a20e4982335fe5599ca1a74c /Documentation
parent0a4a93919bdc5cee48fe4367591e8e0449c1086c (diff)
perf_counter: kerneltop: parse the mmap data stream
frob the kerneltop code to print the mmap data in the stream Better use would be collecting the IPs per PID and mapping them onto the provided userspace code.. TODO Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Acked-by: Paul Mackerras <paulus@samba.org> Orig-LKML-Reference: <20090330171023.501902515@chello.nl> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/perf_counter/kerneltop.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/Documentation/perf_counter/kerneltop.c b/Documentation/perf_counter/kerneltop.c
index 2779c57ad4ba..995111dee7fb 100644
--- a/Documentation/perf_counter/kerneltop.c
+++ b/Documentation/perf_counter/kerneltop.c
@@ -184,6 +184,8 @@ static int nmi = 1;
184static int group = 0; 184static int group = 0;
185static unsigned int page_size; 185static unsigned int page_size;
186static unsigned int mmap_pages = 16; 186static unsigned int mmap_pages = 16;
187static int use_mmap = 0;
188static int use_munmap = 0;
187 189
188static char *vmlinux; 190static char *vmlinux;
189 191
@@ -333,6 +335,8 @@ static void display_help(void)
333 " -z --zero # zero counts after display\n" 335 " -z --zero # zero counts after display\n"
334 " -D --dump_symtab # dump symbol table to stderr on startup\n" 336 " -D --dump_symtab # dump symbol table to stderr on startup\n"
335 " -m pages --mmap_pages=<pages> # number of mmap data pages\n" 337 " -m pages --mmap_pages=<pages> # number of mmap data pages\n"
338 " -M --mmap_info # print mmap info stream\n"
339 " -U --munmap_info # print munmap info stream\n"
336 ); 340 );
337 341
338 exit(0); 342 exit(0);
@@ -1052,9 +1056,11 @@ static void process_options(int argc, char *argv[])
1052 {"stat", no_argument, NULL, 'S'}, 1056 {"stat", no_argument, NULL, 'S'},
1053 {"zero", no_argument, NULL, 'z'}, 1057 {"zero", no_argument, NULL, 'z'},
1054 {"mmap_pages", required_argument, NULL, 'm'}, 1058 {"mmap_pages", required_argument, NULL, 'm'},
1059 {"mmap_info", no_argument, NULL, 'M'},
1060 {"munmap_info", no_argument, NULL, 'U'},
1055 {NULL, 0, NULL, 0 } 1061 {NULL, 0, NULL, 0 }
1056 }; 1062 };
1057 int c = getopt_long(argc, argv, "+:ac:C:d:De:f:g:hn:m:p:s:Sx:z", 1063 int c = getopt_long(argc, argv, "+:ac:C:d:De:f:g:hn:m:p:s:Sx:zMU",
1058 long_options, &option_index); 1064 long_options, &option_index);
1059 if (c == -1) 1065 if (c == -1)
1060 break; 1066 break;
@@ -1092,6 +1098,8 @@ static void process_options(int argc, char *argv[])
1092 case 'x': vmlinux = strdup(optarg); break; 1098 case 'x': vmlinux = strdup(optarg); break;
1093 case 'z': zero = 1; break; 1099 case 'z': zero = 1; break;
1094 case 'm': mmap_pages = atoi(optarg); break; 1100 case 'm': mmap_pages = atoi(optarg); break;
1101 case 'M': use_mmap = 1; break;
1102 case 'U': use_munmap = 1; break;
1095 default: error = 1; break; 1103 default: error = 1; break;
1096 } 1104 }
1097 } 1105 }
@@ -1172,12 +1180,29 @@ static void mmap_read(struct mmap_data *md)
1172 last_read = this_read; 1180 last_read = this_read;
1173 1181
1174 for (; old != head;) { 1182 for (; old != head;) {
1175 struct event_struct { 1183 struct ip_event {
1176 struct perf_event_header header; 1184 struct perf_event_header header;
1177 __u64 ip; 1185 __u64 ip;
1178 __u32 pid, tid; 1186 __u32 pid, tid;
1179 } *event = (struct event_struct *)&data[old & md->mask]; 1187 };
1180 struct event_struct event_copy; 1188 struct mmap_event {
1189 struct perf_event_header header;
1190 __u32 pid, tid;
1191 __u64 start;
1192 __u64 len;
1193 __u64 pgoff;
1194 char filename[PATH_MAX];
1195 };
1196
1197 typedef union event_union {
1198 struct perf_event_header header;
1199 struct ip_event ip;
1200 struct mmap_event mmap;
1201 } event_t;
1202
1203 event_t *event = (event_t *)&data[old & md->mask];
1204
1205 event_t event_copy;
1181 1206
1182 unsigned int size = event->header.size; 1207 unsigned int size = event->header.size;
1183 1208
@@ -1187,7 +1212,7 @@ static void mmap_read(struct mmap_data *md)
1187 */ 1212 */
1188 if ((old & md->mask) + size != ((old + size) & md->mask)) { 1213 if ((old & md->mask) + size != ((old + size) & md->mask)) {
1189 unsigned int offset = old; 1214 unsigned int offset = old;
1190 unsigned int len = sizeof(*event), cpy; 1215 unsigned int len = min(sizeof(*event), size), cpy;
1191 void *dst = &event_copy; 1216 void *dst = &event_copy;
1192 1217
1193 do { 1218 do {
@@ -1206,7 +1231,18 @@ static void mmap_read(struct mmap_data *md)
1206 switch (event->header.type) { 1231 switch (event->header.type) {
1207 case PERF_EVENT_IP: 1232 case PERF_EVENT_IP:
1208 case PERF_EVENT_IP | __PERF_EVENT_TID: 1233 case PERF_EVENT_IP | __PERF_EVENT_TID:
1209 process_event(event->ip, md->counter); 1234 process_event(event->ip.ip, md->counter);
1235 break;
1236
1237 case PERF_EVENT_MMAP:
1238 case PERF_EVENT_MUNMAP:
1239 printf("%s: %Lu %Lu %Lu %s\n",
1240 event->header.type == PERF_EVENT_MMAP
1241 ? "mmap" : "munmap",
1242 event->mmap.start,
1243 event->mmap.len,
1244 event->mmap.pgoff,
1245 event->mmap.filename);
1210 break; 1246 break;
1211 } 1247 }
1212 } 1248 }
@@ -1255,6 +1291,8 @@ int main(int argc, char *argv[])
1255 hw_event.record_type = PERF_RECORD_IRQ; 1291 hw_event.record_type = PERF_RECORD_IRQ;
1256 hw_event.nmi = nmi; 1292 hw_event.nmi = nmi;
1257 hw_event.include_tid = 1; 1293 hw_event.include_tid = 1;
1294 hw_event.mmap = use_mmap;
1295 hw_event.munmap = use_munmap;
1258 1296
1259 fd[i][counter] = sys_perf_counter_open(&hw_event, tid, cpu, group_fd, 0); 1297 fd[i][counter] = sys_perf_counter_open(&hw_event, tid, cpu, group_fd, 0);
1260 if (fd[i][counter] < 0) { 1298 if (fd[i][counter] < 0) {