Merge branch 'perf/urgent' into perf/core
authorIngo Molnar <mingo@kernel.org>
Wed, 24 Oct 2012 08:20:57 +0000 (10:20 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 24 Oct 2012 08:20:57 +0000 (10:20 +0200)
Pick up v3.7-rc2 and fixes before applying more patches.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
1  2 
tools/perf/Makefile
tools/perf/builtin-trace.c
tools/perf/util/thread.c

diff --combined tools/perf/Makefile
@@@ -74,7 -74,7 +74,7 @@@ ifeq ($(ARCH),x86_64
        override ARCH := x86
        IS_X86_64 := 0
        ifeq (, $(findstring m32,$(EXTRA_CFLAGS)))
-               IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -xc - | tail -n 1)
+               IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1)
        endif
        ifeq (${IS_X86_64}, 1)
                RAW_ARCH := x86_64
@@@ -155,15 -155,15 +155,15 @@@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__pow
  
  -include config/feature-tests.mak
  
 -ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y)
 +ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all),y)
        CFLAGS := $(CFLAGS) -fstack-protector-all
  endif
  
 -ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wstack-protector),y)
 +ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wstack-protector),y)
         CFLAGS := $(CFLAGS) -Wstack-protector
  endif
  
 -ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wvolatile-register-var),y)
 +ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wvolatile-register-var),y)
         CFLAGS := $(CFLAGS) -Wvolatile-register-var
  endif
  
  BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)util -I$(TRACE_EVENT_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
  BASIC_LDFLAGS =
  
 +ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS)),y)
 +      BIONIC := 1
 +      EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
 +      EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
 +      BASIC_CFLAGS += -I.
 +endif
 +
  # Guard against environment variables
  BUILTIN_OBJS =
  LIB_H =
@@@ -191,9 -184,22 +191,22 @@@ SCRIPT_SH += perf-archive.s
  grep-libs = $(filter -l%,$(1))
  strip-libs = $(filter-out -l%,$(1))
  
+ TRACE_EVENT_DIR = ../lib/traceevent/
+ ifneq ($(OUTPUT),)
+       TE_PATH=$(OUTPUT)
+ else
+       TE_PATH=$(TRACE_EVENT_DIR)
+ endif
+ LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
+ TE_LIB := -L$(TE_PATH) -ltraceevent
  PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
  PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py
  
+ export LIBTRACEEVENT
  $(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
        $(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \
          --quiet build_ext; \
  
  SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH))
  
- TRACE_EVENT_DIR = ../lib/traceevent/
- ifneq ($(OUTPUT),)
-       TE_PATH=$(OUTPUT)
- else
-       TE_PATH=$(TRACE_EVENT_DIR)
- endif
- LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
- TE_LIB := -L$(TE_PATH) -ltraceevent
  #
  # Single 'perf' binary right now:
  #
@@@ -259,10 -254,10 +261,10 @@@ $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-
  
  LIB_FILE=$(OUTPUT)libperf.a
  
- LIB_H += ../../include/linux/perf_event.h
+ LIB_H += ../../include/uapi/linux/perf_event.h
  LIB_H += ../../include/linux/rbtree.h
  LIB_H += ../../include/linux/list.h
- LIB_H += ../../include/linux/const.h
+ LIB_H += ../../include/uapi/linux/const.h
  LIB_H += ../../include/linux/hash.h
  LIB_H += ../../include/linux/stringify.h
  LIB_H += util/include/linux/bitmap.h
@@@ -277,6 -272,7 +279,7 @@@ LIB_H += util/include/linux/magic.
  LIB_H += util/include/linux/poison.h
  LIB_H += util/include/linux/prefetch.h
  LIB_H += util/include/linux/rbtree.h
+ LIB_H += util/include/linux/rbtree_augmented.h
  LIB_H += util/include/linux/string.h
  LIB_H += util/include/linux/types.h
  LIB_H += util/include/linux/linkage.h
@@@ -307,7 -303,6 +310,7 @@@ LIB_H += util/evlist.
  LIB_H += util/exec_cmd.h
  LIB_H += util/types.h
  LIB_H += util/levenshtein.h
 +LIB_H += util/machine.h
  LIB_H += util/map.h
  LIB_H += util/parse-options.h
  LIB_H += util/parse-events.h
@@@ -391,7 -386,6 +394,7 @@@ LIB_OBJS += $(OUTPUT)util/header.
  LIB_OBJS += $(OUTPUT)util/callchain.o
  LIB_OBJS += $(OUTPUT)util/values.o
  LIB_OBJS += $(OUTPUT)util/debug.o
 +LIB_OBJS += $(OUTPUT)util/machine.o
  LIB_OBJS += $(OUTPUT)util/map.o
  LIB_OBJS += $(OUTPUT)util/pstack.o
  LIB_OBJS += $(OUTPUT)util/session.o
@@@ -476,18 -470,12 +479,18 @@@ els
  FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
  ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF)),y)
        FLAGS_GLIBC=$(ALL_CFLAGS) $(ALL_LDFLAGS)
 -      ifneq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC)),y)
 -              msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
 -      else
 +      ifeq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC)),y)
 +              LIBC_SUPPORT := 1
 +      endif
 +      ifeq ($(BIONIC),1)
 +              LIBC_SUPPORT := 1
 +      endif
 +      ifeq ($(LIBC_SUPPORT),1)
                NO_LIBELF := 1
                NO_DWARF := 1
                NO_DEMANGLE := 1
 +      else
 +              msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
        endif
  else
        FLAGS_DWARF=$(ALL_CFLAGS) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
@@@ -766,12 -754,6 +769,12 @@@ ifndef NO_STRLCP
        endif
  endif
  
 +ifndef NO_ON_EXIT
 +      ifeq ($(call try-cc,$(SOURCE_ON_EXIT),),y)
 +              BASIC_CFLAGS += -DHAVE_ON_EXIT
 +      endif
 +endif
 +
  ifndef NO_BACKTRACE
         ifeq ($(call try-cc,$(SOURCE_BACKTRACE),),y)
                 BASIC_CFLAGS += -DBACKTRACE_SUPPORT
@@@ -902,7 -884,7 +905,7 @@@ $(OUTPUT)ui/browsers/map.o: ui/browsers
        $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
  
  $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
  
  $(OUTPUT)util/parse-events.o: util/parse-events.c $(OUTPUT)PERF-CFLAGS
        $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls $<
@@@ -52,17 -52,14 +52,21 @@@ struct trace 
        struct perf_record_opts opts;
  };
  
 +static bool done = false;
 +
 +static void sig_handler(int sig __maybe_unused)
 +{
 +      done = true;
 +}
 +
  static int trace__read_syscall_info(struct trace *trace, int id)
  {
        char tp_name[128];
        struct syscall *sc;
+       const char *name = audit_syscall_to_name(id, trace->audit_machine);
+       if (name == NULL)
+               return -1;
  
        if (id > trace->syscalls.max) {
                struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc));
        }
  
        sc = trace->syscalls.table + id;
-       sc->name = audit_syscall_to_name(id, trace->audit_machine);
-       if (sc->name == NULL)
-               return -1;
-       sc->fmt = syscall_fmt__find(sc->name);
+       sc->name = name;
+       sc->fmt  = syscall_fmt__find(sc->name);
  
        snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name);
        sc->tp_format = event_format__new("syscalls", tp_name);
@@@ -196,12 -190,11 +197,12 @@@ static int trace__sys_exit(struct trac
        return 0;
  }
  
 -static int trace__run(struct trace *trace)
 +static int trace__run(struct trace *trace, int argc, const char **argv)
  {
        struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
        struct perf_evsel *evsel;
        int err = -1, i, nr_events = 0, before;
 +      const bool forks = argc > 0;
  
        if (evlist == NULL) {
                printf("Not enough memory to run!\n");
  
        perf_evlist__config_attrs(evlist, &trace->opts);
  
 +      signal(SIGCHLD, sig_handler);
 +      signal(SIGINT, sig_handler);
 +
 +      if (forks) {
 +              err = perf_evlist__prepare_workload(evlist, &trace->opts, argv);
 +              if (err < 0) {
 +                      printf("Couldn't run the workload!\n");
 +                      goto out_delete_evlist;
 +              }
 +      }
 +
        err = perf_evlist__open(evlist);
        if (err < 0) {
                printf("Couldn't create the events: %s\n", strerror(errno));
        }
  
        perf_evlist__enable(evlist);
 +
 +      if (forks)
 +              perf_evlist__start_workload(evlist);
 +
  again:
        before = nr_events;
  
                        if (evlist->threads->map[0] == -1 || evlist->threads->nr > 1)
                                printf("%d ", sample.tid);
  
+                       if (sample.raw_data == NULL) {
+                               printf("%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
+                                      perf_evsel__name(evsel), sample.tid,
+                                      sample.cpu, sample.raw_size);
+                               continue;
+                       }
                        handler = evsel->handler.func;
                        handler(trace, evsel, &sample);
                }
        }
  
 -      if (nr_events == before)
 +      if (nr_events == before) {
 +              if (done)
 +                      goto out_delete_evlist;
 +
                poll(evlist->pollfd, evlist->nr_fds, -1);
 +      }
 +
 +      if (done)
 +              perf_evlist__disable(evlist);
  
        goto again;
  
@@@ -316,8 -294,7 +324,8 @@@ out
  int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
  {
        const char * const trace_usage[] = {
 -              "perf trace [<options>]",
 +              "perf trace [<options>] [<command>]",
 +              "perf trace [<options>] -- <command> [<options>]",
                NULL
        };
        struct trace trace = {
        OPT_END()
        };
        int err;
 +      char bf[BUFSIZ];
  
        argc = parse_options(argc, argv, trace_options, trace_usage, 0);
 -      if (argc)
 -              usage_with_options(trace_usage, trace_options);
 +
 +      err = perf_target__validate(&trace.opts.target);
 +      if (err) {
 +              perf_target__strerror(&trace.opts.target, err, bf, sizeof(bf));
 +              printf("%s", bf);
 +              return err;
 +      }
  
        err = perf_target__parse_uid(&trace.opts.target);
        if (err) {
 -              char bf[BUFSIZ];
                perf_target__strerror(&trace.opts.target, err, bf, sizeof(bf));
                printf("%s", bf);
                return err;
        }
  
 -      return trace__run(&trace);
 +      if (!argc && perf_target__none(&trace.opts.target))
 +              trace.opts.target.system_wide = true;
 +
 +      return trace__run(&trace, argc, argv);
  }
diff --combined tools/perf/util/thread.c
@@@ -7,7 -7,7 +7,7 @@@
  #include "util.h"
  #include "debug.h"
  
 -static struct thread *thread__new(pid_t pid)
 +struct thread *thread__new(pid_t pid)
  {
        struct thread *self = zalloc(sizeof(*self));
  
@@@ -39,7 -39,6 +39,6 @@@ int thread__set_comm(struct thread *sel
        err = self->comm == NULL ? -ENOMEM : 0;
        if (!err) {
                self->comm_set = true;
-               map_groups__flush(&self->mg);
        }
        return err;
  }
@@@ -61,6 -60,45 +60,6 @@@ static size_t thread__fprintf(struct th
               map_groups__fprintf(&self->mg, verbose, fp);
  }
  
 -struct thread *machine__findnew_thread(struct machine *self, pid_t pid)
 -{
 -      struct rb_node **p = &self->threads.rb_node;
 -      struct rb_node *parent = NULL;
 -      struct thread *th;
 -
 -      /*
 -       * Font-end cache - PID lookups come in blocks,
 -       * so most of the time we dont have to look up
 -       * the full rbtree:
 -       */
 -      if (self->last_match && self->last_match->pid == pid)
 -              return self->last_match;
 -
 -      while (*p != NULL) {
 -              parent = *p;
 -              th = rb_entry(parent, struct thread, rb_node);
 -
 -              if (th->pid == pid) {
 -                      self->last_match = th;
 -                      return th;
 -              }
 -
 -              if (pid < th->pid)
 -                      p = &(*p)->rb_left;
 -              else
 -                      p = &(*p)->rb_right;
 -      }
 -
 -      th = thread__new(pid);
 -      if (th != NULL) {
 -              rb_link_node(&th->rb_node, parent, p);
 -              rb_insert_color(&th->rb_node, &self->threads);
 -              self->last_match = th;
 -      }
 -
 -      return th;
 -}
 -
  void thread__insert_map(struct thread *self, struct map *map)
  {
        map_groups__fixup_overlappings(&self->mg, map, verbose, stderr);