]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blobdiff - tools/perf/builtin-script.c
perf script: Add scripting operation process_switch()
[mirror_ubuntu-eoan-kernel.git] / tools / perf / builtin-script.c
index 61f00055476a12765f2460ab8a721e5ab94914bd..8f24865596af2fd5a6334f9c5fa10b726bc22956 100644 (file)
@@ -14,7 +14,6 @@
 #include "util/symbol.h"
 #include "util/thread.h"
 #include "util/trace-event.h"
-#include "util/util.h"
 #include "util/evlist.h"
 #include "util/evsel.h"
 #include "util/sort.h"
@@ -34,6 +33,7 @@
 #include <linux/kernel.h>
 #include <linux/stringify.h>
 #include <linux/time64.h>
+#include <linux/zalloc.h>
 #include <sys/utsname.h>
 #include "asm/bug.h"
 #include "util/mem-events.h"
@@ -49,7 +49,7 @@
 #include <unistd.h>
 #include <subcmd/pager.h>
 
-#include "sane_ctype.h"
+#include <linux/ctype.h>
 
 static char const              *script_name;
 static char const              *generate_script_lang;
@@ -2289,6 +2289,12 @@ static int process_switch_event(struct perf_tool *tool,
        if (perf_event__process_switch(tool, event, sample, machine) < 0)
                return -1;
 
+       if (scripting_ops && scripting_ops->process_switch)
+               scripting_ops->process_switch(event, sample, machine);
+
+       if (!script->show_switch_events)
+               return 0;
+
        thread = machine__findnew_thread(machine, sample->pid,
                                         sample->tid);
        if (thread == NULL) {
@@ -2467,7 +2473,7 @@ static int __cmd_script(struct perf_script *script)
                script->tool.mmap = process_mmap_event;
                script->tool.mmap2 = process_mmap2_event;
        }
-       if (script->show_switch_events)
+       if (script->show_switch_events || (scripting_ops && scripting_ops->process_switch))
                script->tool.context_switch = process_switch_event;
        if (script->show_namespace_events)
                script->tool.namespaces = process_namespaces_event;
@@ -2880,7 +2886,7 @@ static int read_script_info(struct script_desc *desc, const char *filename)
                return -1;
 
        while (fgets(line, sizeof(line), fp)) {
-               p = ltrim(line);
+               p = skip_spaces(line);
                if (strlen(p) == 0)
                        continue;
                if (*p != '#')
@@ -2889,19 +2895,19 @@ static int read_script_info(struct script_desc *desc, const char *filename)
                if (strlen(p) && *p == '!')
                        continue;
 
-               p = ltrim(p);
+               p = skip_spaces(p);
                if (strlen(p) && p[strlen(p) - 1] == '\n')
                        p[strlen(p) - 1] = '\0';
 
                if (!strncmp(p, "description:", strlen("description:"))) {
                        p += strlen("description:");
-                       desc->half_liner = strdup(ltrim(p));
+                       desc->half_liner = strdup(skip_spaces(p));
                        continue;
                }
 
                if (!strncmp(p, "args:", strlen("args:"))) {
                        p += strlen("args:");
-                       desc->args = strdup(ltrim(p));
+                       desc->args = strdup(skip_spaces(p));
                        continue;
                }
        }
@@ -3008,7 +3014,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
                return -1;
 
        while (fgets(line, sizeof(line), fp)) {
-               p = ltrim(line);
+               p = skip_spaces(line);
                if (*p == '#')
                        continue;
 
@@ -3018,7 +3024,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
                                break;
 
                        p += 2;
-                       p = ltrim(p);
+                       p = skip_spaces(p);
                        len = strcspn(p, " \t");
                        if (!len)
                                break;
@@ -3522,6 +3528,15 @@ int cmd_script(int argc, const char **argv)
                   "Time span of interest (start,stop)"),
        OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
                    "Show inline function"),
+       OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory",
+                  "guest mount directory under which every guest os"
+                  " instance has a subdir"),
+       OPT_STRING(0, "guestvmlinux", &symbol_conf.default_guest_vmlinux_name,
+                  "file", "file saving guest os vmlinux"),
+       OPT_STRING(0, "guestkallsyms", &symbol_conf.default_guest_kallsyms,
+                  "file", "file saving guest os /proc/kallsyms"),
+       OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules,
+                  "file", "file saving guest os /proc/modules"),
        OPT_END()
        };
        const char * const script_subcommands[] = { "record", "report", NULL };
@@ -3541,6 +3556,16 @@ int cmd_script(int argc, const char **argv)
        argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
                             PARSE_OPT_STOP_AT_NON_OPTION);
 
+       if (symbol_conf.guestmount ||
+           symbol_conf.default_guest_vmlinux_name ||
+           symbol_conf.default_guest_kallsyms ||
+           symbol_conf.default_guest_modules) {
+               /*
+                * Enable guest sample processing.
+                */
+               perf_guest = true;
+       }
+
        data.path  = input_name;
        data.force = symbol_conf.force;
 
@@ -3733,7 +3758,8 @@ int cmd_script(int argc, const char **argv)
                goto out_delete;
 
        uname(&uts);
-       if (!strcmp(uts.machine, session->header.env.arch) ||
+       if (data.is_pipe ||  /* assume pipe_mode indicates native_arch */
+           !strcmp(uts.machine, session->header.env.arch) ||
            (!strcmp(uts.machine, "x86_64") &&
             !strcmp(session->header.env.arch, "i386")))
                native_arch = true;