hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/tools/perf/util/namespaces.c
....@@ -1,14 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
2
- * This program is free software; you can redistribute it and/or modify
3
- * it under the terms of the GNU General Public License, version 2, as
4
- * published by the Free Software Foundation.
53 *
64 * Copyright (C) 2017 Hari Bathini, IBM Corporation
75 */
86
97 #include "namespaces.h"
10
-#include "util.h"
118 #include "event.h"
9
+#include "get_current_dir_name.h"
1210 #include <sys/types.h>
1311 #include <sys/stat.h>
1412 #include <fcntl.h>
....@@ -19,8 +17,27 @@
1917 #include <string.h>
2018 #include <unistd.h>
2119 #include <asm/bug.h>
20
+#include <linux/kernel.h>
21
+#include <linux/zalloc.h>
2222
23
-struct namespaces *namespaces__new(struct namespaces_event *event)
23
+static const char *perf_ns__names[] = {
24
+ [NET_NS_INDEX] = "net",
25
+ [UTS_NS_INDEX] = "uts",
26
+ [IPC_NS_INDEX] = "ipc",
27
+ [PID_NS_INDEX] = "pid",
28
+ [USER_NS_INDEX] = "user",
29
+ [MNT_NS_INDEX] = "mnt",
30
+ [CGROUP_NS_INDEX] = "cgroup",
31
+};
32
+
33
+const char *perf_ns__name(unsigned int id)
34
+{
35
+ if (id >= ARRAY_SIZE(perf_ns__names))
36
+ return "UNKNOWN";
37
+ return perf_ns__names[id];
38
+}
39
+
40
+struct namespaces *namespaces__new(struct perf_record_namespaces *event)
2441 {
2542 struct namespaces *namespaces;
2643 u64 link_info_size = ((event ? event->nr_namespaces : NR_NAMESPACES) *