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

TOMOYO Linux Cross Reference
Linux/tools/perf/ui/browsers/res_sample.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Display a menu with individual samples to browse with perf script */
  3 #include "hist.h"
  4 #include "evsel.h"
  5 #include "hists.h"
  6 #include "sort.h"
  7 #include "config.h"
  8 #include "time-utils.h"
  9 #include "../util.h"
 10 #include "../../util/util.h" // perf_exe()
 11 #include "../../perf.h"
 12 #include <stdlib.h>
 13 #include <string.h>
 14 #include <linux/time64.h>
 15 #include <linux/zalloc.h>
 16 
 17 static u64 context_len = 10 * NSEC_PER_MSEC;
 18 
 19 static int res_sample_config(const char *var, const char *value, void *data __maybe_unused)
 20 {
 21         if (!strcmp(var, "samples.context"))
 22                 return perf_config_u64(&context_len, var, value);
 23         return 0;
 24 }
 25 
 26 void res_sample_init(void)
 27 {
 28         perf_config(res_sample_config, NULL);
 29 }
 30 
 31 int res_sample_browse(struct res_sample *res_samples, int num_res,
 32                       struct evsel *evsel, enum rstype rstype)
 33 {
 34         char **names;
 35         int i, n;
 36         int choice;
 37         char *cmd;
 38         char pbuf[256], tidbuf[32], cpubuf[32];
 39         const char *perf = perf_exe(pbuf, sizeof pbuf);
 40         char trange[128], tsample[64];
 41         struct res_sample *r;
 42         char extra_format[256];
 43 
 44         names = calloc(num_res, sizeof(char *));
 45         if (!names)
 46                 return -1;
 47         for (i = 0; i < num_res; i++) {
 48                 char tbuf[64];
 49 
 50                 timestamp__scnprintf_nsec(res_samples[i].time, tbuf, sizeof tbuf);
 51                 if (asprintf(&names[i], "%s: CPU %d tid %d", tbuf,
 52                              res_samples[i].cpu, res_samples[i].tid) < 0) {
 53                         while (--i >= 0)
 54                                 zfree(&names[i]);
 55                         free(names);
 56                         return -1;
 57                 }
 58         }
 59         choice = ui__popup_menu(num_res, names, NULL);
 60         for (i = 0; i < num_res; i++)
 61                 zfree(&names[i]);
 62         free(names);
 63 
 64         if (choice < 0 || choice >= num_res)
 65                 return -1;
 66         r = &res_samples[choice];
 67 
 68         n = timestamp__scnprintf_nsec(r->time - context_len, trange, sizeof trange);
 69         trange[n++] = ',';
 70         timestamp__scnprintf_nsec(r->time + context_len, trange + n, sizeof trange - n);
 71 
 72         timestamp__scnprintf_nsec(r->time, tsample, sizeof tsample);
 73 
 74         attr_to_script(extra_format, &evsel->core.attr);
 75 
 76         if (asprintf(&cmd, "%s script %s%s --time %s %s%s %s%s --ns %s %s %s %s %s | less +/%s",
 77                      perf,
 78                      input_name ? "-i " : "",
 79                      input_name ? input_name : "",
 80                      trange,
 81                      r->cpu >= 0 ? "--cpu " : "",
 82                      r->cpu >= 0 ? (sprintf(cpubuf, "%d", r->cpu), cpubuf) : "",
 83                      r->tid ? "--tid " : "",
 84                      r->tid ? (sprintf(tidbuf, "%d", r->tid), tidbuf) : "",
 85                      extra_format,
 86                      rstype == A_ASM ? "-F +disasm" :
 87                      rstype == A_SOURCE ? "-F +srcline,+srccode" : "",
 88                      symbol_conf.inline_name ? "--inline" : "",
 89                      "--show-lost-events ",
 90                      r->tid ? "--show-switch-events --show-task-events " : "",
 91                      tsample) < 0)
 92                 return -1;
 93         run_script(cmd);
 94         free(cmd);
 95         return 0;
 96 }
 97 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php