diff options
author | Namhyung Kim <namhyung@kernel.org> | 2012-09-24 04:15:00 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-24 10:45:53 -0400 |
commit | 7e94cfcc9d201984a7be00a4fb42050c69ec4c56 (patch) | |
tree | e557a30891bef0915ac7b72059e2d5783fb9fdb7 /tools/perf/util/header.c | |
parent | a1ae565528757f26d315897929b6fe58c5647915 (diff) |
perf header: Use pre-processed session env when printing
From now on each feature information is processed and saved in perf
header so that it can be used for printing. The event desc and branch
stack features are not touched since they're not saved.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1348474503-15070-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/header.c')
-rw-r--r-- | tools/perf/util/header.c | 207 |
1 files changed, 66 insertions, 141 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index d74b58d4105d..b2929d7a3d4e 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -1103,118 +1103,80 @@ static int write_branch_stack(int fd __maybe_unused, | |||
1103 | return 0; | 1103 | return 0; |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | static void print_hostname(struct perf_header *ph, int fd, FILE *fp) | 1106 | static void print_hostname(struct perf_header *ph, int fd __maybe_unused, |
1107 | FILE *fp) | ||
1107 | { | 1108 | { |
1108 | char *str = do_read_string(fd, ph); | 1109 | fprintf(fp, "# hostname : %s\n", ph->env.hostname); |
1109 | fprintf(fp, "# hostname : %s\n", str); | ||
1110 | free(str); | ||
1111 | } | 1110 | } |
1112 | 1111 | ||
1113 | static void print_osrelease(struct perf_header *ph, int fd, FILE *fp) | 1112 | static void print_osrelease(struct perf_header *ph, int fd __maybe_unused, |
1113 | FILE *fp) | ||
1114 | { | 1114 | { |
1115 | char *str = do_read_string(fd, ph); | 1115 | fprintf(fp, "# os release : %s\n", ph->env.os_release); |
1116 | fprintf(fp, "# os release : %s\n", str); | ||
1117 | free(str); | ||
1118 | } | 1116 | } |
1119 | 1117 | ||
1120 | static void print_arch(struct perf_header *ph, int fd, FILE *fp) | 1118 | static void print_arch(struct perf_header *ph, int fd __maybe_unused, FILE *fp) |
1121 | { | 1119 | { |
1122 | char *str = do_read_string(fd, ph); | 1120 | fprintf(fp, "# arch : %s\n", ph->env.arch); |
1123 | fprintf(fp, "# arch : %s\n", str); | ||
1124 | free(str); | ||
1125 | } | 1121 | } |
1126 | 1122 | ||
1127 | static void print_cpudesc(struct perf_header *ph, int fd, FILE *fp) | 1123 | static void print_cpudesc(struct perf_header *ph, int fd __maybe_unused, |
1124 | FILE *fp) | ||
1128 | { | 1125 | { |
1129 | char *str = do_read_string(fd, ph); | 1126 | fprintf(fp, "# cpudesc : %s\n", ph->env.cpu_desc); |
1130 | fprintf(fp, "# cpudesc : %s\n", str); | ||
1131 | free(str); | ||
1132 | } | 1127 | } |
1133 | 1128 | ||
1134 | static void print_nrcpus(struct perf_header *ph, int fd, FILE *fp) | 1129 | static void print_nrcpus(struct perf_header *ph, int fd __maybe_unused, |
1130 | FILE *fp) | ||
1135 | { | 1131 | { |
1136 | ssize_t ret; | 1132 | fprintf(fp, "# nrcpus online : %u\n", ph->env.nr_cpus_online); |
1137 | u32 nr; | 1133 | fprintf(fp, "# nrcpus avail : %u\n", ph->env.nr_cpus_avail); |
1138 | |||
1139 | ret = read(fd, &nr, sizeof(nr)); | ||
1140 | if (ret != (ssize_t)sizeof(nr)) | ||
1141 | nr = -1; /* interpreted as error */ | ||
1142 | |||
1143 | if (ph->needs_swap) | ||
1144 | nr = bswap_32(nr); | ||
1145 | |||
1146 | fprintf(fp, "# nrcpus online : %u\n", nr); | ||
1147 | |||
1148 | ret = read(fd, &nr, sizeof(nr)); | ||
1149 | if (ret != (ssize_t)sizeof(nr)) | ||
1150 | nr = -1; /* interpreted as error */ | ||
1151 | |||
1152 | if (ph->needs_swap) | ||
1153 | nr = bswap_32(nr); | ||
1154 | |||
1155 | fprintf(fp, "# nrcpus avail : %u\n", nr); | ||
1156 | } | 1134 | } |
1157 | 1135 | ||
1158 | static void print_version(struct perf_header *ph, int fd, FILE *fp) | 1136 | static void print_version(struct perf_header *ph, int fd __maybe_unused, |
1137 | FILE *fp) | ||
1159 | { | 1138 | { |
1160 | char *str = do_read_string(fd, ph); | 1139 | fprintf(fp, "# perf version : %s\n", ph->env.version); |
1161 | fprintf(fp, "# perf version : %s\n", str); | ||
1162 | free(str); | ||
1163 | } | 1140 | } |
1164 | 1141 | ||
1165 | static void print_cmdline(struct perf_header *ph, int fd, FILE *fp) | 1142 | static void print_cmdline(struct perf_header *ph, int fd __maybe_unused, |
1143 | FILE *fp) | ||
1166 | { | 1144 | { |
1167 | ssize_t ret; | 1145 | int nr, i; |
1168 | char *str; | 1146 | char *str; |
1169 | u32 nr, i; | ||
1170 | |||
1171 | ret = read(fd, &nr, sizeof(nr)); | ||
1172 | if (ret != (ssize_t)sizeof(nr)) | ||
1173 | return; | ||
1174 | 1147 | ||
1175 | if (ph->needs_swap) | 1148 | nr = ph->env.nr_cmdline; |
1176 | nr = bswap_32(nr); | 1149 | str = ph->env.cmdline; |
1177 | 1150 | ||
1178 | fprintf(fp, "# cmdline : "); | 1151 | fprintf(fp, "# cmdline : "); |
1179 | 1152 | ||
1180 | for (i = 0; i < nr; i++) { | 1153 | for (i = 0; i < nr; i++) { |
1181 | str = do_read_string(fd, ph); | ||
1182 | fprintf(fp, "%s ", str); | 1154 | fprintf(fp, "%s ", str); |
1183 | free(str); | 1155 | str += strlen(str) + 1; |
1184 | } | 1156 | } |
1185 | fputc('\n', fp); | 1157 | fputc('\n', fp); |
1186 | } | 1158 | } |
1187 | 1159 | ||
1188 | static void print_cpu_topology(struct perf_header *ph, int fd, FILE *fp) | 1160 | static void print_cpu_topology(struct perf_header *ph, int fd __maybe_unused, |
1161 | FILE *fp) | ||
1189 | { | 1162 | { |
1190 | ssize_t ret; | 1163 | int nr, i; |
1191 | u32 nr, i; | ||
1192 | char *str; | 1164 | char *str; |
1193 | 1165 | ||
1194 | ret = read(fd, &nr, sizeof(nr)); | 1166 | nr = ph->env.nr_sibling_cores; |
1195 | if (ret != (ssize_t)sizeof(nr)) | 1167 | str = ph->env.sibling_cores; |
1196 | return; | ||
1197 | |||
1198 | if (ph->needs_swap) | ||
1199 | nr = bswap_32(nr); | ||
1200 | 1168 | ||
1201 | for (i = 0; i < nr; i++) { | 1169 | for (i = 0; i < nr; i++) { |
1202 | str = do_read_string(fd, ph); | ||
1203 | fprintf(fp, "# sibling cores : %s\n", str); | 1170 | fprintf(fp, "# sibling cores : %s\n", str); |
1204 | free(str); | 1171 | str += strlen(str) + 1; |
1205 | } | 1172 | } |
1206 | 1173 | ||
1207 | ret = read(fd, &nr, sizeof(nr)); | 1174 | nr = ph->env.nr_sibling_threads; |
1208 | if (ret != (ssize_t)sizeof(nr)) | 1175 | str = ph->env.sibling_threads; |
1209 | return; | ||
1210 | |||
1211 | if (ph->needs_swap) | ||
1212 | nr = bswap_32(nr); | ||
1213 | 1176 | ||
1214 | for (i = 0; i < nr; i++) { | 1177 | for (i = 0; i < nr; i++) { |
1215 | str = do_read_string(fd, ph); | ||
1216 | fprintf(fp, "# sibling threads : %s\n", str); | 1178 | fprintf(fp, "# sibling threads : %s\n", str); |
1217 | free(str); | 1179 | str += strlen(str) + 1; |
1218 | } | 1180 | } |
1219 | } | 1181 | } |
1220 | 1182 | ||
@@ -1375,126 +1337,89 @@ static void print_event_desc(struct perf_header *ph, int fd, FILE *fp) | |||
1375 | free_event_desc(events); | 1337 | free_event_desc(events); |
1376 | } | 1338 | } |
1377 | 1339 | ||
1378 | static void print_total_mem(struct perf_header *h __maybe_unused, int fd, | 1340 | static void print_total_mem(struct perf_header *ph, int fd __maybe_unused, |
1379 | FILE *fp) | 1341 | FILE *fp) |
1380 | { | 1342 | { |
1381 | uint64_t mem; | 1343 | fprintf(fp, "# total memory : %Lu kB\n", ph->env.total_mem); |
1382 | ssize_t ret; | ||
1383 | |||
1384 | ret = read(fd, &mem, sizeof(mem)); | ||
1385 | if (ret != sizeof(mem)) | ||
1386 | goto error; | ||
1387 | |||
1388 | if (h->needs_swap) | ||
1389 | mem = bswap_64(mem); | ||
1390 | |||
1391 | fprintf(fp, "# total memory : %"PRIu64" kB\n", mem); | ||
1392 | return; | ||
1393 | error: | ||
1394 | fprintf(fp, "# total memory : unknown\n"); | ||
1395 | } | 1344 | } |
1396 | 1345 | ||
1397 | static void print_numa_topology(struct perf_header *h __maybe_unused, int fd, | 1346 | static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused, |
1398 | FILE *fp) | 1347 | FILE *fp) |
1399 | { | 1348 | { |
1400 | ssize_t ret; | ||
1401 | u32 nr, c, i; | 1349 | u32 nr, c, i; |
1402 | char *str; | 1350 | char *str, *tmp; |
1403 | uint64_t mem_total, mem_free; | 1351 | uint64_t mem_total, mem_free; |
1404 | 1352 | ||
1405 | /* nr nodes */ | 1353 | /* nr nodes */ |
1406 | ret = read(fd, &nr, sizeof(nr)); | 1354 | nr = ph->env.nr_numa_nodes; |
1407 | if (ret != (ssize_t)sizeof(nr)) | 1355 | str = ph->env.numa_nodes; |
1408 | goto error; | ||
1409 | |||
1410 | if (h->needs_swap) | ||
1411 | nr = bswap_32(nr); | ||
1412 | 1356 | ||
1413 | for (i = 0; i < nr; i++) { | 1357 | for (i = 0; i < nr; i++) { |
1414 | |||
1415 | /* node number */ | 1358 | /* node number */ |
1416 | ret = read(fd, &c, sizeof(c)); | 1359 | c = strtoul(str, &tmp, 0); |
1417 | if (ret != (ssize_t)sizeof(c)) | 1360 | if (*tmp != ':') |
1418 | goto error; | 1361 | goto error; |
1419 | 1362 | ||
1420 | if (h->needs_swap) | 1363 | str = tmp + 1; |
1421 | c = bswap_32(c); | 1364 | mem_total = strtoull(str, &tmp, 0); |
1422 | 1365 | if (*tmp != ':') | |
1423 | ret = read(fd, &mem_total, sizeof(u64)); | ||
1424 | if (ret != sizeof(u64)) | ||
1425 | goto error; | 1366 | goto error; |
1426 | 1367 | ||
1427 | ret = read(fd, &mem_free, sizeof(u64)); | 1368 | str = tmp + 1; |
1428 | if (ret != sizeof(u64)) | 1369 | mem_free = strtoull(str, &tmp, 0); |
1370 | if (*tmp != ':') | ||
1429 | goto error; | 1371 | goto error; |
1430 | 1372 | ||
1431 | if (h->needs_swap) { | ||
1432 | mem_total = bswap_64(mem_total); | ||
1433 | mem_free = bswap_64(mem_free); | ||
1434 | } | ||
1435 | |||
1436 | fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB," | 1373 | fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB," |
1437 | " free = %"PRIu64" kB\n", | 1374 | " free = %"PRIu64" kB\n", |
1438 | c, | 1375 | c, mem_total, mem_free); |
1439 | mem_total, | ||
1440 | mem_free); | ||
1441 | 1376 | ||
1442 | str = do_read_string(fd, h); | 1377 | str = tmp + 1; |
1443 | fprintf(fp, "# node%u cpu list : %s\n", c, str); | 1378 | fprintf(fp, "# node%u cpu list : %s\n", c, str); |
1444 | free(str); | ||
1445 | } | 1379 | } |
1446 | return; | 1380 | return; |
1447 | error: | 1381 | error: |
1448 | fprintf(fp, "# numa topology : not available\n"); | 1382 | fprintf(fp, "# numa topology : not available\n"); |
1449 | } | 1383 | } |
1450 | 1384 | ||
1451 | static void print_cpuid(struct perf_header *ph, int fd, FILE *fp) | 1385 | static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp) |
1452 | { | 1386 | { |
1453 | char *str = do_read_string(fd, ph); | 1387 | fprintf(fp, "# cpuid : %s\n", ph->env.cpuid); |
1454 | fprintf(fp, "# cpuid : %s\n", str); | ||
1455 | free(str); | ||
1456 | } | 1388 | } |
1457 | 1389 | ||
1458 | static void print_branch_stack(struct perf_header *ph __maybe_unused, | 1390 | static void print_branch_stack(struct perf_header *ph __maybe_unused, |
1459 | int fd __maybe_unused, | 1391 | int fd __maybe_unused, FILE *fp) |
1460 | FILE *fp) | ||
1461 | { | 1392 | { |
1462 | fprintf(fp, "# contains samples with branch stack\n"); | 1393 | fprintf(fp, "# contains samples with branch stack\n"); |
1463 | } | 1394 | } |
1464 | 1395 | ||
1465 | static void print_pmu_mappings(struct perf_header *ph, int fd, FILE *fp) | 1396 | static void print_pmu_mappings(struct perf_header *ph, int fd __maybe_unused, |
1397 | FILE *fp) | ||
1466 | { | 1398 | { |
1467 | const char *delimiter = "# pmu mappings: "; | 1399 | const char *delimiter = "# pmu mappings: "; |
1468 | char *name; | 1400 | char *str, *tmp; |
1469 | int ret; | ||
1470 | u32 pmu_num; | 1401 | u32 pmu_num; |
1471 | u32 type; | 1402 | u32 type; |
1472 | 1403 | ||
1473 | ret = read(fd, &pmu_num, sizeof(pmu_num)); | 1404 | pmu_num = ph->env.nr_pmu_mappings; |
1474 | if (ret != sizeof(pmu_num)) | ||
1475 | goto error; | ||
1476 | |||
1477 | if (ph->needs_swap) | ||
1478 | pmu_num = bswap_32(pmu_num); | ||
1479 | |||
1480 | if (!pmu_num) { | 1405 | if (!pmu_num) { |
1481 | fprintf(fp, "# pmu mappings: not available\n"); | 1406 | fprintf(fp, "# pmu mappings: not available\n"); |
1482 | return; | 1407 | return; |
1483 | } | 1408 | } |
1484 | 1409 | ||
1410 | str = ph->env.pmu_mappings; | ||
1411 | |||
1485 | while (pmu_num) { | 1412 | while (pmu_num) { |
1486 | if (read(fd, &type, sizeof(type)) != sizeof(type)) | 1413 | type = strtoul(str, &tmp, 0); |
1487 | break; | 1414 | if (*tmp != ':') |
1488 | if (ph->needs_swap) | 1415 | goto error; |
1489 | type = bswap_32(type); | 1416 | |
1417 | str = tmp + 1; | ||
1418 | fprintf(fp, "%s%s = %" PRIu32, delimiter, str, type); | ||
1490 | 1419 | ||
1491 | name = do_read_string(fd, ph); | ||
1492 | if (!name) | ||
1493 | break; | ||
1494 | pmu_num--; | ||
1495 | fprintf(fp, "%s%s = %" PRIu32, delimiter, name, type); | ||
1496 | free(name); | ||
1497 | delimiter = ", "; | 1420 | delimiter = ", "; |
1421 | str += strlen(str) + 1; | ||
1422 | pmu_num--; | ||
1498 | } | 1423 | } |
1499 | 1424 | ||
1500 | fprintf(fp, "\n"); | 1425 | fprintf(fp, "\n"); |