[PATCH] perf-script : improves option passing mechansim

2014-03-18 Thread Adrien BAK

This pull request fixes the following issues :
* when passing custom arguments to a script, if those arguments are
 not declared within perf, they prevent the execution of perf.
e.g.

perf script -i path/to/perf.data -s my_script -arg1 arg_value

perf will issue an error message and no processing will occur


* when passing custom arguments to a script, if those arguments are
 declared by perf, they are consumed and not passed to the script.
e.g.
perf script -i path/to/perf.data -s my_script -h

perf will display its own help message, instead of the expected help
message from my_script.

These issues are addressed as follows :
* The parse option flag is changed from PARSE_OPT_STOP_AT_NON_OPTION to
PARSE_OPT_KEEP_UNKNOWN
* A new option type is introduce OPT_CALLBACK_FINAL_OPTION, which 
effectively

 prevents the parsing of all options located after the script.

Signed-off-by: Adrien Bak 

---

 tools/perf/builtin-script.c | 8 
 tools/perf/util/parse-options.c | 4 
 tools/perf/util/parse-options.h | 5 +
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 9e9c91f..3cd6a46 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1523,9 +1523,9 @@ int cmd_script(int argc, const char **argv, const 
char *prefix __maybe_unused)

 "show latency attributes (irqs/preemption disabled, etc)"),
 OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
list_available_scripts),
-OPT_CALLBACK('s', "script", NULL, "name",
- "script file name (lang:script name, script name, or *)",
- parse_scriptname),
+OPT_CALLBACK_FINAL_OPTION('s', "script", NULL, "name",
+  "script file name (lang:script name, script name, or *)",
+  parse_scriptname),
 OPT_STRING('g', "gen-script", &generate_script_lang, "lang",
"generate perf-script.xx script in specified language"),
 OPT_STRING('i', "input", &input_name, "file", "input file name"),
@@ -1578,7 +1578,7 @@ int cmd_script(int argc, const char **argv, const 
char *prefix __maybe_unused)

 setup_scripting();

 argc = parse_options(argc, argv, options, script_usage,
- PARSE_OPT_STOP_AT_NON_OPTION);
+ PARSE_OPT_KEEP_UNKNOWN);

 file.path = input_name;

diff --git a/tools/perf/util/parse-options.c 
b/tools/perf/util/parse-options.c

index d22e3f8..77f566d 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -112,6 +112,8 @@ static int get_value(struct parse_opt_ctx_t *p,
 return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
 if (get_arg(p, opt, flags, &arg))
 return -1;
+if (opt->flags & PARSE_OPT_FINAL_OPTION)
+return (*opt->callback)(opt, arg, 0)?(-1) : (-3);
 return (*opt->callback)(opt, arg, 0) ? (-1) : 0;

 case OPTION_INTEGER:
@@ -366,6 +368,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 return parse_options_usage(usagestr, options, arg + 1, 1);
 case -2:
 goto unknown;
+case -3:
+return PARSE_OPT_DONE;
 default:
 break;
 }
diff --git a/tools/perf/util/parse-options.h 
b/tools/perf/util/parse-options.h

index cbf0149..b1fa6b6 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -38,6 +38,7 @@ enum parse_opt_option_flags {
 PARSE_OPT_NONEG   = 4,
 PARSE_OPT_HIDDEN  = 8,
 PARSE_OPT_LASTARG_DEFAULT = 16,
+PARSE_OPT_FINAL_OPTION = 32,
 };

 struct option;
@@ -123,6 +124,10 @@ struct option {
 { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), 
.value = (v), .argh = "time", .help = (h), .callback = 
parse_opt_approxidate_cb }

 #define OPT_CALLBACK(s, l, v, a, h, f) \
 { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), 
.value = (v), (a), .help = (h), .callback = (f) }

+#define OPT_CALLBACK_FINAL_OPTION(s, l, v, a, h, f) \
+{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l),\
+.value = (v), (a), .help = (h), .callback = (f),\
+.flags = PARSE_OPT_FINAL_OPTION}
 #define OPT_CALLBACK_NOOPT(s, l, v, a, h, f) \
 { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), 
.value = (v), (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG }

 #define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] perf-script : improves option passing mechansim

2014-03-20 Thread Adrien BAK
Indeed. I wasn't aware of the '--' behaviour and the documentation 
doesn't seem to mention it. My patch essentially implements the same 
behaviour, except that the script name itself is used to separate the 
options. I guess there is not much need the proposed patch then.


Sorry for the wasted time.
Adrien

On 03/18/2014 07:15 PM, Arnaldo Carvalho de Melo wrote:

Em Tue, Mar 18, 2014 at 05:09:33PM +0100, Adrien BAK escreveu:

This pull request fixes the following issues :
* when passing custom arguments to a script, if those arguments are
  not declared within perf, they prevent the execution of perf.
e.g.

perf script -i path/to/perf.data -s my_script -arg1 arg_value

perf will issue an error message and no processing will occur

I haven't tested this, but what comes to mind is the use of -- to
separate what options should be processed by perf and which ones should
be left to the script, is that what you're fixing?

- Arnaldo
  

* when passing custom arguments to a script, if those arguments are
  declared by perf, they are consumed and not passed to the script.
e.g.
perf script -i path/to/perf.data -s my_script -h

perf will display its own help message, instead of the expected help
message from my_script.

These issues are addressed as follows :
* The parse option flag is changed from PARSE_OPT_STOP_AT_NON_OPTION to
PARSE_OPT_KEEP_UNKNOWN
* A new option type is introduce OPT_CALLBACK_FINAL_OPTION, which
effectively
  prevents the parsing of all options located after the script.

Signed-off-by: Adrien Bak 

---

  tools/perf/builtin-script.c | 8 
  tools/perf/util/parse-options.c | 4 
  tools/perf/util/parse-options.h | 5 +
  3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 9e9c91f..3cd6a46 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1523,9 +1523,9 @@ int cmd_script(int argc, const char **argv,
const char *prefix __maybe_unused)
  "show latency attributes (irqs/preemption disabled, etc)"),
  OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
 list_available_scripts),
-OPT_CALLBACK('s', "script", NULL, "name",
- "script file name (lang:script name, script name, or *)",
- parse_scriptname),
+OPT_CALLBACK_FINAL_OPTION('s', "script", NULL, "name",
+  "script file name (lang:script name, script name, or *)",
+  parse_scriptname),
  OPT_STRING('g', "gen-script", &generate_script_lang, "lang",
 "generate perf-script.xx script in specified language"),
  OPT_STRING('i', "input", &input_name, "file", "input file name"),
@@ -1578,7 +1578,7 @@ int cmd_script(int argc, const char **argv,
const char *prefix __maybe_unused)
  setup_scripting();

  argc = parse_options(argc, argv, options, script_usage,
- PARSE_OPT_STOP_AT_NON_OPTION);
+ PARSE_OPT_KEEP_UNKNOWN);

  file.path = input_name;

diff --git a/tools/perf/util/parse-options.c
b/tools/perf/util/parse-options.c
index d22e3f8..77f566d 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -112,6 +112,8 @@ static int get_value(struct parse_opt_ctx_t *p,
  return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
  if (get_arg(p, opt, flags, &arg))
  return -1;
+if (opt->flags & PARSE_OPT_FINAL_OPTION)
+return (*opt->callback)(opt, arg, 0)?(-1) : (-3);
  return (*opt->callback)(opt, arg, 0) ? (-1) : 0;

  case OPTION_INTEGER:
@@ -366,6 +368,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
  return parse_options_usage(usagestr, options, arg + 1, 1);
  case -2:
  goto unknown;
+case -3:
+return PARSE_OPT_DONE;
  default:
  break;
  }
diff --git a/tools/perf/util/parse-options.h
b/tools/perf/util/parse-options.h
index cbf0149..b1fa6b6 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -38,6 +38,7 @@ enum parse_opt_option_flags {
  PARSE_OPT_NONEG   = 4,
  PARSE_OPT_HIDDEN  = 8,
  PARSE_OPT_LASTARG_DEFAULT = 16,
+PARSE_OPT_FINAL_OPTION = 32,
  };

  struct option;
@@ -123,6 +124,10 @@ struct option {
  { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l),
.value = (v), .argh = "time", .help = (h), .callback =
parse_opt_approxidate_cb }
  #define OPT_CALLBACK(s, l, v, a, h, f) \
  { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l),
.value = (v), (a), .help = (h), .callback = (f) }
+#define OPT_CALLBACK_FINAL_OP

[PATCH] extends perf-script to native scripts

2014-04-07 Thread Adrien BAK


As it is perf-script allows one to use perl or python scripts to parse 
perf events.

The following proposal aimed to introduce support of .so files as scripts.
This support allows for better performance when parsing perf's data 
files and

a complete access to the raw data.

This support is implemented analogously to the one in place for 
perl/python script.
More precisely, when passing a .so file as a script argument, the 
following symbols

are loaded :
- start_script
- stop_script
- process_event
These symbols will be called instead of the corresponding :
- default_start_script
- default_stop_script
- process_event

There currently is a limitation regarding the generate_script function 
which cannot
be generalized to native scripts. Is it better to leave things as they 
are (die gracefully
when the user asks for native_generate_script) or to do one of the 
following :
- print a usage message specifying the symbols a .so script should 
expose

- create a .c file complying with said interface

Regarding style compliance, the following issues remains :
- 3 'fprintf' lines slightly over 80 chars in trace-event-native.
 Is it better to introduce a line break than to have a 83-chars 
long line?
- in trace-event-scripting.c a struct is declared as extern. Here, 
I followed

what was already done for perl/python scripting.

Thank you for your time and valued input.

Signed-off-by: Adrien BAK 
---



diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 50d875d..1eeb29b 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -543,6 +543,10 @@ ifndef NO_LIBPYTHON
   LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
 endif

+ifndef NO_NATIVE_SCRIPTING
+  LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-native.o
+endif
+
 ifeq ($(NO_PERF_REGS),0)
   ifeq ($(ARCH),x86)
 LIB_H += arch/x86/include/perf_regs.h
@@ -715,6 +719,9 @@ 
$(OUTPUT)util/scripting-engines/trace-event-python.o: 
util/scripting-engines/tra
 $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: 
scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PYTHON_EMBED_CCOPTS) 
-Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter 
-Wno-nested-externs $<


+$(OUTPUT)util/scripting-engines/trace-event-native.o: 
util/scripting-engines/trace-event-native.c $(OUTPUT)PERF-CFLAGS
+$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-redundant-decls 
-Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<

+
 $(OUTPUT)perf-%: %.o $(PERFLIBS)
 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 9e9c91f..7241e30 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -522,6 +522,7 @@ static void setup_scripting(void)
 {
 setup_perl_scripting();
 setup_python_scripting();
+setup_native_scripting();

 scripting_ops = &default_scripting_ops;
 }
diff --git a/tools/perf/util/scripting-engines/trace-event-native.c 
b/tools/perf/util/scripting-engines/trace-event-native.c

new file mode 100644
index 000..54ea57a
--- /dev/null
+++ b/tools/perf/util/scripting-engines/trace-event-native.c
@@ -0,0 +1,125 @@
+#include 
+#include 
+
+#include "../../perf.h"
+#include "../evsel.h"
+#include "../util.h"
+#include "../event.h"
+#include "../thread.h"
+#include "../trace-event.h"
+
+static void *handle;
+
+enum syms {
+START_SCRIPT = 0,
+STOP_SCRIPT,
+PROCESS_EVENT,
+GENERATE_SCRIPT,
+};
+
+const char *sym_names[4] = {"start_script",
+"stop_script",
+"process_event",
+"generate_script"};
+
+int  (*so_start_script)(const char*, int, const char**);
+int  (*so_stop_script)(void);
+void (*so_process_event)(union perf_event *, struct perf_sample *,
+ struct perf_evsel *, struct thread *,
+ struct addr_location *);
+
+static void native_process_event(union perf_event *event __maybe_unused,
+ struct perf_sample *sample,
+ struct perf_evsel *evsel,
+ struct thread *thread,
+ struct addr_location *al)
+{
+(so_process_event)(event, sample, evsel, thread, al);
+}
+
+static int native_start_script(const char *script, int argc, const char 
**argv)

+{
+int err = 0;
+
+char *error;
+
+handle = dlopen(script, RTLD_NOW);
+
+if (!handle) {
+fprintf(stderr, "an error occurred while loading the .so file\n");
+fprintf(stderr, "%s\n", dlerror());
+return -1;
+}
+
+*(void **)(&so_start_script) = dlsym(handle, sym_names[START_SCRIPT]);
+
+error = dlerror();
+if (error) {
+fprintf(stderr, "an error occured while loading start_script

[PATCH] extends perf-script to native scripts (updated)

2014-04-15 Thread Adrien BAK
As it is perf-script allows one to use perl or python scripts to parse 
perf events.

The following proposal aimed to introduce support of .so files as scripts.
This support allows for better performance when parsing perf's data 
files and

a complete access to the raw data.

This support is implemented analogously to the one in place for 
perl/python script.
More precisely, when passing a .so file as a script argument, the 
following symbols

are loaded :
- start_script
- stop_script
- process_event
These symbols will be called instead of the corresponding :
- default_start_script
- default_stop_script
- process_event

There currently is a limitation regarding the generate_script function 
which cannot
be generalized to native scripts. Is it better to leave things as they 
are (die gracefully
when the user asks for native_generate_script) or to do one of the 
following :
- print a usage message specifying the symbols a .so script should 
expose

- create a .c file complying with said interface

Regarding style compliance, the following issues remains :
- 3 'fprintf' lines slightly over 80 chars in trace-event-native.
 Is it better to introduce a line break than to have a 83-chars 
long line?
- in trace-event-scripting.c a struct is declared as extern. Here, 
I followed

what was already done for perl/python scripting.

Since the first time this was submitted, the following change was added:
- a local variable (error) in trace-event-native.c could shadow a 
goto label.
A compilation error could then occur with gcc 4.7. The variable has 
been renamed

to avoid that.

Thank you for your time and valued input.

Signed-off-by: Adrien BAK 
---


diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 50d875d..1eeb29b 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -543,6 +543,10 @@ ifndef NO_LIBPYTHON
   LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
 endif

+ifndef NO_NATIVE_SCRIPTING
+  LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-native.o
+endif
+
 ifeq ($(NO_PERF_REGS),0)
   ifeq ($(ARCH),x86)
 LIB_H += arch/x86/include/perf_regs.h
@@ -715,6 +719,9 @@ 
$(OUTPUT)util/scripting-engines/trace-event-python.o: 
util/scripting-engines/tra
 $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: 
scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PYTHON_EMBED_CCOPTS) 
-Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter 
-Wno-nested-externs $<


+$(OUTPUT)util/scripting-engines/trace-event-native.o: 
util/scripting-engines/trace-event-native.c $(OUTPUT)PERF-CFLAGS
+$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-redundant-decls 
-Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<

+
 $(OUTPUT)perf-%: %.o $(PERFLIBS)
 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)

diff --git a/tools/perf/PERF-FEATURES b/tools/perf/PERF-FEATURES
new file mode 100644
index 000..9e5500d
--- /dev/null
+++ b/tools/perf/PERF-FEATURES
@@ -0,0 +1 @@
+feature-dwarf(1) feature-glibc(1) feature-gtk2(1) feature-libaudit(1) 
feature-libbfd(1) feature-libelf(1) feature-libnuma(1) 
feature-libperl(0) feature-libpython(1) feature-libslang(1) 
feature-libunwind(1) feature-libdw-dwarf-unwind(0) 
dwarf-post-unwind(libunwind)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 9e9c91f..7241e30 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -522,6 +522,7 @@ static void setup_scripting(void)
 {
 setup_perl_scripting();
 setup_python_scripting();
+setup_native_scripting();

 scripting_ops = &default_scripting_ops;
 }
diff --git a/tools/perf/util/scripting-engines/trace-event-native.c 
b/tools/perf/util/scripting-engines/trace-event-native.c

new file mode 100644
index 000..4349bf1
--- /dev/null
+++ b/tools/perf/util/scripting-engines/trace-event-native.c
@@ -0,0 +1,125 @@
+#include 
+#include 
+
+#include "../../perf.h"
+#include "../evsel.h"
+#include "../util.h"
+#include "../event.h"
+#include "../thread.h"
+#include "../trace-event.h"
+
+static void *handle;
+
+enum syms {
+START_SCRIPT = 0,
+STOP_SCRIPT,
+PROCESS_EVENT,
+GENERATE_SCRIPT,
+};
+
+const char *sym_names[4] = {"start_script",
+"stop_script",
+"process_event",
+"generate_script"};
+
+int  (*so_start_script)(const char*, int, const char**);
+int  (*so_stop_script)(void);
+void (*so_process_event)(union perf_event *, struct perf_sample *,
+ struct perf_evsel *, struct thread *,
+ struct addr_location *);
+
+static void native_process_event(union perf_event *event __maybe_unused,
+ struct perf_sample *sample,
+ struct perf_evsel *evsel,
+ s

[PATCH] Error reporting improvement

2014-04-16 Thread Adrien BAK

In the current version, when using perf record, if something goes wrong in
tools/perf/builtin-record.c:375  session = perf_session__new(file, 
false, NULL);

The error message:
"Not enough memory for reading per file header"
is issued. This error message seems to be outdated and is not very helpful.
This patch propose to replace this error message by
"Perf session creation failed"

I believe this issue has been brought to lkml :
https://lkml.org/lkml/2014/2/24/458
although this patch only tackle a (small) part of the issue.

Additionnaly, this patch improves error reporting in
tools/perf/util/data.c open_file_write
Currently, if the call to open fails, the user is unaware of it.
This patch logs the error, before returning the error code to the caller.

Signed-off-by: Adrien BAK 

---
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index eb524f9..8ce62ef 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -374,7 +374,7 @@ static int __cmd_record(struct record *rec, int 
argc, const char **argv)


 session = perf_session__new(file, false, NULL);
 if (session == NULL) {
-pr_err("Not enough memory for reading perf file header\n");
+pr_err("Perf session creation failed.\n");
 return -1;
 }

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 1fbcd8b..ff2ced7 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -86,10 +86,16 @@ static int open_file_read(struct perf_data_file *file)

 static int open_file_write(struct perf_data_file *file)
 {
+int fd;
 if (check_backup(file))
 return -1;

-return open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
+fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
+
+if (fd < 0)
+pr_err("failed to open %s : %s\n", file->path, strerror(errno));
+
+return fd;
 }

 static int open_file(struct perf_data_file *file)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] perf tools : adds support for native scripting

2014-05-21 Thread Adrien BAK
As it is perf-script allows one to use perl or python scripts to parse 
perf events.
The following proposal aimed to introduce support of .so files as scripts.
This support allows for better performance when parsing perf's data 
files and a complete access to the raw data.

This support is implemented analogously to the one in place for 
perl/python script.
More precisely, when passing a .so file as a script argument, the 
following symbols
are loaded :
- start_script
- stop_script
- process_event
These symbols will be called instead of the corresponding :
- default_start_script
- default_stop_script
- process_event

There currently is a limitation regarding the generate_script function 
which cannot be generalized to native scripts. Is it better to leave
 things as they are (die gracefully when the user asks for 
native_generate_script) or to do one of the following :
- print a usage message specifying the symbols a .so script should 
expose
- create a .c file complying with said interface

Regarding style compliance, the following issues remains :
- 3 'fprintf' lines slightly over 80 chars in trace-event-native.
Is it better to introduce a line break than to have a 83-chars 
long line?
- in trace-event-scripting.c a struct is declared as extern. Here, 
I followed what was already done for perl/python scripting.


Signed-off-by: Adrien BAK 

---

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 895edd3..1342a2e 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -543,6 +543,10 @@ ifndef NO_LIBPYTHON
   LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
 endif
 
+ifndef NO_NATIVE_SCRIPTING
+  LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-native.o
+endif
+
 ifeq ($(NO_PERF_REGS),0)
   ifeq ($(ARCH),x86)
 LIB_H += arch/x86/include/perf_regs.h
@@ -715,6 +719,9 @@ $(OUTPUT)util/scripting-engines/trace-event-python.o: 
util/scripting-engines/tra
 $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: 
scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PYTHON_EMBED_CCOPTS) 
-Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter 
-Wno-nested-externs $<
 
+$(OUTPUT)util/scripting-engines/trace-event-native.o: 
util/scripting-engines/trace-event-native.c $(OUTPUT)PERF-CFLAGS
+   $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-redundant-decls 
-Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
+
 $(OUTPUT)perf-%: %.o $(PERFLIBS)
$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 9e9c91f..7241e30 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -522,6 +522,7 @@ static void setup_scripting(void)
 {
setup_perl_scripting();
setup_python_scripting();
+   setup_native_scripting();
 
scripting_ops = &default_scripting_ops;
 }
diff --git a/tools/perf/util/scripting-engines/trace-event-native.c 
b/tools/perf/util/scripting-engines/trace-event-native.c
new file mode 100644
index 000..4349bf1
--- /dev/null
+++ b/tools/perf/util/scripting-engines/trace-event-native.c
@@ -0,0 +1,125 @@
+#include 
+#include 
+
+#include "../../perf.h"
+#include "../evsel.h"
+#include "../util.h"
+#include "../event.h"
+#include "../thread.h"
+#include "../trace-event.h"
+
+static void *handle;
+
+enum syms {
+START_SCRIPT = 0,
+STOP_SCRIPT,
+PROCESS_EVENT,
+GENERATE_SCRIPT,
+};
+
+const char *sym_names[4] = {"start_script",
+   "stop_script",
+   "process_event",
+   "generate_script"};
+
+int  (*so_start_script)(const char*, int, const char**);
+int  (*so_stop_script)(void);
+void (*so_process_event)(union perf_event *, struct perf_sample *,
+struct perf_evsel *, struct thread *,
+struct addr_location *);
+
+static void native_process_event(union perf_event *event __maybe_unused,
+struct perf_sample *sample,
+struct perf_evsel *evsel,
+struct thread *thread,
+struct addr_location *al)
+{
+   (so_process_event)(event, sample, evsel, thread, al);
+}
+
+static int native_start_script(const char *script, int argc, const char **argv)
+{
+   int err = 0;
+
+   char *local_error;
+
+   handle = dlopen(script, RTLD_NOW);
+
+   if (!handle) {
+   fprintf(stderr, "an error occurred while loading the .so 
file\n");
+   fprintf(stderr, "%s\n", dlerror());
+   return -1;
+   }
+
+   *(void **)(

[tip:perf/urgent] perf tools: Improve error reporting

2014-04-20 Thread tip-bot for Adrien BAK
Commit-ID:  ffa91880a992ec1aaee4b4f7c9ddffda0c277ba9
Gitweb: http://git.kernel.org/tip/ffa91880a992ec1aaee4b4f7c9ddffda0c277ba9
Author: Adrien BAK 
AuthorDate: Fri, 18 Apr 2014 11:00:43 +0900
Committer:  Jiri Olsa 
CommitDate: Sun, 20 Apr 2014 00:15:12 +0200

perf tools: Improve error reporting

In the current version, when using perf record, if something goes
wrong in tools/perf/builtin-record.c:375
  session = perf_session__new(file, false, NULL);

The error message:
"Not enough memory for reading per file header"

is issued. This error message seems to be outdated and is not very
helpful. This patch proposes to replace this error message by
"Perf session creation failed"

I believe this issue has been brought to lkml:
https://lkml.org/lkml/2014/2/24/458
although this patch only tackles a (small) part of the issue.

Additionnaly, this patch improves error reporting in
tools/perf/util/data.c open_file_write.

Currently, if the call to open fails, the user is unaware of it.
This patch logs the error, before returning the error code to
the caller.

Reported-by: Will Deacon 
Signed-off-by: Adrien BAK 
Link: http://lkml.kernel.org/r/1397786443.3093.4.camel@beast
[ Reorganize the changelog into paragraphs ]
[ Added empty line after fd declaration in open_file_write ]
Signed-off-by: Jiri Olsa 
---
 tools/perf/builtin-record.c | 2 +-
 tools/perf/util/data.c  | 9 -
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index eb524f9..8ce62ef 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -374,7 +374,7 @@ static int __cmd_record(struct record *rec, int argc, const 
char **argv)
 
session = perf_session__new(file, false, NULL);
if (session == NULL) {
-   pr_err("Not enough memory for reading perf file header\n");
+   pr_err("Perf session creation failed.\n");
return -1;
}
 
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 1fbcd8b..55de44e 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -86,10 +86,17 @@ static int open_file_read(struct perf_data_file *file)
 
 static int open_file_write(struct perf_data_file *file)
 {
+   int fd;
+
if (check_backup(file))
return -1;
 
-   return open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
+   fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);
+
+   if (fd < 0)
+   pr_err("failed to open %s : %s\n", file->path, strerror(errno));
+
+   return fd;
 }
 
 static int open_file(struct perf_data_file *file)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/