~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/openat-syscall-tp-fields.c

Version: ~ [ linux-5.9-rc6 ] ~ [ linux-5.8.10 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.66 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.146 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.198 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.236 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.236 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <linux/err.h>
  2 #include "perf.h"
  3 #include "evlist.h"
  4 #include "evsel.h"
  5 #include "thread_map.h"
  6 #include "tests.h"
  7 #include "debug.h"
  8 
  9 int test__syscall_openat_tp_fields(int subtest __maybe_unused)
 10 {
 11         struct record_opts opts = {
 12                 .target = {
 13                         .uid = UINT_MAX,
 14                         .uses_mmap = true,
 15                 },
 16                 .no_buffering = true,
 17                 .freq         = 1,
 18                 .mmap_pages   = 256,
 19                 .raw_samples  = true,
 20         };
 21         const char *filename = "/etc/passwd";
 22         int flags = O_RDONLY | O_DIRECTORY;
 23         struct perf_evlist *evlist = perf_evlist__new();
 24         struct perf_evsel *evsel;
 25         int err = -1, i, nr_events = 0, nr_polls = 0;
 26         char sbuf[STRERR_BUFSIZE];
 27 
 28         if (evlist == NULL) {
 29                 pr_debug("%s: perf_evlist__new\n", __func__);
 30                 goto out;
 31         }
 32 
 33         evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
 34         if (IS_ERR(evsel)) {
 35                 pr_debug("%s: perf_evsel__newtp\n", __func__);
 36                 goto out_delete_evlist;
 37         }
 38 
 39         perf_evlist__add(evlist, evsel);
 40 
 41         err = perf_evlist__create_maps(evlist, &opts.target);
 42         if (err < 0) {
 43                 pr_debug("%s: perf_evlist__create_maps\n", __func__);
 44                 goto out_delete_evlist;
 45         }
 46 
 47         perf_evsel__config(evsel, &opts, NULL);
 48 
 49         thread_map__set_pid(evlist->threads, 0, getpid());
 50 
 51         err = perf_evlist__open(evlist);
 52         if (err < 0) {
 53                 pr_debug("perf_evlist__open: %s\n",
 54                          strerror_r(errno, sbuf, sizeof(sbuf)));
 55                 goto out_delete_evlist;
 56         }
 57 
 58         err = perf_evlist__mmap(evlist, UINT_MAX, false);
 59         if (err < 0) {
 60                 pr_debug("perf_evlist__mmap: %s\n",
 61                          strerror_r(errno, sbuf, sizeof(sbuf)));
 62                 goto out_delete_evlist;
 63         }
 64 
 65         perf_evlist__enable(evlist);
 66 
 67         /*
 68          * Generate the event:
 69          */
 70         openat(AT_FDCWD, filename, flags);
 71 
 72         while (1) {
 73                 int before = nr_events;
 74 
 75                 for (i = 0; i < evlist->nr_mmaps; i++) {
 76                         union perf_event *event;
 77 
 78                         while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
 79                                 const u32 type = event->header.type;
 80                                 int tp_flags;
 81                                 struct perf_sample sample;
 82 
 83                                 ++nr_events;
 84 
 85                                 if (type != PERF_RECORD_SAMPLE) {
 86                                         perf_evlist__mmap_consume(evlist, i);
 87                                         continue;
 88                                 }
 89 
 90                                 err = perf_evsel__parse_sample(evsel, event, &sample);
 91                                 if (err) {
 92                                         pr_debug("Can't parse sample, err = %d\n", err);
 93                                         goto out_delete_evlist;
 94                                 }
 95 
 96                                 tp_flags = perf_evsel__intval(evsel, &sample, "flags");
 97 
 98                                 if (flags != tp_flags) {
 99                                         pr_debug("%s: Expected flags=%#x, got %#x\n",
100                                                  __func__, flags, tp_flags);
101                                         goto out_delete_evlist;
102                                 }
103 
104                                 goto out_ok;
105                         }
106                 }
107 
108                 if (nr_events == before)
109                         perf_evlist__poll(evlist, 10);
110 
111                 if (++nr_polls > 5) {
112                         pr_debug("%s: no events!\n", __func__);
113                         goto out_delete_evlist;
114                 }
115         }
116 out_ok:
117         err = 0;
118 out_delete_evlist:
119         perf_evlist__delete(evlist);
120 out:
121         return err;
122 }
123 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp