diff options
author | Robert Richter <robert.richter@amd.com> | 2012-02-10 09:41:55 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-02-13 20:32:32 -0500 |
commit | 08d95bd256277f914e525aeb292da52f15173e7d (patch) | |
tree | 02899bd6300d18e44995736a31091b9c3ac1a811 /tools | |
parent | 850f8127fa3666737881aecb3b16e8ede85e58f4 (diff) |
perf tools: Moving code in header.c
Needed for later changes. No modified functionality.
Cc: Ingo Molnar <mingo@elte.hu>
Link: http://lkml.kernel.org/r/1328884916-5901-1-git-send-email-robert.richter@amd.com
Signed-off-by: Robert Richter <robert.richter@amd.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/header.c | 300 |
1 files changed, 150 insertions, 150 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 6f4187de4b72..5bb2d752ab8f 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -1316,6 +1316,156 @@ static void print_cpuid(struct perf_header *ph, int fd, FILE *fp) | |||
1316 | free(str); | 1316 | free(str); |
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | static int __event_process_build_id(struct build_id_event *bev, | ||
1320 | char *filename, | ||
1321 | struct perf_session *session) | ||
1322 | { | ||
1323 | int err = -1; | ||
1324 | struct list_head *head; | ||
1325 | struct machine *machine; | ||
1326 | u16 misc; | ||
1327 | struct dso *dso; | ||
1328 | enum dso_kernel_type dso_type; | ||
1329 | |||
1330 | machine = perf_session__findnew_machine(session, bev->pid); | ||
1331 | if (!machine) | ||
1332 | goto out; | ||
1333 | |||
1334 | misc = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | ||
1335 | |||
1336 | switch (misc) { | ||
1337 | case PERF_RECORD_MISC_KERNEL: | ||
1338 | dso_type = DSO_TYPE_KERNEL; | ||
1339 | head = &machine->kernel_dsos; | ||
1340 | break; | ||
1341 | case PERF_RECORD_MISC_GUEST_KERNEL: | ||
1342 | dso_type = DSO_TYPE_GUEST_KERNEL; | ||
1343 | head = &machine->kernel_dsos; | ||
1344 | break; | ||
1345 | case PERF_RECORD_MISC_USER: | ||
1346 | case PERF_RECORD_MISC_GUEST_USER: | ||
1347 | dso_type = DSO_TYPE_USER; | ||
1348 | head = &machine->user_dsos; | ||
1349 | break; | ||
1350 | default: | ||
1351 | goto out; | ||
1352 | } | ||
1353 | |||
1354 | dso = __dsos__findnew(head, filename); | ||
1355 | if (dso != NULL) { | ||
1356 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
1357 | |||
1358 | dso__set_build_id(dso, &bev->build_id); | ||
1359 | |||
1360 | if (filename[0] == '[') | ||
1361 | dso->kernel = dso_type; | ||
1362 | |||
1363 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), | ||
1364 | sbuild_id); | ||
1365 | pr_debug("build id event received for %s: %s\n", | ||
1366 | dso->long_name, sbuild_id); | ||
1367 | } | ||
1368 | |||
1369 | err = 0; | ||
1370 | out: | ||
1371 | return err; | ||
1372 | } | ||
1373 | |||
1374 | static int perf_header__read_build_ids_abi_quirk(struct perf_header *header, | ||
1375 | int input, u64 offset, u64 size) | ||
1376 | { | ||
1377 | struct perf_session *session = container_of(header, struct perf_session, header); | ||
1378 | struct { | ||
1379 | struct perf_event_header header; | ||
1380 | u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))]; | ||
1381 | char filename[0]; | ||
1382 | } old_bev; | ||
1383 | struct build_id_event bev; | ||
1384 | char filename[PATH_MAX]; | ||
1385 | u64 limit = offset + size; | ||
1386 | |||
1387 | while (offset < limit) { | ||
1388 | ssize_t len; | ||
1389 | |||
1390 | if (read(input, &old_bev, sizeof(old_bev)) != sizeof(old_bev)) | ||
1391 | return -1; | ||
1392 | |||
1393 | if (header->needs_swap) | ||
1394 | perf_event_header__bswap(&old_bev.header); | ||
1395 | |||
1396 | len = old_bev.header.size - sizeof(old_bev); | ||
1397 | if (read(input, filename, len) != len) | ||
1398 | return -1; | ||
1399 | |||
1400 | bev.header = old_bev.header; | ||
1401 | |||
1402 | /* | ||
1403 | * As the pid is the missing value, we need to fill | ||
1404 | * it properly. The header.misc value give us nice hint. | ||
1405 | */ | ||
1406 | bev.pid = HOST_KERNEL_ID; | ||
1407 | if (bev.header.misc == PERF_RECORD_MISC_GUEST_USER || | ||
1408 | bev.header.misc == PERF_RECORD_MISC_GUEST_KERNEL) | ||
1409 | bev.pid = DEFAULT_GUEST_KERNEL_ID; | ||
1410 | |||
1411 | memcpy(bev.build_id, old_bev.build_id, sizeof(bev.build_id)); | ||
1412 | __event_process_build_id(&bev, filename, session); | ||
1413 | |||
1414 | offset += bev.header.size; | ||
1415 | } | ||
1416 | |||
1417 | return 0; | ||
1418 | } | ||
1419 | |||
1420 | static int perf_header__read_build_ids(struct perf_header *header, | ||
1421 | int input, u64 offset, u64 size) | ||
1422 | { | ||
1423 | struct perf_session *session = container_of(header, struct perf_session, header); | ||
1424 | struct build_id_event bev; | ||
1425 | char filename[PATH_MAX]; | ||
1426 | u64 limit = offset + size, orig_offset = offset; | ||
1427 | int err = -1; | ||
1428 | |||
1429 | while (offset < limit) { | ||
1430 | ssize_t len; | ||
1431 | |||
1432 | if (read(input, &bev, sizeof(bev)) != sizeof(bev)) | ||
1433 | goto out; | ||
1434 | |||
1435 | if (header->needs_swap) | ||
1436 | perf_event_header__bswap(&bev.header); | ||
1437 | |||
1438 | len = bev.header.size - sizeof(bev); | ||
1439 | if (read(input, filename, len) != len) | ||
1440 | goto out; | ||
1441 | /* | ||
1442 | * The a1645ce1 changeset: | ||
1443 | * | ||
1444 | * "perf: 'perf kvm' tool for monitoring guest performance from host" | ||
1445 | * | ||
1446 | * Added a field to struct build_id_event that broke the file | ||
1447 | * format. | ||
1448 | * | ||
1449 | * Since the kernel build-id is the first entry, process the | ||
1450 | * table using the old format if the well known | ||
1451 | * '[kernel.kallsyms]' string for the kernel build-id has the | ||
1452 | * first 4 characters chopped off (where the pid_t sits). | ||
1453 | */ | ||
1454 | if (memcmp(filename, "nel.kallsyms]", 13) == 0) { | ||
1455 | if (lseek(input, orig_offset, SEEK_SET) == (off_t)-1) | ||
1456 | return -1; | ||
1457 | return perf_header__read_build_ids_abi_quirk(header, input, offset, size); | ||
1458 | } | ||
1459 | |||
1460 | __event_process_build_id(&bev, filename, session); | ||
1461 | |||
1462 | offset += bev.header.size; | ||
1463 | } | ||
1464 | err = 0; | ||
1465 | out: | ||
1466 | return err; | ||
1467 | } | ||
1468 | |||
1319 | struct feature_ops { | 1469 | struct feature_ops { |
1320 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); | 1470 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); |
1321 | void (*print)(struct perf_header *h, int fd, FILE *fp); | 1471 | void (*print)(struct perf_header *h, int fd, FILE *fp); |
@@ -1735,156 +1885,6 @@ int perf_file_header__read(struct perf_file_header *header, | |||
1735 | return 0; | 1885 | return 0; |
1736 | } | 1886 | } |
1737 | 1887 | ||
1738 | static int __event_process_build_id(struct build_id_event *bev, | ||
1739 | char *filename, | ||
1740 | struct perf_session *session) | ||
1741 | { | ||
1742 | int err = -1; | ||
1743 | struct list_head *head; | ||
1744 | struct machine *machine; | ||
1745 | u16 misc; | ||
1746 | struct dso *dso; | ||
1747 | enum dso_kernel_type dso_type; | ||
1748 | |||
1749 | machine = perf_session__findnew_machine(session, bev->pid); | ||
1750 | if (!machine) | ||
1751 | goto out; | ||
1752 | |||
1753 | misc = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | ||
1754 | |||
1755 | switch (misc) { | ||
1756 | case PERF_RECORD_MISC_KERNEL: | ||
1757 | dso_type = DSO_TYPE_KERNEL; | ||
1758 | head = &machine->kernel_dsos; | ||
1759 | break; | ||
1760 | case PERF_RECORD_MISC_GUEST_KERNEL: | ||
1761 | dso_type = DSO_TYPE_GUEST_KERNEL; | ||
1762 | head = &machine->kernel_dsos; | ||
1763 | break; | ||
1764 | case PERF_RECORD_MISC_USER: | ||
1765 | case PERF_RECORD_MISC_GUEST_USER: | ||
1766 | dso_type = DSO_TYPE_USER; | ||
1767 | head = &machine->user_dsos; | ||
1768 | break; | ||
1769 | default: | ||
1770 | goto out; | ||
1771 | } | ||
1772 | |||
1773 | dso = __dsos__findnew(head, filename); | ||
1774 | if (dso != NULL) { | ||
1775 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
1776 | |||
1777 | dso__set_build_id(dso, &bev->build_id); | ||
1778 | |||
1779 | if (filename[0] == '[') | ||
1780 | dso->kernel = dso_type; | ||
1781 | |||
1782 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), | ||
1783 | sbuild_id); | ||
1784 | pr_debug("build id event received for %s: %s\n", | ||
1785 | dso->long_name, sbuild_id); | ||
1786 | } | ||
1787 | |||
1788 | err = 0; | ||
1789 | out: | ||
1790 | return err; | ||
1791 | } | ||
1792 | |||
1793 | static int perf_header__read_build_ids_abi_quirk(struct perf_header *header, | ||
1794 | int input, u64 offset, u64 size) | ||
1795 | { | ||
1796 | struct perf_session *session = container_of(header, struct perf_session, header); | ||
1797 | struct { | ||
1798 | struct perf_event_header header; | ||
1799 | u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))]; | ||
1800 | char filename[0]; | ||
1801 | } old_bev; | ||
1802 | struct build_id_event bev; | ||
1803 | char filename[PATH_MAX]; | ||
1804 | u64 limit = offset + size; | ||
1805 | |||
1806 | while (offset < limit) { | ||
1807 | ssize_t len; | ||
1808 | |||
1809 | if (read(input, &old_bev, sizeof(old_bev)) != sizeof(old_bev)) | ||
1810 | return -1; | ||
1811 | |||
1812 | if (header->needs_swap) | ||
1813 | perf_event_header__bswap(&old_bev.header); | ||
1814 | |||
1815 | len = old_bev.header.size - sizeof(old_bev); | ||
1816 | if (read(input, filename, len) != len) | ||
1817 | return -1; | ||
1818 | |||
1819 | bev.header = old_bev.header; | ||
1820 | |||
1821 | /* | ||
1822 | * As the pid is the missing value, we need to fill | ||
1823 | * it properly. The header.misc value give us nice hint. | ||
1824 | */ | ||
1825 | bev.pid = HOST_KERNEL_ID; | ||
1826 | if (bev.header.misc == PERF_RECORD_MISC_GUEST_USER || | ||
1827 | bev.header.misc == PERF_RECORD_MISC_GUEST_KERNEL) | ||
1828 | bev.pid = DEFAULT_GUEST_KERNEL_ID; | ||
1829 | |||
1830 | memcpy(bev.build_id, old_bev.build_id, sizeof(bev.build_id)); | ||
1831 | __event_process_build_id(&bev, filename, session); | ||
1832 | |||
1833 | offset += bev.header.size; | ||
1834 | } | ||
1835 | |||
1836 | return 0; | ||
1837 | } | ||
1838 | |||
1839 | static int perf_header__read_build_ids(struct perf_header *header, | ||
1840 | int input, u64 offset, u64 size) | ||
1841 | { | ||
1842 | struct perf_session *session = container_of(header, struct perf_session, header); | ||
1843 | struct build_id_event bev; | ||
1844 | char filename[PATH_MAX]; | ||
1845 | u64 limit = offset + size, orig_offset = offset; | ||
1846 | int err = -1; | ||
1847 | |||
1848 | while (offset < limit) { | ||
1849 | ssize_t len; | ||
1850 | |||
1851 | if (read(input, &bev, sizeof(bev)) != sizeof(bev)) | ||
1852 | goto out; | ||
1853 | |||
1854 | if (header->needs_swap) | ||
1855 | perf_event_header__bswap(&bev.header); | ||
1856 | |||
1857 | len = bev.header.size - sizeof(bev); | ||
1858 | if (read(input, filename, len) != len) | ||
1859 | goto out; | ||
1860 | /* | ||
1861 | * The a1645ce1 changeset: | ||
1862 | * | ||
1863 | * "perf: 'perf kvm' tool for monitoring guest performance from host" | ||
1864 | * | ||
1865 | * Added a field to struct build_id_event that broke the file | ||
1866 | * format. | ||
1867 | * | ||
1868 | * Since the kernel build-id is the first entry, process the | ||
1869 | * table using the old format if the well known | ||
1870 | * '[kernel.kallsyms]' string for the kernel build-id has the | ||
1871 | * first 4 characters chopped off (where the pid_t sits). | ||
1872 | */ | ||
1873 | if (memcmp(filename, "nel.kallsyms]", 13) == 0) { | ||
1874 | if (lseek(input, orig_offset, SEEK_SET) == (off_t)-1) | ||
1875 | return -1; | ||
1876 | return perf_header__read_build_ids_abi_quirk(header, input, offset, size); | ||
1877 | } | ||
1878 | |||
1879 | __event_process_build_id(&bev, filename, session); | ||
1880 | |||
1881 | offset += bev.header.size; | ||
1882 | } | ||
1883 | err = 0; | ||
1884 | out: | ||
1885 | return err; | ||
1886 | } | ||
1887 | |||
1888 | static int perf_file_section__process(struct perf_file_section *section, | 1888 | static int perf_file_section__process(struct perf_file_section *section, |
1889 | struct perf_header *ph, | 1889 | struct perf_header *ph, |
1890 | int feat, int fd, void *data __used) | 1890 | int feat, int fd, void *data __used) |