process_synthesized_event,
&rec->session->machines.host,
rec->opts.sample_address);
- thread_map__put(thread_map);
+ perf_thread_map__put(thread_map);
return err;
}
LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid);
+LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread);
+
+LIBPERF_API struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map);
+LIBPERF_API void perf_thread_map__put(struct perf_thread_map *map);
#endif /* __LIBPERF_THREADMAP_H */
perf_cpu_map__put;
perf_thread_map__new_dummy;
perf_thread_map__set_pid;
+ perf_thread_map__comm;
+ perf_thread_map__get;
+ perf_thread_map__put;
local:
*;
};
#include <linux/refcount.h>
#include <internal/threadmap.h>
#include <string.h>
+#include <asm/bug.h>
+#include <stdio.h>
static void perf_thread_map__reset(struct perf_thread_map *map, int start, int nr)
{
map->map[thread].pid = pid;
}
+char *perf_thread_map__comm(struct perf_thread_map *map, int thread)
+{
+ return map->map[thread].comm;
+}
+
struct perf_thread_map *perf_thread_map__new_dummy(void)
{
struct perf_thread_map *threads = thread_map__alloc(1);
}
return threads;
}
+
+static void perf_thread_map__delete(struct perf_thread_map *threads)
+{
+ if (threads) {
+ int i;
+
+ WARN_ONCE(refcount_read(&threads->refcnt) != 0,
+ "thread map refcnt unbalanced\n");
+ for (i = 0; i < threads->nr; i++)
+ free(perf_thread_map__comm(threads, i));
+ free(threads);
+ }
+}
+
+struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map)
+{
+ if (map)
+ refcount_inc(&map->refcnt);
+ return map;
+}
+
+void perf_thread_map__put(struct perf_thread_map *map)
+{
+ if (map && refcount_dec_and_test(&map->refcnt))
+ perf_thread_map__delete(map);
+}
* call. Getting refference to keep them alive.
*/
perf_cpu_map__get(cpus);
- thread_map__get(threads);
+ perf_thread_map__get(threads);
perf_evlist__set_maps(evlist, NULL, NULL);
evlist__delete(evlist);
evlist = NULL;
evlist__delete(evlist);
} else {
perf_cpu_map__put(cpus);
- thread_map__put(threads);
+ perf_thread_map__put(threads);
}
machine__delete_threads(machine);
machine__delete(machine);
return err;
}
- thread_map__put(threads);
+ perf_thread_map__put(threads);
return evsel__enable(evsel) == 0 ? TEST_OK : TEST_FAIL;
}
err = perf_evsel__open_per_thread(evsel, threads);
- thread_map__put(threads);
+ perf_thread_map__put(threads);
return err == 0 ? TEST_OK : TEST_FAIL;
}
evlist__delete(evlist);
} else {
perf_cpu_map__put(cpus);
- thread_map__put(threads);
+ perf_thread_map__put(threads);
}
return err;
out_free_cpus:
perf_cpu_map__put(cpus);
out_free_threads:
- thread_map__put(threads);
+ perf_thread_map__put(threads);
return err;
}
perf_event__process,
machine, 0);
- thread_map__put(map);
+ perf_thread_map__put(map);
return err;
}
out_cpu_map_delete:
perf_cpu_map__put(cpus);
out_thread_map_delete:
- thread_map__put(threads);
+ perf_thread_map__put(threads);
return err;
}
out_evsel_delete:
evsel__delete(evsel);
out_thread_map_delete:
- thread_map__put(threads);
+ perf_thread_map__put(threads);
return err;
}
out_free_maps:
perf_cpu_map__put(cpus);
- thread_map__put(threads);
+ perf_thread_map__put(threads);
out_delete_evlist:
evlist__delete(evlist);
return err;
evlist__delete(evlist);
} else {
perf_cpu_map__put(cpus);
- thread_map__put(threads);
+ perf_thread_map__put(threads);
}
return err;
out_free_maps:
perf_cpu_map__put(cpus);
- thread_map__put(threads);
+ perf_thread_map__put(threads);
out_delete_evlist:
evlist__delete(evlist);
return err;
TEST_ASSERT_VAL("wrong pid",
thread_map__pid(map, 0) == getpid());
TEST_ASSERT_VAL("wrong comm",
- thread_map__comm(map, 0) &&
- !strcmp(thread_map__comm(map, 0), NAME));
+ perf_thread_map__comm(map, 0) &&
+ !strcmp(perf_thread_map__comm(map, 0), NAME));
TEST_ASSERT_VAL("wrong refcnt",
refcount_read(&map->refcnt) == 1);
- thread_map__put(map);
+ perf_thread_map__put(map);
/* test dummy pid */
map = perf_thread_map__new_dummy();
TEST_ASSERT_VAL("wrong nr", map->nr == 1);
TEST_ASSERT_VAL("wrong pid", thread_map__pid(map, 0) == -1);
TEST_ASSERT_VAL("wrong comm",
- thread_map__comm(map, 0) &&
- !strcmp(thread_map__comm(map, 0), "dummy"));
+ perf_thread_map__comm(map, 0) &&
+ !strcmp(perf_thread_map__comm(map, 0), "dummy"));
TEST_ASSERT_VAL("wrong refcnt",
refcount_read(&map->refcnt) == 1);
- thread_map__put(map);
+ perf_thread_map__put(map);
return 0;
}
TEST_ASSERT_VAL("wrong pid",
thread_map__pid(threads, 0) == getpid());
TEST_ASSERT_VAL("wrong comm",
- thread_map__comm(threads, 0) &&
- !strcmp(thread_map__comm(threads, 0), NAME));
+ perf_thread_map__comm(threads, 0) &&
+ !strcmp(perf_thread_map__comm(threads, 0), NAME));
TEST_ASSERT_VAL("wrong refcnt",
refcount_read(&threads->refcnt) == 1);
- thread_map__put(threads);
+ perf_thread_map__put(threads);
return 0;
}
for (i = 0; i < threads->nr; i++) {
struct thread_map_event_entry *entry = &event->thread_map.entries[i];
- char *comm = thread_map__comm(threads, i);
+ char *comm = perf_thread_map__comm(threads, i);
if (!comm)
comm = (char *) "";
else
ret += fprintf(fp, "failed to get threads from event\n");
- thread_map__put(threads);
+ perf_thread_map__put(threads);
return ret;
}
perf_evlist__munmap(evlist);
evlist__close(evlist);
perf_cpu_map__put(evlist->cpus);
- thread_map__put(evlist->threads);
+ perf_thread_map__put(evlist->threads);
evlist->cpus = NULL;
evlist->threads = NULL;
perf_evlist__purge(evlist);
evsel->cpus = perf_cpu_map__get(evsel->own_cpus);
}
- thread_map__put(evsel->threads);
- evsel->threads = thread_map__get(evlist->threads);
+ perf_thread_map__put(evsel->threads);
+ evsel->threads = perf_thread_map__get(evlist->threads);
}
static void perf_evlist__propagate_maps(struct evlist *evlist)
return 0;
out_delete_threads:
- thread_map__put(threads);
+ perf_thread_map__put(threads);
return -1;
}
}
if (threads != evlist->threads) {
- thread_map__put(evlist->threads);
- evlist->threads = thread_map__get(threads);
+ perf_thread_map__put(evlist->threads);
+ evlist->threads = perf_thread_map__get(threads);
}
perf_evlist__propagate_maps(evlist);
cgroup__put(evsel->cgrp);
perf_cpu_map__put(evsel->cpus);
perf_cpu_map__put(evsel->own_cpus);
- thread_map__put(evsel->threads);
+ perf_thread_map__put(evsel->threads);
zfree(&evsel->group_name);
zfree(&evsel->name);
perf_evsel__object.fini(evsel);
evsel__delete(evsel);
}
- thread_map__put(tmap);
+ perf_thread_map__put(tmap);
return ret;
}
static void pyrf_thread_map__delete(struct pyrf_thread_map *pthreads)
{
- thread_map__put(pthreads->threads);
+ perf_thread_map__put(pthreads->threads);
Py_TYPE(pthreads)->tp_free((PyObject*)pthreads);
}
case AGGR_THREAD:
fprintf(config->output, "%*s-%*d%s",
config->csv_output ? 0 : 16,
- thread_map__comm(evsel->threads, id),
+ perf_thread_map__comm(evsel->threads, id),
config->csv_output ? 0 : -8,
thread_map__pid(evsel->threads, id),
config->csv_sep);
return thread_map__new_by_tid_str(tid);
}
-static void thread_map__delete(struct perf_thread_map *threads)
-{
- if (threads) {
- int i;
-
- WARN_ONCE(refcount_read(&threads->refcnt) != 0,
- "thread map refcnt unbalanced\n");
- for (i = 0; i < threads->nr; i++)
- free(thread_map__comm(threads, i));
- free(threads);
- }
-}
-
-struct perf_thread_map *thread_map__get(struct perf_thread_map *map)
-{
- if (map)
- refcount_inc(&map->refcnt);
- return map;
-}
-
-void thread_map__put(struct perf_thread_map *map)
-{
- if (map && refcount_dec_and_test(&map->refcnt))
- thread_map__delete(map);
-}
-
size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp)
{
int i;
struct perf_thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid);
struct perf_thread_map *thread_map__new_event(struct thread_map_event *event);
-struct perf_thread_map *thread_map__get(struct perf_thread_map *map);
-void thread_map__put(struct perf_thread_map *map);
-
struct perf_thread_map *thread_map__new_str(const char *pid,
const char *tid, uid_t uid, bool all_threads);
return map->map[thread].pid;
}
-static inline char *thread_map__comm(struct perf_thread_map *map, int thread)
-{
- return map->map[thread].comm;
-}
-
void thread_map__read_comms(struct perf_thread_map *threads);
bool thread_map__has(struct perf_thread_map *threads, pid_t pid);
int thread_map__remove(struct perf_thread_map *threads, int idx);