Lines Matching +full:attr +full:- +full:cnt +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0
35 #include "trace-event.h"
44 #include "build-id.h"
50 #include "time-utils.h"
54 #include "bpf-event.h"
55 #include "bpf-utils.h"
62 #include <event-parse.h>
83 struct perf_event_attr attr; member
89 __set_bit(feat, header->adds_features); in perf_header__set_feat()
94 __clear_bit(feat, header->adds_features); in perf_header__clear_feat()
99 return test_bit(feat, header->adds_features); in perf_header__has_feat()
104 ssize_t ret = writen(ff->fd, buf, size); in __do_write_fd()
107 return ret < 0 ? (int)ret : -1; in __do_write_fd()
114 const size_t max_size = 0xffff - sizeof(struct perf_event_header); in __do_write_buf()
115 size_t new_size = ff->size; in __do_write_buf()
118 if (size + ff->offset > max_size) in __do_write_buf()
119 return -E2BIG; in __do_write_buf()
121 while (size > (new_size - ff->offset)) in __do_write_buf()
125 if (ff->size < new_size) { in __do_write_buf()
126 addr = realloc(ff->buf, new_size); in __do_write_buf()
128 return -ENOMEM; in __do_write_buf()
129 ff->buf = addr; in __do_write_buf()
130 ff->size = new_size; in __do_write_buf()
133 memcpy(ff->buf + ff->offset, buf, size); in __do_write_buf()
134 ff->offset += size; in __do_write_buf()
139 /* Return: 0 if succeeded, -ERR if failed. */
142 if (!ff->buf) in do_write()
147 /* Return: 0 if succeeded, -ERR if failed. */
166 /* Return: 0 if succeeded, -ERR if failed. */
174 err = do_write(ff, zero_buf, count_aligned - count); in write_padded()
182 /* Return: 0 if succeeded, -ERR if failed. */
201 ssize_t ret = readn(ff->fd, addr, size); in __do_read_fd()
204 return ret < 0 ? (int)ret : -1; in __do_read_fd()
210 if (size > (ssize_t)ff->size - ff->offset) in __do_read_buf()
211 return -1; in __do_read_buf()
213 memcpy(addr, ff->buf + ff->offset, size); in __do_read_buf()
214 ff->offset += size; in __do_read_buf()
222 if (!ff->buf) in __do_read()
235 if (ff->ph->needs_swap) in do_read_u32()
248 if (ff->ph->needs_swap) in do_read_u64()
278 /* Return: 0 if succeeded, -ERR if failed. */
291 return -ENOMEM; in do_read_bitmap()
312 if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) in write_tracing_data()
313 return -1; in write_tracing_data()
315 return read_tracing_data(ff->fd, &evlist->core.entries); in write_tracing_data()
325 session = container_of(ff->ph, struct perf_session, header); in write_build_id()
328 return -1; in write_build_id()
330 if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) in write_build_id()
331 return -1; in write_build_id()
351 return -1; in write_hostname()
364 return -1; in write_osrelease()
377 return -1; in write_arch()
395 int ret = -1; in __write_cpudesc()
398 return -1; in __write_cpudesc()
402 return -1; in __write_cpudesc()
411 ret = -1; in __write_cpudesc()
455 #define CPUINFO_PROC { "model name", "Processor", } in write_cpudesc()
461 #define CPUINFO_PROC { "Model Name", } in write_cpudesc()
463 #define CPUINFO_PROC { "model name", } in write_cpudesc()
475 return -1; in write_cpudesc()
490 return -1; in write_nrcpus()
508 nre = evlist->core.nr_entries; in write_event_desc()
520 sz = (u32)sizeof(evsel->core.attr); in write_event_desc()
526 ret = do_write(ff, &evsel->core.attr, sz); in write_event_desc()
536 nri = evsel->core.ids; in write_event_desc()
550 ret = do_write(ff, evsel->core.id, evsel->core.ids * sizeof(u64)); in write_event_desc()
560 struct perf_env *env = &ff->ph->env; in write_cmdline()
568 n = env->nr_cmdline + 1; in write_cmdline()
578 for (i = 0 ; i < env->nr_cmdline; i++) { in write_cmdline()
579 ret = do_write_string(ff, env->cmdline_argv[i]); in write_cmdline()
590 struct perf_env *env = &ff->ph->env; in write_cpu_topology()
597 return -1; in write_cpu_topology()
599 ret = do_write(ff, &tp->package_cpus_lists, sizeof(tp->package_cpus_lists)); in write_cpu_topology()
603 for (i = 0; i < tp->package_cpus_lists; i++) { in write_cpu_topology()
604 ret = do_write_string(ff, tp->package_cpus_list[i]); in write_cpu_topology()
608 ret = do_write(ff, &tp->core_cpus_lists, sizeof(tp->core_cpus_lists)); in write_cpu_topology()
612 for (i = 0; i < tp->core_cpus_lists; i++) { in write_cpu_topology()
613 ret = do_write_string(ff, tp->core_cpus_list[i]); in write_cpu_topology()
622 for (j = 0; j < env->nr_cpus_avail; j++) { in write_cpu_topology()
623 ret = do_write(ff, &env->cpu[j].core_id, in write_cpu_topology()
624 sizeof(env->cpu[j].core_id)); in write_cpu_topology()
627 ret = do_write(ff, &env->cpu[j].socket_id, in write_cpu_topology()
628 sizeof(env->cpu[j].socket_id)); in write_cpu_topology()
633 if (!tp->die_cpus_lists) in write_cpu_topology()
636 ret = do_write(ff, &tp->die_cpus_lists, sizeof(tp->die_cpus_lists)); in write_cpu_topology()
640 for (i = 0; i < tp->die_cpus_lists; i++) { in write_cpu_topology()
641 ret = do_write_string(ff, tp->die_cpus_list[i]); in write_cpu_topology()
646 for (j = 0; j < env->nr_cpus_avail; j++) { in write_cpu_topology()
647 ret = do_write(ff, &env->cpu[j].die_id, in write_cpu_topology()
648 sizeof(env->cpu[j].die_id)); in write_cpu_topology()
666 int ret = -1, n; in write_total_mem()
671 return -1; in write_total_mem()
683 ret = -1; in write_total_mem()
693 int ret = -1; in write_numa_topology()
698 return -ENOMEM; in write_numa_topology()
700 ret = do_write(ff, &tp->nr, sizeof(u32)); in write_numa_topology()
704 for (i = 0; i < tp->nr; i++) { in write_numa_topology()
705 struct numa_topology_node *n = &tp->nodes[i]; in write_numa_topology()
707 ret = do_write(ff, &n->node, sizeof(u32)); in write_numa_topology()
711 ret = do_write(ff, &n->mem_total, sizeof(u64)); in write_numa_topology()
715 ret = do_write(ff, &n->mem_free, sizeof(u64)); in write_numa_topology()
719 ret = do_write_string(ff, n->cpus); in write_numa_topology()
738 * char name[];
762 ret = do_write(ff, &pmu->type, sizeof(pmu->type)); in write_pmu_mappings()
766 ret = do_write_string(ff, pmu->name); in write_pmu_mappings()
780 * char name[];
798 if (evsel__is_group_leader(evsel) && evsel->core.nr_members > 1) { in write_group_desc()
799 const char *name = evsel->group_name ?: "{anon_group}"; in write_group_desc() local
800 u32 leader_idx = evsel->core.idx; in write_group_desc()
801 u32 nr_members = evsel->core.nr_members; in write_group_desc()
803 ret = do_write_string(ff, name); in write_group_desc()
852 * Otherwise return non-zero.
869 size_t match_len = (pmatch[0].rm_eo - pmatch[0].rm_so); in strcmp_cpuid_str()
890 struct perf_cpu cpu = perf_cpu_map__min(evlist->core.all_cpus); in write_cpuid()
896 return -1; in write_cpuid()
913 if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) in write_auxtrace()
914 return -1; in write_auxtrace()
916 session = container_of(ff->ph, struct perf_session, header); in write_auxtrace()
918 err = auxtrace_index__write(ff->fd, &session->auxtrace_index); in write_auxtrace()
927 return do_write(ff, &ff->ph->env.clock.clockid_res_ns, in write_clockid()
928 sizeof(ff->ph->env.clock.clockid_res_ns)); in write_clockid()
946 data32 = ff->ph->env.clock.clockid; in write_clock_data()
953 data64 = &ff->ph->env.clock.tod_ns; in write_clock_data()
960 data64 = &ff->ph->env.clock.clockid_ns; in write_clock_data()
974 return -ENOENT; in write_hybrid_topology()
976 ret = do_write(ff, &tp->nr, sizeof(u32)); in write_hybrid_topology()
980 for (i = 0; i < tp->nr; i++) { in write_hybrid_topology()
981 struct hybrid_topology_node *n = &tp->nodes[i]; in write_hybrid_topology()
983 ret = do_write_string(ff, n->pmu_name); in write_hybrid_topology()
987 ret = do_write_string(ff, n->cpus); in write_hybrid_topology()
1005 session = container_of(ff->ph, struct perf_session, header); in write_dir_format()
1006 data = session->data; in write_dir_format()
1009 return -1; in write_dir_format()
1011 return do_write(ff, &data->dir.version, sizeof(data->dir.version)); in write_dir_format()
1018 struct perf_env *env = &ff->ph->env; in write_bpf_prog_info()
1023 down_read(&env->bpf_progs.lock); in write_bpf_prog_info()
1025 ret = do_write(ff, &env->bpf_progs.infos_cnt, in write_bpf_prog_info()
1026 sizeof(env->bpf_progs.infos_cnt)); in write_bpf_prog_info()
1027 if (ret < 0 || env->bpf_progs.infos_cnt == 0) in write_bpf_prog_info()
1030 root = &env->bpf_progs.infos; in write_bpf_prog_info()
1037 next = rb_next(&node->rb_node); in write_bpf_prog_info()
1039 node->info_linear->data_len; in write_bpf_prog_info()
1042 bpil_addr_to_offs(node->info_linear); in write_bpf_prog_info()
1043 ret = do_write(ff, node->info_linear, len); in write_bpf_prog_info()
1048 bpil_offs_to_addr(node->info_linear); in write_bpf_prog_info()
1053 up_read(&env->bpf_progs.lock); in write_bpf_prog_info()
1060 struct perf_env *env = &ff->ph->env; in write_bpf_btf()
1065 down_read(&env->bpf_progs.lock); in write_bpf_btf()
1067 ret = do_write(ff, &env->bpf_progs.btfs_cnt, in write_bpf_btf()
1068 sizeof(env->bpf_progs.btfs_cnt)); in write_bpf_btf()
1070 if (ret < 0 || env->bpf_progs.btfs_cnt == 0) in write_bpf_btf()
1073 root = &env->bpf_progs.btfs; in write_bpf_btf()
1079 next = rb_next(&node->rb_node); in write_bpf_btf()
1080 ret = do_write(ff, &node->id, in write_bpf_btf()
1081 sizeof(u32) * 2 + node->data_size); in write_bpf_btf()
1086 up_read(&env->bpf_progs.lock); in write_bpf_btf()
1096 return cache_a->level - cache_b->level; in cpu_cache_level__sort()
1101 if (a->level != b->level) in cpu_cache_level__cmp()
1104 if (a->line_size != b->line_size) in cpu_cache_level__cmp()
1107 if (a->sets != b->sets) in cpu_cache_level__cmp()
1110 if (a->ways != b->ways) in cpu_cache_level__cmp()
1113 if (strcmp(a->type, b->type)) in cpu_cache_level__cmp()
1116 if (strcmp(a->size, b->size)) in cpu_cache_level__cmp()
1119 if (strcmp(a->map, b->map)) in cpu_cache_level__cmp()
1138 if (sysfs__read_int(file, (int *) &cache->level)) in cpu_cache_level__read()
1139 return -1; in cpu_cache_level__read()
1142 if (sysfs__read_int(file, (int *) &cache->line_size)) in cpu_cache_level__read()
1143 return -1; in cpu_cache_level__read()
1146 if (sysfs__read_int(file, (int *) &cache->sets)) in cpu_cache_level__read()
1147 return -1; in cpu_cache_level__read()
1150 if (sysfs__read_int(file, (int *) &cache->ways)) in cpu_cache_level__read()
1151 return -1; in cpu_cache_level__read()
1154 if (sysfs__read_str(file, &cache->type, &len)) in cpu_cache_level__read()
1155 return -1; in cpu_cache_level__read()
1157 cache->type[len] = 0; in cpu_cache_level__read()
1158 cache->type = strim(cache->type); in cpu_cache_level__read()
1161 if (sysfs__read_str(file, &cache->size, &len)) { in cpu_cache_level__read()
1162 zfree(&cache->type); in cpu_cache_level__read()
1163 return -1; in cpu_cache_level__read()
1166 cache->size[len] = 0; in cpu_cache_level__read()
1167 cache->size = strim(cache->size); in cpu_cache_level__read()
1170 if (sysfs__read_str(file, &cache->map, &len)) { in cpu_cache_level__read()
1171 zfree(&cache->size); in cpu_cache_level__read()
1172 zfree(&cache->type); in cpu_cache_level__read()
1173 return -1; in cpu_cache_level__read()
1176 cache->map[len] = 0; in cpu_cache_level__read()
1177 cache->map = strim(cache->map); in cpu_cache_level__read()
1183 fprintf(out, "L%d %-15s %8s [%s]\n", c->level, c->type, c->size, c->map); in cpu_cache_level__fprintf()
1225 u32 nr, cpu, cnt = 0; in build_caches() local
1230 int ret = build_caches_for_cpu(cpu, caches, &cnt); in build_caches()
1235 *cntp = cnt; in build_caches()
1244 u32 cnt = 0, i, version = 1; in write_cache() local
1247 ret = build_caches(caches, &cnt); in write_cache()
1251 qsort(&caches, cnt, sizeof(struct cpu_cache_level), cpu_cache_level__sort); in write_cache()
1257 ret = do_write(ff, &cnt, sizeof(u32)); in write_cache()
1261 for (i = 0; i < cnt; i++) { in write_cache()
1265 ret = do_write(ff, &c->v, sizeof(u32)); \ in write_cache()
1276 ret = do_write_string(ff, (const char *) c->v); \ in write_cache()
1287 for (i = 0; i < cnt; i++) in write_cache()
1303 ret = do_write(ff, &evlist->first_sample_time, in write_sample_time()
1304 sizeof(evlist->first_sample_time)); in write_sample_time()
1308 return do_write(ff, &evlist->last_sample_time, in write_sample_time()
1309 sizeof(evlist->last_sample_time)); in write_sample_time()
1322 if (strcmp(ent->d_name, ".") && \ in memory_node__read()
1323 strcmp(ent->d_name, "..") && \ in memory_node__read()
1324 sscanf(ent->d_name, "memory%u", &mem) == 1) in memory_node__read()
1333 return -1; in memory_node__read()
1342 n->set = bitmap_zalloc(size); in memory_node__read()
1343 if (!n->set) { in memory_node__read()
1345 return -ENOMEM; in memory_node__read()
1348 n->node = idx; in memory_node__read()
1349 n->size = size; in memory_node__read()
1354 __set_bit(phys, n->set); in memory_node__read()
1361 static void memory_node__delete_nodes(struct memory_node *nodesp, u64 cnt) in memory_node__delete_nodes() argument
1363 for (u64 i = 0; i < cnt; i++) in memory_node__delete_nodes()
1374 return na->node - nb->node; in memory_node__sort()
1383 size_t cnt = 0, size = 0; in build_mem_topology() local
1393 return -1; in build_mem_topology()
1400 if (!strcmp(ent->d_name, ".") || in build_mem_topology()
1401 !strcmp(ent->d_name, "..")) in build_mem_topology()
1404 r = sscanf(ent->d_name, "node%u", &idx); in build_mem_topology()
1408 if (cnt >= size) { in build_mem_topology()
1410 reallocarray(nodes, cnt + 4, sizeof(*nodes)); in build_mem_topology()
1414 ret = -ENOMEM; in build_mem_topology()
1420 ret = memory_node__read(&nodes[cnt], idx); in build_mem_topology()
1422 cnt += 1; in build_mem_topology()
1427 *cntp = cnt; in build_mem_topology()
1429 qsort(nodes, cnt, sizeof(nodes[0]), memory_node__sort); in build_mem_topology()
1431 memory_node__delete_nodes(nodes, cnt); in build_mem_topology()
1440 * 0 - version | for future changes
1441 * 8 - block_size_bytes | /sys/devices/system/memory/block_size_bytes
1442 * 16 - count | number of nodes
1447 * 32 - node id | node index
1448 * 40 - size | size of bitmap
1449 * 48 - bitmap | bitmap of memory indexes that belongs to node
1483 ret = do_write(ff, &n->v, sizeof(n->v)); \ in write_mem_topology()
1492 ret = do_write_bitmap(ff, n->set, n->size); in write_mem_topology()
1507 ret = do_write(ff, &(ff->ph->env.comp_ver), sizeof(ff->ph->env.comp_ver)); in write_compressed()
1511 ret = do_write(ff, &(ff->ph->env.comp_type), sizeof(ff->ph->env.comp_type)); in write_compressed()
1515 ret = do_write(ff, &(ff->ph->env.comp_level), sizeof(ff->ph->env.comp_level)); in write_compressed()
1519 ret = do_write(ff, &(ff->ph->env.comp_ratio), sizeof(ff->ph->env.comp_ratio)); in write_compressed()
1523 return do_write(ff, &(ff->ph->env.comp_mmap_len), sizeof(ff->ph->env.comp_mmap_len)); in write_compressed()
1532 ret = do_write(ff, &pmu->nr_caps, sizeof(pmu->nr_caps)); in __write_pmu_caps()
1536 list_for_each_entry(caps, &pmu->caps, list) { in __write_pmu_caps()
1537 ret = do_write_string(ff, caps->name); in __write_pmu_caps()
1541 ret = do_write_string(ff, caps->value); in __write_pmu_caps()
1547 ret = do_write_string(ff, pmu->name); in __write_pmu_caps()
1562 return -ENOENT; in write_cpu_pmu_caps()
1579 if (!strcmp(pmu->name, "cpu")) { in write_pmu_caps()
1605 if (!strcmp(pmu->name, "cpu")) { in write_pmu_caps()
1620 fprintf(fp, "# hostname : %s\n", ff->ph->env.hostname); in print_hostname()
1625 fprintf(fp, "# os release : %s\n", ff->ph->env.os_release); in print_osrelease()
1630 fprintf(fp, "# arch : %s\n", ff->ph->env.arch); in print_arch()
1635 fprintf(fp, "# cpudesc : %s\n", ff->ph->env.cpu_desc); in print_cpudesc()
1640 fprintf(fp, "# nrcpus online : %u\n", ff->ph->env.nr_cpus_online); in print_nrcpus()
1641 fprintf(fp, "# nrcpus avail : %u\n", ff->ph->env.nr_cpus_avail); in print_nrcpus()
1646 fprintf(fp, "# perf version : %s\n", ff->ph->env.version); in print_version()
1653 nr = ff->ph->env.nr_cmdline; in print_cmdline()
1658 char *argv_i = strdup(ff->ph->env.cmdline_argv[i]); in print_cmdline()
1660 fprintf(fp, "%s ", ff->ph->env.cmdline_argv[i]); in print_cmdline()
1680 struct perf_header *ph = ff->ph; in print_cpu_topology()
1681 int cpu_nr = ph->env.nr_cpus_avail; in print_cpu_topology()
1685 nr = ph->env.nr_sibling_cores; in print_cpu_topology()
1686 str = ph->env.sibling_cores; in print_cpu_topology()
1693 if (ph->env.nr_sibling_dies) { in print_cpu_topology()
1694 nr = ph->env.nr_sibling_dies; in print_cpu_topology()
1695 str = ph->env.sibling_dies; in print_cpu_topology()
1703 nr = ph->env.nr_sibling_threads; in print_cpu_topology()
1704 str = ph->env.sibling_threads; in print_cpu_topology()
1711 if (ph->env.nr_sibling_dies) { in print_cpu_topology()
1712 if (ph->env.cpu != NULL) { in print_cpu_topology()
1716 i, ph->env.cpu[i].core_id, in print_cpu_topology()
1717 ph->env.cpu[i].die_id, in print_cpu_topology()
1718 ph->env.cpu[i].socket_id); in print_cpu_topology()
1723 if (ph->env.cpu != NULL) { in print_cpu_topology()
1727 i, ph->env.cpu[i].core_id, in print_cpu_topology()
1728 ph->env.cpu[i].socket_id); in print_cpu_topology()
1738 ff->ph->env.clock.clockid_res_ns * 1000); in print_clockid()
1750 if (!ff->ph->env.clock.enabled) { in print_clock_data()
1756 ref = ff->ph->env.clock.tod_ns; in print_clock_data()
1758 ref -= tod_ns.tv_sec * NSEC_PER_SEC; in print_clock_data()
1762 ref = ff->ph->env.clock.clockid_ns; in print_clock_data()
1764 ref -= clockid_ns.tv_sec * NSEC_PER_SEC; in print_clock_data()
1767 clockid = ff->ph->env.clock.clockid; in print_clock_data()
1790 for (i = 0; i < ff->ph->env.nr_hybrid_nodes; i++) { in print_hybrid_topology()
1791 n = &ff->ph->env.hybrid_nodes[i]; in print_hybrid_topology()
1792 fprintf(fp, "# %s cpu list : %s\n", n->pmu_name, n->cpus); in print_hybrid_topology()
1801 session = container_of(ff->ph, struct perf_session, header); in print_dir_format()
1802 data = session->data; in print_dir_format()
1804 fprintf(fp, "# directory data version : %"PRIu64"\n", data->dir.version); in print_dir_format()
1810 struct perf_env *env = &ff->ph->env; in print_bpf_prog_info()
1814 down_read(&env->bpf_progs.lock); in print_bpf_prog_info()
1816 root = &env->bpf_progs.infos; in print_bpf_prog_info()
1826 next = rb_next(&node->rb_node); in print_bpf_prog_info()
1828 __bpf_event__print_bpf_prog_info(&node->info_linear->info, in print_bpf_prog_info()
1832 up_read(&env->bpf_progs.lock); in print_bpf_prog_info()
1837 struct perf_env *env = &ff->ph->env; in print_bpf_btf()
1841 down_read(&env->bpf_progs.lock); in print_bpf_btf()
1843 root = &env->bpf_progs.btfs; in print_bpf_btf()
1853 next = rb_next(&node->rb_node); in print_bpf_btf()
1854 fprintf(fp, "# btf info of id %u\n", node->id); in print_bpf_btf()
1857 up_read(&env->bpf_progs.lock); in print_bpf_btf()
1868 for (evsel = events; evsel->core.attr.size; evsel++) { in free_event_desc()
1869 zfree(&evsel->name); in free_event_desc()
1870 zfree(&evsel->core.id); in free_event_desc()
1876 static bool perf_attr_check(struct perf_event_attr *attr) in perf_attr_check() argument
1878 if (attr->__reserved_1 || attr->__reserved_2 || attr->__reserved_3) { in perf_attr_check()
1884 if (attr->sample_type & ~(PERF_SAMPLE_MAX-1)) { in perf_attr_check()
1887 attr->sample_type); in perf_attr_check()
1891 if (attr->read_format & ~(PERF_FORMAT_MAX-1)) { in perf_attr_check()
1894 attr->read_format); in perf_attr_check()
1898 if ((attr->sample_type & PERF_SAMPLE_BRANCH_STACK) && in perf_attr_check()
1899 (attr->branch_sample_type & ~(PERF_SAMPLE_BRANCH_MAX-1))) { in perf_attr_check()
1902 attr->branch_sample_type); in perf_attr_check()
1925 /* buffer to hold on file attr struct */ in read_event_desc()
1930 /* the last event terminates with evsel->core.attr.size == 0: */ in read_event_desc()
1935 msz = sizeof(evsel->core.attr); in read_event_desc()
1940 evsel->core.idx = i; in read_event_desc()
1943 * must read entire on-file attr struct to in read_event_desc()
1949 if (ff->ph->needs_swap) in read_event_desc()
1952 memcpy(&evsel->core.attr, buf, msz); in read_event_desc()
1954 if (!perf_attr_check(&evsel->core.attr)) in read_event_desc()
1960 if (ff->ph->needs_swap) in read_event_desc()
1961 evsel->needs_swap = true; in read_event_desc()
1963 evsel->name = do_read_string(ff); in read_event_desc()
1964 if (!evsel->name) in read_event_desc()
1973 evsel->core.ids = nr; in read_event_desc()
1974 evsel->core.id = id; in read_event_desc()
1991 static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val, in __desc_attr__fprintf() argument
1994 return fprintf(fp, ", %s = %s", name, val); in __desc_attr__fprintf()
2003 if (ff->events) in print_event_desc()
2004 events = ff->events; in print_event_desc()
2013 for (evsel = events; evsel->core.attr.size; evsel++) { in print_event_desc()
2014 fprintf(fp, "# event : name = %s, ", evsel->name); in print_event_desc()
2016 if (evsel->core.ids) { in print_event_desc()
2018 for (j = 0, id = evsel->core.id; j < evsel->core.ids; j++, id++) { in print_event_desc()
2026 perf_event_attr__fprintf(fp, &evsel->core.attr, __desc_attr__fprintf, NULL); in print_event_desc()
2032 ff->events = NULL; in print_event_desc()
2037 fprintf(fp, "# total memory : %llu kB\n", ff->ph->env.total_mem); in print_total_mem()
2045 for (i = 0; i < ff->ph->env.nr_numa_nodes; i++) { in print_numa_topology()
2046 n = &ff->ph->env.numa_nodes[i]; in print_numa_topology()
2050 n->node, n->mem_total, n->mem_free); in print_numa_topology()
2052 fprintf(fp, "# node%u cpu list : ", n->node); in print_numa_topology()
2053 cpu_map__fprintf(n->map, fp); in print_numa_topology()
2059 fprintf(fp, "# cpuid : %s\n", ff->ph->env.cpuid); in print_cpuid()
2082 for (i = 0; i < ff->ph->env.caches_cnt; i++) { in print_cache()
2084 cpu_cache_level__fprintf(fp, &ff->ph->env.caches[i]); in print_cache()
2091 ff->ph->env.comp_type == PERF_COMP_ZSTD ? "Zstd" : "Unknown", in print_compressed()
2092 ff->ph->env.comp_level, ff->ph->env.comp_ratio); in print_compressed()
2116 __print_pmu_caps(fp, ff->ph->env.nr_cpu_pmu_caps, in print_cpu_pmu_caps()
2117 ff->ph->env.cpu_pmu_caps, (char *)"cpu"); in print_cpu_pmu_caps()
2122 struct perf_env *env = &ff->ph->env; in print_pmu_caps()
2125 for (int i = 0; i < env->nr_pmus_with_caps; i++) { in print_pmu_caps()
2126 pmu_caps = &env->pmu_caps[i]; in print_pmu_caps()
2127 __print_pmu_caps(fp, pmu_caps->nr_caps, pmu_caps->caps, in print_pmu_caps()
2128 pmu_caps->pmu_name); in print_pmu_caps()
2142 struct perf_env *env = &ff->ph->env; in print_pmu_mappings()
2148 pmu_num = env->nr_pmu_mappings; in print_pmu_mappings()
2154 str = env->pmu_mappings; in print_pmu_mappings()
2166 pmu_num--; in print_pmu_mappings()
2183 session = container_of(ff->ph, struct perf_session, header); in print_group_desc()
2185 evlist__for_each_entry(session->evlist, evsel) { in print_group_desc()
2186 if (evsel__is_group_leader(evsel) && evsel->core.nr_members > 1) { in print_group_desc()
2187 fprintf(fp, "# group: %s{%s", evsel->group_name ?: "", evsel__name(evsel)); in print_group_desc()
2189 nr = evsel->core.nr_members - 1; in print_group_desc()
2193 if (--nr == 0) in print_group_desc()
2205 session = container_of(ff->ph, struct perf_session, header); in print_sample_time()
2207 timestamp__scnprintf_usec(session->evlist->first_sample_time, in print_sample_time()
2211 timestamp__scnprintf_usec(session->evlist->last_sample_time, in print_sample_time()
2215 d = (double)(session->evlist->last_sample_time - in print_sample_time()
2216 session->evlist->first_sample_time) / NSEC_PER_MSEC; in print_sample_time()
2227 size = bsize * bitmap_weight(n->set, n->size); in memory_node__fprintf()
2230 bitmap_scnprintf(n->set, n->size, buf_map, 100); in memory_node__fprintf()
2231 fprintf(fp, "# %3" PRIu64 " [%s]: %s\n", n->node, buf_size, buf_map); in memory_node__fprintf()
2236 struct perf_env *env = &ff->ph->env; in print_mem_topology()
2240 nodes = env->memory_nodes; in print_mem_topology()
2241 nr = env->nr_memory_nodes; in print_mem_topology()
2244 nr, env->memory_bsize); in print_mem_topology()
2247 memory_node__fprintf(&nodes[i], env->memory_bsize, fp); in print_mem_topology()
2255 int err = -1; in __event_process_build_id()
2261 machine = perf_session__findnew_machine(session, bev->pid); in __event_process_build_id()
2265 cpumode = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; in __event_process_build_id()
2288 if (bev->header.misc & PERF_RECORD_MISC_BUILD_ID_SIZE) in __event_process_build_id()
2289 size = bev->size; in __event_process_build_id()
2291 build_id__init(&bid, bev->data, size); in __event_process_build_id()
2296 struct kmod_path m = { .name = NULL, }; in __event_process_build_id()
2302 free(m.name); in __event_process_build_id()
2333 return -1; in perf_header__read_build_ids_abi_quirk()
2335 if (header->needs_swap) in perf_header__read_build_ids_abi_quirk()
2338 len = old_bev.header.size - sizeof(old_bev); in perf_header__read_build_ids_abi_quirk()
2340 return -1; in perf_header__read_build_ids_abi_quirk()
2369 int err = -1; in perf_header__read_build_ids()
2377 if (header->needs_swap) in perf_header__read_build_ids()
2380 len = bev.header.size - sizeof(bev); in perf_header__read_build_ids()
2391 * Since the kernel build-id is the first entry, process the in perf_header__read_build_ids()
2393 * '[kernel.kallsyms]' string for the kernel build-id has the in perf_header__read_build_ids()
2397 if (lseek(input, orig_offset, SEEK_SET) == (off_t)-1) in perf_header__read_build_ids()
2398 return -1; in perf_header__read_build_ids()
2415 free(ff->ph->env.__feat_env); \
2416 ff->ph->env.__feat_env = do_read_string(ff); \
2417 return ff->ph->env.__feat_env ? 0 : -ENOMEM; \
2430 ssize_t ret = trace_report(ff->fd, data, false); in process_tracing_data()
2432 return ret < 0 ? -1 : 0; in process_tracing_data()
2438 if (perf_header__read_build_ids(ff->ph, ff->fd, ff->offset, ff->size)) in process_build_id()
2445 struct perf_env *env = &ff->ph->env; in process_nrcpus()
2456 env->nr_cpus_avail = (int)nr_cpus_avail; in process_nrcpus()
2457 env->nr_cpus_online = (int)nr_cpus_online; in process_nrcpus()
2463 struct perf_env *env = &ff->ph->env; in process_total_mem()
2469 return -1; in process_total_mem()
2470 env->total_mem = (unsigned long long)total_mem; in process_total_mem()
2479 if (evsel->core.idx == idx) in evlist__find_by_index()
2490 if (!event->name) in evlist__set_event_name()
2493 evsel = evlist__find_by_index(evlist, event->core.idx); in evlist__set_event_name()
2497 if (evsel->name) in evlist__set_event_name()
2500 evsel->name = strdup(event->name); in evlist__set_event_name()
2512 session = container_of(ff->ph, struct perf_session, header); in process_event_desc()
2514 if (session->data->is_pipe) { in process_event_desc()
2517 ff->events = events; in process_event_desc()
2520 for (evsel = events; evsel->core.attr.size; evsel++) in process_event_desc()
2521 evlist__set_event_name(session->evlist, evsel); in process_event_desc()
2523 if (!session->data->is_pipe) in process_event_desc()
2531 struct perf_env *env = &ff->ph->env; in process_cmdline()
2536 return -1; in process_cmdline()
2538 env->nr_cmdline = nr; in process_cmdline()
2540 cmdline = zalloc(ff->size + nr + 1); in process_cmdline()
2542 return -1; in process_cmdline()
2558 env->cmdline = cmdline; in process_cmdline()
2559 env->cmdline_argv = (const char **) argv; in process_cmdline()
2565 return -1; in process_cmdline()
2573 struct perf_env *env = &ff->ph->env; in process_cpu_topology()
2574 int cpu_nr = env->nr_cpus_avail; in process_cpu_topology()
2577 env->cpu = calloc(cpu_nr, sizeof(*env->cpu)); in process_cpu_topology()
2578 if (!env->cpu) in process_cpu_topology()
2579 return -1; in process_cpu_topology()
2584 env->nr_sibling_cores = nr; in process_cpu_topology()
2600 env->sibling_cores = strbuf_detach(&sb, NULL); in process_cpu_topology()
2603 return -1; in process_cpu_topology()
2605 env->nr_sibling_threads = nr; in process_cpu_topology()
2619 env->sibling_threads = strbuf_detach(&sb, NULL); in process_cpu_topology()
2625 if (ff->size <= size) { in process_cpu_topology()
2626 zfree(&env->cpu); in process_cpu_topology()
2634 env->cpu[i].core_id = nr; in process_cpu_topology()
2640 env->cpu[i].socket_id = nr; in process_cpu_topology()
2648 if (ff->size <= size) in process_cpu_topology()
2652 return -1; in process_cpu_topology()
2654 env->nr_sibling_dies = nr; in process_cpu_topology()
2668 env->sibling_dies = strbuf_detach(&sb, NULL); in process_cpu_topology()
2674 env->cpu[i].die_id = nr; in process_cpu_topology()
2683 zfree(&env->cpu); in process_cpu_topology()
2684 return -1; in process_cpu_topology()
2689 struct perf_env *env = &ff->ph->env; in process_numa_topology()
2696 return -1; in process_numa_topology()
2700 return -ENOMEM; in process_numa_topology()
2706 if (do_read_u32(ff, &n->node)) in process_numa_topology()
2709 if (do_read_u64(ff, &n->mem_total)) in process_numa_topology()
2712 if (do_read_u64(ff, &n->mem_free)) in process_numa_topology()
2719 n->map = perf_cpu_map__new(str); in process_numa_topology()
2721 if (!n->map) in process_numa_topology()
2724 env->nr_numa_nodes = nr; in process_numa_topology()
2725 env->numa_nodes = nodes; in process_numa_topology()
2730 return -1; in process_numa_topology()
2735 struct perf_env *env = &ff->ph->env; in process_pmu_mappings()
2736 char *name; in process_pmu_mappings() local
2742 return -1; in process_pmu_mappings()
2749 env->nr_pmu_mappings = pmu_num; in process_pmu_mappings()
2751 return -1; in process_pmu_mappings()
2757 name = do_read_string(ff); in process_pmu_mappings()
2758 if (!name) in process_pmu_mappings()
2761 if (strbuf_addf(&sb, "%u:%s", type, name) < 0) in process_pmu_mappings()
2767 if (!strcmp(name, "msr")) in process_pmu_mappings()
2768 env->msr_pmu_type = type; in process_pmu_mappings()
2770 free(name); in process_pmu_mappings()
2771 pmu_num--; in process_pmu_mappings()
2774 free(env->pmu_mappings); in process_pmu_mappings()
2775 env->pmu_mappings = strbuf_detach(&sb, NULL); in process_pmu_mappings()
2780 return -1; in process_pmu_mappings()
2785 struct perf_env *env = &ff->ph->env; in process_group_desc()
2786 size_t ret = -1; in process_group_desc()
2791 char *name; in process_group_desc() member
2797 return -1; in process_group_desc()
2799 env->nr_groups = nr_groups; in process_group_desc()
2807 return -1; in process_group_desc()
2810 desc[i].name = do_read_string(ff); in process_group_desc()
2811 if (!desc[i].name) in process_group_desc()
2824 session = container_of(ff->ph, struct perf_session, header); in process_group_desc()
2827 evlist__for_each_entry(session->evlist, evsel) { in process_group_desc()
2828 if (i < nr_groups && evsel->core.idx == (int) desc[i].leader_idx) { in process_group_desc()
2830 /* {anon_group} is a dummy name */ in process_group_desc()
2831 if (strcmp(desc[i].name, "{anon_group}")) { in process_group_desc()
2832 evsel->group_name = desc[i].name; in process_group_desc()
2833 desc[i].name = NULL; in process_group_desc()
2835 evsel->core.nr_members = desc[i].nr_members; in process_group_desc()
2843 nr = evsel->core.nr_members - 1; in process_group_desc()
2849 nr--; in process_group_desc()
2861 zfree(&desc[i].name); in process_group_desc()
2872 session = container_of(ff->ph, struct perf_session, header); in process_auxtrace()
2874 err = auxtrace_index__process(ff->fd, ff->size, session, in process_auxtrace()
2875 ff->ph->needs_swap); in process_auxtrace()
2883 struct perf_env *env = &ff->ph->env; in process_cache()
2885 u32 cnt, i, version; in process_cache() local
2888 return -1; in process_cache()
2891 return -1; in process_cache()
2893 if (do_read_u32(ff, &cnt)) in process_cache()
2894 return -1; in process_cache()
2896 caches = zalloc(sizeof(*caches) * cnt); in process_cache()
2898 return -1; in process_cache()
2900 for (i = 0; i < cnt; i++) { in process_cache()
2904 if (do_read_u32(ff, &c->v)) \ in process_cache()
2914 c->v = do_read_string(ff); \ in process_cache()
2915 if (!c->v) \ in process_cache()
2924 env->caches = caches; in process_cache()
2925 env->caches_cnt = cnt; in process_cache()
2928 for (i = 0; i < cnt; i++) { in process_cache()
2934 return -1; in process_cache()
2943 session = container_of(ff->ph, struct perf_session, header); in process_sample_time()
2947 return -1; in process_sample_time()
2951 return -1; in process_sample_time()
2953 session->evlist->first_sample_time = first_sample_time; in process_sample_time()
2954 session->evlist->last_sample_time = last_sample_time; in process_sample_time()
2961 struct perf_env *env = &ff->ph->env; in process_mem_topology()
2964 int ret = -1; in process_mem_topology()
2967 return -1; in process_mem_topology()
2970 return -1; in process_mem_topology()
2973 return -1; in process_mem_topology()
2976 return -1; in process_mem_topology()
2980 return -1; in process_mem_topology()
3000 env->memory_bsize = bsize; in process_mem_topology()
3001 env->memory_nodes = nodes; in process_mem_topology()
3002 env->nr_memory_nodes = nr; in process_mem_topology()
3014 struct perf_env *env = &ff->ph->env; in process_clockid()
3016 if (do_read_u64(ff, &env->clock.clockid_res_ns)) in process_clockid()
3017 return -1; in process_clockid()
3025 struct perf_env *env = &ff->ph->env; in process_clock_data()
3031 return -1; in process_clock_data()
3034 return -1; in process_clock_data()
3038 return -1; in process_clock_data()
3040 env->clock.clockid = data32; in process_clock_data()
3044 return -1; in process_clock_data()
3046 env->clock.tod_ns = data64; in process_clock_data()
3050 return -1; in process_clock_data()
3052 env->clock.clockid_ns = data64; in process_clock_data()
3053 env->clock.enabled = true; in process_clock_data()
3060 struct perf_env *env = &ff->ph->env; in process_hybrid_topology()
3066 return -1; in process_hybrid_topology()
3070 return -ENOMEM; in process_hybrid_topology()
3075 n->pmu_name = do_read_string(ff); in process_hybrid_topology()
3076 if (!n->pmu_name) in process_hybrid_topology()
3079 n->cpus = do_read_string(ff); in process_hybrid_topology()
3080 if (!n->cpus) in process_hybrid_topology()
3084 env->nr_hybrid_nodes = nr; in process_hybrid_topology()
3085 env->hybrid_nodes = nodes; in process_hybrid_topology()
3095 return -1; in process_hybrid_topology()
3104 session = container_of(ff->ph, struct perf_session, header); in process_dir_format()
3105 data = session->data; in process_dir_format()
3108 return -1; in process_dir_format()
3110 return do_read_u64(ff, &data->dir.version); in process_dir_format()
3117 struct perf_env *env = &ff->ph->env; in process_bpf_prog_info()
3120 int err = -1; in process_bpf_prog_info()
3122 if (ff->ph->needs_swap) { in process_bpf_prog_info()
3128 return -1; in process_bpf_prog_info()
3130 down_write(&env->bpf_progs.lock); in process_bpf_prog_info()
3151 info_linear->info_len = sizeof(struct bpf_prog_info); in process_bpf_prog_info()
3152 info_linear->data_len = data_len; in process_bpf_prog_info()
3153 if (do_read_u64(ff, (u64 *)(&info_linear->arrays))) in process_bpf_prog_info()
3155 if (__do_read(ff, &info_linear->info, info_len)) in process_bpf_prog_info()
3158 memset(((void *)(&info_linear->info)) + info_len, 0, in process_bpf_prog_info()
3159 sizeof(struct bpf_prog_info) - info_len); in process_bpf_prog_info()
3161 if (__do_read(ff, info_linear->data, data_len)) in process_bpf_prog_info()
3170 info_node->info_linear = info_linear; in process_bpf_prog_info()
3171 info_node->metadata = NULL; in process_bpf_prog_info()
3178 up_write(&env->bpf_progs.lock); in process_bpf_prog_info()
3183 up_write(&env->bpf_progs.lock); in process_bpf_prog_info()
3189 struct perf_env *env = &ff->ph->env; in process_bpf_btf()
3192 int err = -1; in process_bpf_btf()
3194 if (ff->ph->needs_swap) { in process_bpf_btf()
3200 return -1; in process_bpf_btf()
3202 down_write(&env->bpf_progs.lock); in process_bpf_btf()
3216 node->id = id; in process_bpf_btf()
3217 node->data_size = data_size; in process_bpf_btf()
3219 if (__do_read(ff, node->data, data_size)) in process_bpf_btf()
3229 up_write(&env->bpf_progs.lock); in process_bpf_btf()
3238 struct perf_env *env = &ff->ph->env; in process_compressed()
3240 if (do_read_u32(ff, &(env->comp_ver))) in process_compressed()
3241 return -1; in process_compressed()
3243 if (do_read_u32(ff, &(env->comp_type))) in process_compressed()
3244 return -1; in process_compressed()
3246 if (do_read_u32(ff, &(env->comp_level))) in process_compressed()
3247 return -1; in process_compressed()
3249 if (do_read_u32(ff, &(env->comp_ratio))) in process_compressed()
3250 return -1; in process_compressed()
3252 if (do_read_u32(ff, &(env->comp_mmap_len))) in process_compressed()
3253 return -1; in process_compressed()
3263 char *name, *value, *ptr; in __process_pmu_caps() local
3270 return -1; in __process_pmu_caps()
3277 return -1; in __process_pmu_caps()
3280 name = do_read_string(ff); in __process_pmu_caps()
3281 if (!name) in __process_pmu_caps()
3288 if (asprintf(&ptr, "%s=%s", name, value) < 0) in __process_pmu_caps()
3293 if (!strcmp(name, "branches")) in __process_pmu_caps()
3296 if (!strcmp(name, "branch_counter_nr")) in __process_pmu_caps()
3299 if (!strcmp(name, "branch_counter_width")) in __process_pmu_caps()
3303 free(name); in __process_pmu_caps()
3311 free(name); in __process_pmu_caps()
3313 for (; i > 0; i--) in __process_pmu_caps()
3314 free((*caps)[i - 1]); in __process_pmu_caps()
3318 return -1; in __process_pmu_caps()
3324 struct perf_env *env = &ff->ph->env; in process_cpu_pmu_caps()
3325 int ret = __process_pmu_caps(ff, &env->nr_cpu_pmu_caps, in process_cpu_pmu_caps()
3326 &env->cpu_pmu_caps, in process_cpu_pmu_caps()
3327 &env->max_branches, in process_cpu_pmu_caps()
3328 &env->br_cntr_nr, in process_cpu_pmu_caps()
3329 &env->br_cntr_width); in process_cpu_pmu_caps()
3331 if (!ret && !env->cpu_pmu_caps) in process_cpu_pmu_caps()
3338 struct perf_env *env = &ff->ph->env; in process_pmu_caps()
3345 return -1; in process_pmu_caps()
3354 return -ENOMEM; in process_pmu_caps()
3367 ret = -1; in process_pmu_caps()
3376 env->nr_pmus_with_caps = nr_pmu; in process_pmu_caps()
3377 env->pmu_caps = pmu_caps; in process_pmu_caps()
3394 .name = __stringify(n), \
3404 .name = __stringify(n), \
3418 // Only used in util/synthetic-events.c
3471 if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { in perf_file_section__fprintf_info()
3473 "%d, continuing...\n", section->offset, feat); in perf_file_section__fprintf_info()
3488 if (!feat_ops[feat].full_only || hd->full) in perf_file_section__fprintf_info()
3489 feat_ops[feat].print(&ff, hd->fp); in perf_file_section__fprintf_info()
3491 fprintf(hd->fp, "# %s info available, use -I to display\n", in perf_file_section__fprintf_info()
3492 feat_ops[feat].name); in perf_file_section__fprintf_info()
3500 struct perf_header *header = &session->header; in perf_header__fprintf_info()
3501 int fd = perf_data__fd(session->data); in perf_header__fprintf_info()
3510 if (ret == -1) in perf_header__fprintf_info()
3511 return -1; in perf_header__fprintf_info()
3516 fprintf(fp, "# header version : %u\n", header->version); in perf_header__fprintf_info()
3517 fprintf(fp, "# data offset : %" PRIu64 "\n", header->data_offset); in perf_header__fprintf_info()
3518 fprintf(fp, "# data size : %" PRIu64 "\n", header->data_size); in perf_header__fprintf_info()
3519 fprintf(fp, "# feat offset : %" PRIu64 "\n", header->feat_offset); in perf_header__fprintf_info()
3524 if (session->data->is_pipe) in perf_header__fprintf_info()
3528 for_each_clear_bit(bit, header->adds_features, HEADER_LAST_FEATURE) { in perf_header__fprintf_info()
3530 fprintf(fp, "%s ", feat_ops[bit].name); in perf_header__fprintf_info()
3546 return do_write(h->ff, buf, sz); in feat_writer_cb()
3557 if (perf_header__has_feat(ff->ph, type)) { in do_write_feat()
3559 return -1; in do_write_feat()
3561 if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) in do_write_feat()
3562 return -1; in do_write_feat()
3564 (*p)->offset = lseek(ff->fd, 0, SEEK_CUR); in do_write_feat()
3570 if (fc && fc->copy) { in do_write_feat()
3576 /* ->copy() returns 0 if the feature was not copied */ in do_write_feat()
3577 err = fc->copy(fc, type, &h.fw); in do_write_feat()
3584 pr_debug("failed to write feature %s\n", feat_ops[type].name); in do_write_feat()
3587 lseek(ff->fd, (*p)->offset, SEEK_SET); in do_write_feat()
3589 return -1; in do_write_feat()
3591 (*p)->size = lseek(ff->fd, 0, SEEK_CUR) - (*p)->offset; in do_write_feat()
3612 nr_sections = bitmap_weight(header->adds_features, HEADER_FEAT_BITS); in perf_header__adds_write()
3618 return -ENOMEM; in perf_header__adds_write()
3622 sec_start = header->feat_offset; in perf_header__adds_write()
3625 for_each_set_bit(feat, header->adds_features, HEADER_FEAT_BITS) { in perf_header__adds_write()
3638 free(ff.buf); /* TODO: added to silence clang-tidy. */ in perf_header__adds_write()
3672 struct perf_header *header = &session->header; in perf_session__do_write_header()
3686 if (!header->data_offset && header->data_size) { in perf_session__do_write_header()
3688 err = -1; in perf_session__do_write_header()
3691 header->feat_offset = header->data_offset + header->data_size; in perf_session__do_write_header()
3700 evlist__for_each_entry(session->evlist, evsel) { in perf_session__do_write_header()
3701 evsel->id_offset = attr_offset; in perf_session__do_write_header()
3704 err = do_write(&ff, evsel->core.id, evsel->core.ids * sizeof(u64)); in perf_session__do_write_header()
3710 attr_offset += evsel->core.ids * sizeof(u64); in perf_session__do_write_header()
3714 if (evsel->core.attr.size < sizeof(evsel->core.attr)) { in perf_session__do_write_header()
3717 * from an older file. Update attr size so that in perf_session__do_write_header()
3720 evsel->core.attr.size = sizeof(evsel->core.attr); in perf_session__do_write_header()
3725 .attr = evsel->core.attr, in perf_session__do_write_header()
3727 .offset = evsel->id_offset, in perf_session__do_write_header()
3728 .size = evsel->core.ids * sizeof(u64), in perf_session__do_write_header()
3740 if (!header->data_offset) { in perf_session__do_write_header()
3742 header->data_offset = sizeof(f_header); in perf_session__do_write_header()
3744 header->data_offset = attr_offset + attr_size; in perf_session__do_write_header()
3746 header->feat_offset = header->data_offset + header->data_size; in perf_session__do_write_header()
3764 .offset = header->data_offset, in perf_session__do_write_header()
3765 .size = header->data_size, in perf_session__do_write_header()
3770 memcpy(&f_header.adds_features, &header->adds_features, sizeof(header->adds_features)); in perf_session__do_write_header()
3801 data_offset += evsel->core.ids * sizeof(u64); in perf_session__data_offset()
3803 data_offset += evlist->core.nr_entries * sizeof(struct perf_file_attr); in perf_session__data_offset()
3822 return -1; in perf_header__getbuffer64()
3824 if (header->needs_swap) in perf_header__getbuffer64()
3842 nr_sections = bitmap_weight(header->adds_features, HEADER_FEAT_BITS); in perf_header__process_sections()
3848 return -1; in perf_header__process_sections()
3852 lseek(fd, header->feat_offset, SEEK_SET); in perf_header__process_sections()
3858 for_each_set_bit(feat, header->adds_features, HEADER_LAST_FEATURE) { in perf_header__process_sections()
3897 ph->needs_swap = true; in try_all_file_abis()
3901 ph->needs_swap); in try_all_file_abis()
3905 return -1; in try_all_file_abis()
3933 ph->needs_swap = true; in try_all_pipe_abis()
3938 return -1; in try_all_pipe_abis()
3959 ph->version = PERF_HEADER_VERSION_1; in check_magic_endian()
3968 * - unique number to identify actual perf.data files in check_magic_endian()
3969 * - encode endianness of file in check_magic_endian()
3971 ph->version = PERF_HEADER_VERSION_2; in check_magic_endian()
3979 return -1; in check_magic_endian()
3981 ph->needs_swap = true; in check_magic_endian()
3995 return -1; in perf_file_header__read()
3997 if (check_magic_endian(header->magic, in perf_file_header__read()
3998 header->attr_size, false, ph) < 0) { in perf_file_header__read()
4000 return -1; in perf_file_header__read()
4003 if (ph->needs_swap) { in perf_file_header__read()
4008 if (header->size > header->attrs.offset) { in perf_file_header__read()
4010 return -1; in perf_file_header__read()
4013 if (header->size > header->data.offset) { in perf_file_header__read()
4015 return -1; in perf_file_header__read()
4018 if ((header->attrs.offset <= header->data.offset && in perf_file_header__read()
4019 header->attrs.offset + header->attrs.size > header->data.offset) || in perf_file_header__read()
4020 (header->attrs.offset > header->data.offset && in perf_file_header__read()
4021 header->data.offset + header->data.size > header->attrs.offset)) { in perf_file_header__read()
4023 return -1; in perf_file_header__read()
4026 if (header->size != sizeof(*header)) { in perf_file_header__read()
4028 if (header->size == offsetof(typeof(*header), adds_features)) in perf_file_header__read()
4029 bitmap_zero(header->adds_features, HEADER_FEAT_BITS); in perf_file_header__read()
4031 return -1; in perf_file_header__read()
4032 } else if (ph->needs_swap) { in perf_file_header__read()
4034 * feature bitmap is declared as an array of unsigned longs -- in perf_file_header__read()
4040 * guess at determining it: try 64-bit swap first (ie., file in perf_file_header__read()
4041 * created on a 64-bit host), and check if the hostname feature in perf_file_header__read()
4043 * If the bit is not, undo the 64-bit swap and try a 32-bit in perf_file_header__read()
4045 * file), punt and fallback to the original behavior -- in perf_file_header__read()
4048 mem_bswap_64(&header->adds_features, in perf_file_header__read()
4051 if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { in perf_file_header__read()
4053 mem_bswap_64(&header->adds_features, in perf_file_header__read()
4057 mem_bswap_32(&header->adds_features, in perf_file_header__read()
4061 if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { in perf_file_header__read()
4062 bitmap_zero(header->adds_features, HEADER_FEAT_BITS); in perf_file_header__read()
4063 __set_bit(HEADER_BUILD_ID, header->adds_features); in perf_file_header__read()
4067 memcpy(&ph->adds_features, &header->adds_features, in perf_file_header__read()
4068 sizeof(ph->adds_features)); in perf_file_header__read()
4070 ph->data_offset = header->data.offset; in perf_file_header__read()
4071 ph->data_size = header->data.size; in perf_file_header__read()
4072 ph->feat_offset = header->data.offset + header->data.size; in perf_file_header__read()
4083 .size = section->size, in perf_file_section__process()
4084 .offset = section->offset, in perf_file_section__process()
4087 if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { in perf_file_section__process()
4089 "%d, continuing...\n", section->offset, feat); in perf_file_section__process()
4112 return -1; in perf_file_header__read_pipe()
4114 if (check_magic_endian(header->magic, header->size, true, ph) < 0) { in perf_file_header__read_pipe()
4116 return -1; in perf_file_header__read_pipe()
4119 if (ph->needs_swap) in perf_file_header__read_pipe()
4120 header->size = bswap_64(header->size); in perf_file_header__read_pipe()
4127 struct perf_header *header = &session->header; in perf_header__read_pipe()
4130 if (perf_file_header__read_pipe(&f_header, header, session->data) < 0) { in perf_header__read_pipe()
4132 return -EINVAL; in perf_header__read_pipe()
4135 return f_header.size == sizeof(f_header) ? 0 : -1; in perf_header__read_pipe()
4141 struct perf_event_attr *attr = &f_attr->attr; in read_attr() local
4143 size_t our_sz = sizeof(f_attr->attr); in read_attr()
4149 ret = readn(fd, attr, PERF_ATTR_SIZE_VER0); in read_attr()
4151 pr_debug("cannot read %d bytes of header attr\n", in read_attr()
4153 return -1; in read_attr()
4157 sz = attr->size; in read_attr()
4159 if (ph->needs_swap) in read_attr()
4167 " (%zu bytes extra)\n", sz - our_sz); in read_attr()
4168 return -1; in read_attr()
4171 left = sz - PERF_ATTR_SIZE_VER0; in read_attr()
4173 void *ptr = attr; in read_attr()
4179 ret = readn(fd, &f_attr->ids, sizeof(f_attr->ids)); in read_attr()
4181 return ret <= 0 ? -1 : 0; in read_attr()
4191 if (evsel->tp_format) in evsel__prepare_tracepoint_event()
4196 return -1; in evsel__prepare_tracepoint_event()
4199 event = tep_find_event(pevent, evsel->core.attr.config); in evsel__prepare_tracepoint_event()
4201 pr_debug("cannot find event format for %d\n", (int)evsel->core.attr.config); in evsel__prepare_tracepoint_event()
4202 return -1; in evsel__prepare_tracepoint_event()
4205 if (!evsel->name) { in evsel__prepare_tracepoint_event()
4206 snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name); in evsel__prepare_tracepoint_event()
4207 evsel->name = strdup(bf); in evsel__prepare_tracepoint_event()
4208 if (evsel->name == NULL) in evsel__prepare_tracepoint_event()
4209 return -1; in evsel__prepare_tracepoint_event()
4212 evsel->tp_format = event; in evsel__prepare_tracepoint_event()
4221 if (pos->core.attr.type == PERF_TYPE_TRACEPOINT && in evlist__prepare_tracepoint_events()
4223 return -1; in evlist__prepare_tracepoint_events()
4232 struct perf_data *data = session->data; in perf_session__read_header()
4233 struct perf_header *header = &session->header; in perf_session__read_header()
4240 session->evlist = evlist__new(); in perf_session__read_header()
4241 if (session->evlist == NULL) in perf_session__read_header()
4242 return -ENOMEM; in perf_session__read_header()
4244 session->evlist->session = session; in perf_session__read_header()
4245 session->machines.host.env = &header->env; in perf_session__read_header()
4253 data->is_pipe = true; in perf_session__read_header()
4258 return -EINVAL; in perf_session__read_header()
4260 if (header->needs_swap && data->in_place_update) { in perf_session__read_header()
4261 pr_err("In-place update not supported when byte-swapping is required\n"); in perf_session__read_header()
4262 return -EINVAL; in perf_session__read_header()
4274 data->file.path); in perf_session__read_header()
4278 pr_err("ERROR: The %s file's attr size field is 0 which is unexpected.\n" in perf_session__read_header()
4280 data->file.path); in perf_session__read_header()
4281 return -EINVAL; in perf_session__read_header()
4294 if (header->needs_swap) { in perf_session__read_header()
4297 perf_event__attr_swap(&f_attr.attr); in perf_session__read_header()
4301 evsel = evsel__new(&f_attr.attr); in perf_session__read_header()
4306 evsel->needs_swap = header->needs_swap; in perf_session__read_header()
4311 evlist__add(session->evlist, evsel); in perf_session__read_header()
4317 * hattr->ids threads. in perf_session__read_header()
4319 if (perf_evsel__alloc_id(&evsel->core, 1, nr_ids)) in perf_session__read_header()
4328 perf_evlist__id_add(&session->evlist->core, &evsel->core, 0, j, f_id); in perf_session__read_header()
4335 perf_header__process_sections(header, fd, &session->tevent, in perf_session__read_header()
4338 if (evlist__prepare_tracepoint_events(session->evlist, session->tevent.pevent)) in perf_session__read_header()
4346 return -errno; in perf_session__read_header()
4349 evlist__delete(session->evlist); in perf_session__read_header()
4350 session->evlist = NULL; in perf_session__read_header()
4351 return -ENOMEM; in perf_session__read_header()
4359 int type = fe->header.type; in perf_event__process_feature()
4360 u64 feat = fe->feat_id; in perf_event__process_feature()
4365 pr_warning("invalid record type %d in pipe-mode\n", type); in perf_event__process_feature()
4369 pr_warning("invalid record type %d in pipe-mode\n", type); in perf_event__process_feature()
4370 return -1; in perf_event__process_feature()
4373 ff.buf = (void *)fe->data; in perf_event__process_feature()
4374 ff.size = event->header.size - sizeof(*fe); in perf_event__process_feature()
4375 ff.ph = &session->header; in perf_event__process_feature()
4378 ret = -1; in perf_event__process_feature()
4382 if (session->tool->show_feat_hdr) { in perf_event__process_feature()
4384 session->tool->show_feat_hdr >= SHOW_FEAT_HEADER_FULL_INFO) { in perf_event__process_feature()
4387 fprintf(stdout, "# %s info available, use -I to display\n", in perf_event__process_feature()
4388 feat_ops[feat].name); in perf_event__process_feature()
4399 printf("# %s", feat_ops[feat].name); in perf_event__process_feature()
4409 struct perf_record_event_update *ev = &event->event_update; in perf_event__fprintf_event_update()
4413 ret = fprintf(fp, "\n... id: %" PRI_lu64 "\n", ev->id); in perf_event__fprintf_event_update()
4415 switch (ev->type) { in perf_event__fprintf_event_update()
4417 ret += fprintf(fp, "... scale: %f\n", ev->scale.scale); in perf_event__fprintf_event_update()
4420 ret += fprintf(fp, "... unit: %s\n", ev->unit); in perf_event__fprintf_event_update()
4423 ret += fprintf(fp, "... name: %s\n", ev->name); in perf_event__fprintf_event_update()
4428 map = cpu_map__new_data(&ev->cpus.cpus); in perf_event__fprintf_event_update()
4445 return perf_event_attr__fprintf(fp, &event->attr.attr, __desc_attr__fprintf, NULL); in perf_event__fprintf_attr()
4463 return -ENOMEM; in perf_event__process_attr()
4466 evsel = evsel__new(&event->attr.attr); in perf_event__process_attr()
4468 return -ENOMEM; in perf_event__process_attr()
4472 n_ids = event->header.size - sizeof(event->header) - event->attr.attr.size; in perf_event__process_attr()
4477 * hattr->ids threads. in perf_event__process_attr()
4479 if (perf_evsel__alloc_id(&evsel->core, 1, n_ids)) in perf_event__process_attr()
4480 return -ENOMEM; in perf_event__process_attr()
4484 perf_evlist__id_add(&evlist->core, &evsel->core, 0, i, ids[i]); in perf_event__process_attr()
4494 struct perf_record_event_update *ev = &event->event_update; in perf_event__process_event_update()
4503 return -EINVAL; in perf_event__process_event_update()
4507 evsel = evlist__id2evsel(evlist, ev->id); in perf_event__process_event_update()
4509 return -EINVAL; in perf_event__process_event_update()
4511 switch (ev->type) { in perf_event__process_event_update()
4513 free((char *)evsel->unit); in perf_event__process_event_update()
4514 evsel->unit = strdup(ev->unit); in perf_event__process_event_update()
4517 free(evsel->name); in perf_event__process_event_update()
4518 evsel->name = strdup(ev->name); in perf_event__process_event_update()
4521 evsel->scale = ev->scale.scale; in perf_event__process_event_update()
4524 map = cpu_map__new_data(&ev->cpus.cpus); in perf_event__process_event_update()
4526 perf_cpu_map__put(evsel->core.pmu_cpus); in perf_event__process_event_update()
4527 evsel->core.pmu_cpus = map; in perf_event__process_event_update()
4541 ssize_t size_read, padding, size = event->tracing_data.size; in perf_event__process_tracing_data()
4542 int fd = perf_data__fd(session->data); in perf_event__process_tracing_data()
4552 if (!perf_data__is_pipe(session->data)) { in perf_event__process_tracing_data()
4560 size_read = trace_report(fd, &session->tevent, session->trace_event_repipe); in perf_event__process_tracing_data()
4561 padding = PERF_ALIGN(size_read, sizeof(u64)) - size_read; in perf_event__process_tracing_data()
4565 return -1; in perf_event__process_tracing_data()
4567 if (session->trace_event_repipe) { in perf_event__process_tracing_data()
4571 return -1; in perf_event__process_tracing_data()
4577 return -1; in perf_event__process_tracing_data()
4580 evlist__prepare_tracepoint_events(session->evlist, session->tevent.pevent); in perf_event__process_tracing_data()
4589 __event_process_build_id(&event->build_id, in perf_event__process_build_id()
4590 event->build_id.filename, in perf_event__process_build_id()