aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Makefile.config5
-rw-r--r--tools/perf/tests/attr/base-record2
-rw-r--r--tools/perf/trace/beauty/ioctl.c1
-rw-r--r--tools/perf/util/Build1
-rw-r--r--tools/perf/util/evsel.c2
-rw-r--r--tools/perf/util/get_current_dir_name.c18
-rw-r--r--tools/perf/util/namespaces.c17
-rw-r--r--tools/perf/util/namespaces.h1
-rw-r--r--tools/perf/util/util.h4
9 files changed, 47 insertions, 4 deletions
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index e30d20fb482d..a0e8c23f9125 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -299,6 +299,11 @@ ifndef NO_BIONIC
299 endif 299 endif
300endif 300endif
301 301
302ifeq ($(feature-get_current_dir_name), 1)
303 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
304endif
305
306
302ifdef NO_LIBELF 307ifdef NO_LIBELF
303 NO_DWARF := 1 308 NO_DWARF := 1
304 NO_DEMANGLE := 1 309 NO_DEMANGLE := 1
diff --git a/tools/perf/tests/attr/base-record b/tools/perf/tests/attr/base-record
index 37940665f736..efd0157b9d22 100644
--- a/tools/perf/tests/attr/base-record
+++ b/tools/perf/tests/attr/base-record
@@ -9,7 +9,7 @@ size=112
9config=0 9config=0
10sample_period=* 10sample_period=*
11sample_type=263 11sample_type=263
12read_format=0 12read_format=0|4
13disabled=1 13disabled=1
14inherit=1 14inherit=1
15pinned=0 15pinned=0
diff --git a/tools/perf/trace/beauty/ioctl.c b/tools/perf/trace/beauty/ioctl.c
index 5d2a7fd8d407..eae59ad15ce3 100644
--- a/tools/perf/trace/beauty/ioctl.c
+++ b/tools/perf/trace/beauty/ioctl.c
@@ -31,6 +31,7 @@ static size_t ioctl__scnprintf_tty_cmd(int nr, int dir, char *bf, size_t size)
31 "TCSETSW2", "TCSETSF2", "TIOCGRS48", "TIOCSRS485", "TIOCGPTN", "TIOCSPTLCK", 31 "TCSETSW2", "TCSETSF2", "TIOCGRS48", "TIOCSRS485", "TIOCGPTN", "TIOCSPTLCK",
32 "TIOCGDEV", "TCSETX", "TCSETXF", "TCSETXW", "TIOCSIG", "TIOCVHANGUP", "TIOCGPKT", 32 "TIOCGDEV", "TCSETX", "TCSETXF", "TCSETXW", "TIOCSIG", "TIOCVHANGUP", "TIOCGPKT",
33 "TIOCGPTLCK", [_IOC_NR(TIOCGEXCL)] = "TIOCGEXCL", "TIOCGPTPEER", 33 "TIOCGPTLCK", [_IOC_NR(TIOCGEXCL)] = "TIOCGEXCL", "TIOCGPTPEER",
34 "TIOCGISO7816", "TIOCSISO7816",
34 [_IOC_NR(FIONCLEX)] = "FIONCLEX", "FIOCLEX", "FIOASYNC", "TIOCSERCONFIG", 35 [_IOC_NR(FIONCLEX)] = "FIONCLEX", "FIOCLEX", "FIOASYNC", "TIOCSERCONFIG",
35 "TIOCSERGWILD", "TIOCSERSWILD", "TIOCGLCKTRMIOS", "TIOCSLCKTRMIOS", 36 "TIOCSERGWILD", "TIOCSERSWILD", "TIOCGLCKTRMIOS", "TIOCSLCKTRMIOS",
36 "TIOCSERGSTRUCT", "TIOCSERGETLSR", "TIOCSERGETMULTI", "TIOCSERSETMULTI", 37 "TIOCSERGSTRUCT", "TIOCSERGETLSR", "TIOCSERGETMULTI", "TIOCSERSETMULTI",
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index ecd9f9ceda77..b7bf201fe8a8 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -10,6 +10,7 @@ libperf-y += evlist.o
10libperf-y += evsel.o 10libperf-y += evsel.o
11libperf-y += evsel_fprintf.o 11libperf-y += evsel_fprintf.o
12libperf-y += find_bit.o 12libperf-y += find_bit.o
13libperf-y += get_current_dir_name.o
13libperf-y += kallsyms.o 14libperf-y += kallsyms.o
14libperf-y += levenshtein.o 15libperf-y += levenshtein.o
15libperf-y += llvm-utils.o 16libperf-y += llvm-utils.o
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index d37bb1566cd9..dbc0466db368 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1092,7 +1092,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
1092 attr->exclude_user = 1; 1092 attr->exclude_user = 1;
1093 } 1093 }
1094 1094
1095 if (evsel->own_cpus) 1095 if (evsel->own_cpus || evsel->unit)
1096 evsel->attr.read_format |= PERF_FORMAT_ID; 1096 evsel->attr.read_format |= PERF_FORMAT_ID;
1097 1097
1098 /* 1098 /*
diff --git a/tools/perf/util/get_current_dir_name.c b/tools/perf/util/get_current_dir_name.c
new file mode 100644
index 000000000000..267aa609a582
--- /dev/null
+++ b/tools/perf/util/get_current_dir_name.c
@@ -0,0 +1,18 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3//
4#ifndef HAVE_GET_CURRENT_DIR_NAME
5#include "util.h"
6#include <unistd.h>
7#include <stdlib.h>
8#include <stdlib.h>
9
10/* Android's 'bionic' library, for one, doesn't have this */
11
12char *get_current_dir_name(void)
13{
14 char pwd[PATH_MAX];
15
16 return getcwd(pwd, sizeof(pwd)) == NULL ? NULL : strdup(pwd);
17}
18#endif // HAVE_GET_CURRENT_DIR_NAME
diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c
index cf8bd123cf73..aed170bd4384 100644
--- a/tools/perf/util/namespaces.c
+++ b/tools/perf/util/namespaces.c
@@ -18,6 +18,7 @@
18#include <stdio.h> 18#include <stdio.h>
19#include <string.h> 19#include <string.h>
20#include <unistd.h> 20#include <unistd.h>
21#include <asm/bug.h>
21 22
22struct namespaces *namespaces__new(struct namespaces_event *event) 23struct namespaces *namespaces__new(struct namespaces_event *event)
23{ 24{
@@ -186,6 +187,7 @@ void nsinfo__mountns_enter(struct nsinfo *nsi,
186 char curpath[PATH_MAX]; 187 char curpath[PATH_MAX];
187 int oldns = -1; 188 int oldns = -1;
188 int newns = -1; 189 int newns = -1;
190 char *oldcwd = NULL;
189 191
190 if (nc == NULL) 192 if (nc == NULL)
191 return; 193 return;
@@ -199,9 +201,13 @@ void nsinfo__mountns_enter(struct nsinfo *nsi,
199 if (snprintf(curpath, PATH_MAX, "/proc/self/ns/mnt") >= PATH_MAX) 201 if (snprintf(curpath, PATH_MAX, "/proc/self/ns/mnt") >= PATH_MAX)
200 return; 202 return;
201 203
204 oldcwd = get_current_dir_name();
205 if (!oldcwd)
206 return;
207
202 oldns = open(curpath, O_RDONLY); 208 oldns = open(curpath, O_RDONLY);
203 if (oldns < 0) 209 if (oldns < 0)
204 return; 210 goto errout;
205 211
206 newns = open(nsi->mntns_path, O_RDONLY); 212 newns = open(nsi->mntns_path, O_RDONLY);
207 if (newns < 0) 213 if (newns < 0)
@@ -210,11 +216,13 @@ void nsinfo__mountns_enter(struct nsinfo *nsi,
210 if (setns(newns, CLONE_NEWNS) < 0) 216 if (setns(newns, CLONE_NEWNS) < 0)
211 goto errout; 217 goto errout;
212 218
219 nc->oldcwd = oldcwd;
213 nc->oldns = oldns; 220 nc->oldns = oldns;
214 nc->newns = newns; 221 nc->newns = newns;
215 return; 222 return;
216 223
217errout: 224errout:
225 free(oldcwd);
218 if (oldns > -1) 226 if (oldns > -1)
219 close(oldns); 227 close(oldns);
220 if (newns > -1) 228 if (newns > -1)
@@ -223,11 +231,16 @@ errout:
223 231
224void nsinfo__mountns_exit(struct nscookie *nc) 232void nsinfo__mountns_exit(struct nscookie *nc)
225{ 233{
226 if (nc == NULL || nc->oldns == -1 || nc->newns == -1) 234 if (nc == NULL || nc->oldns == -1 || nc->newns == -1 || !nc->oldcwd)
227 return; 235 return;
228 236
229 setns(nc->oldns, CLONE_NEWNS); 237 setns(nc->oldns, CLONE_NEWNS);
230 238
239 if (nc->oldcwd) {
240 WARN_ON_ONCE(chdir(nc->oldcwd));
241 zfree(&nc->oldcwd);
242 }
243
231 if (nc->oldns > -1) { 244 if (nc->oldns > -1) {
232 close(nc->oldns); 245 close(nc->oldns);
233 nc->oldns = -1; 246 nc->oldns = -1;
diff --git a/tools/perf/util/namespaces.h b/tools/perf/util/namespaces.h
index cae1a9a39722..d5f46c09ea31 100644
--- a/tools/perf/util/namespaces.h
+++ b/tools/perf/util/namespaces.h
@@ -38,6 +38,7 @@ struct nsinfo {
38struct nscookie { 38struct nscookie {
39 int oldns; 39 int oldns;
40 int newns; 40 int newns;
41 char *oldcwd;
41}; 42};
42 43
43int nsinfo__init(struct nsinfo *nsi); 44int nsinfo__init(struct nsinfo *nsi);
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 14508ee7707a..ece040b799f6 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -59,6 +59,10 @@ int fetch_kernel_version(unsigned int *puint,
59 59
60const char *perf_tip(const char *dirpath); 60const char *perf_tip(const char *dirpath);
61 61
62#ifndef HAVE_GET_CURRENT_DIR_NAME
63char *get_current_dir_name(void);
64#endif
65
62#ifndef HAVE_SCHED_GETCPU_SUPPORT 66#ifndef HAVE_SCHED_GETCPU_SUPPORT
63int sched_getcpu(void); 67int sched_getcpu(void);
64#endif 68#endif