perf_counter tools: Rework the file format
Commit-ID: 7c6a1c65bbd3be688e581511f45818663efc1877 Gitweb: http://git.kernel.org/tip/7c6a1c65bbd3be688e581511f45818663efc1877 Author: Peter Zijlstra <[email protected]> AuthorDate: Thu, 25 Jun 2009 17:05:54 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 25 Jun 2009 21:39:04 +0200
perf_counter tools: Rework the file format
Create a structured file format that includes the full perf_counter_attr and all its relevant counter IDs so that the reporting program has full information.
Signed-off-by Peter Zijlstra <[email protected]>
LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>
---
tools/perf/Makefile | 3 +-
tools/perf/builtin-record.c | 100 +++++++++++------
tools/perf/builtin-report.c | 37 +++++--
tools/perf/perf.h | 8 +-
tools/perf/util/header.c | 242 +++++++++++++++++++++++++++++++++++++++++
tools/perf/util/header.h | 37 ++++++
tools/perf/util/string.h | 2 +-
tools/perf/util/symbol.h | 2 +-
tools/perf/{ => util}/types.h | 0
9 files changed, 377 insertions(+), 54 deletions(-)tools/perf/Makefile +2 -1
@@ -290,7 +290,7 @@ LIB_FILE=libperf.a LIB_H += ../../include/linux/perf_counter.h LIB_H += perf.h -LIB_H += types.h +LIB_H += util/types.h LIB_H += util/list.h LIB_H += util/rbtree.h LIB_H += util/levenshtein.h
@@ -328,6 +328,7 @@ LIB_OBJS += util/sigchain.o LIB_OBJS += util/symbol.o LIB_OBJS += util/color.o LIB_OBJS += util/pager.o +LIB_OBJS += util/header.o BUILTIN_OBJS += builtin-annotate.o BUILTIN_OBJS += builtin-help.o
tools/perf/builtin-record.c +65 -35
182 lines not on this page · raw message
tools/perf/builtin-report.c +28 -9
@@ -17,6 +17,7 @@#include "util/string.h" #include "perf.h" +#include "util/header.h" #include "util/parse-options.h" #include "util/parse-events.h"
@@ -1385,13 +1386,27 @@ process_event(event_t *event, unsigned long offset, unsigned long head)return 0 ; } -static struct perf_file_header file_header; +static struct perf_header *header; + +static int perf_header__has_sample (u64 sample_mask) +{ +int i; + +for (i =0 ; i < header->attrs; i++) { +struct perf_header_attr *attr = header->attr[i]; + +if (!(attr->attr.sample_type & sample_mask)) +return 0 ; + } + +return 1 ; +}static int __cmd_report (void ) {int ret, rc =EXIT_FAILURE ;unsigned long offset =0 ; -unsigned long head =sizeof (file_header); +unsigned long head, shift;struct stat stat;event_t *event;uint32_t size;
@@ -1419,13 +1434,11 @@ static int __cmd_report(void)exit (0 ); } -if (read (input, &file_header,sizeof (file_header)) ==-1 ) { -perror ("failed to read file headers" ); -exit (-1 ); - } + header =perf_header__read (input); + head = header->data_offset;if (sort__has_parent && - !(file_header.sample_type &PERF_SAMPLE_CALLCHAIN )) { + !perf_header__has_sample (PERF_SAMPLE_CALLCHAIN )) {fprintf (stderr,"selected --sort parent, but no callchain data\n" );exit (-1 ); }
@@ -1445,6 +1458,11 @@ static int __cmd_report(void) cwd =NULL ; cwdlen =0 ; } + + shift = page_size * (head / page_size); + offset += shift; + head -= shift; + remap: buf = (char *)mmap (NULL , page_size * mmap_window,PROT_READ ,MAP_SHARED , input, offset);
@@ -1461,9 +1479,10 @@ more: size =8 ;if (head + event->header.size >= page_size * mmap_window) { -unsigned long shift = page_size * (head / page_size);int ret; + shift = page_size * (head / page_size); + ret =munmap (buf, page_size * mmap_window);assert (ret ==0 );
@@ -1501,7 +1520,7 @@ more: head += size; -if (offset + head >=sizeof (file_header) + file_header.data_size) +if (offset + head >= header->data_offset + header->data_size) goto done;if (offset + head < stat.st_size)
tools/perf/perf.h +1 -7
@@ -19,7 +19,7 @@#include <sys/syscall.h> #include "../../include/linux/perf_counter.h" -#include "types.h" +#include "util/types.h" /* * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
@@ -66,10 +66,4 @@ sys_perf_counter_open(struct perf_counter_attr *attr,#define MAX_COUNTERS 256#define MAX_NR_CPUS 256 -struct perf_file_header { -u64 version; -u64 sample_type; -u64 data_size; -}; -#endif
tools/perf/util/header.c new file +242 -0
242 lines not on this page · raw message
tools/perf/util/header.h new file +37 -0
@@ -0,0 +1,37 @@ +#ifndef _PERF_HEADER_H +#define _PERF_HEADER_H + +#include "../../../include/linux/perf_counter.h" +#include <sys/types.h> +#include "types.h" + +struct perf_header_attr { +struct perf_counter_attr attr; +int ids, size; +u64 *id; +off_t id_offset; +}; + +struct perf_header { +int frozen; +int attrs, size; +struct perf_header_attr **attr; +off_t attr_offset; +u64 data_offset; +u64 data_size; +}; + +struct perf_header *perf_header__read (int fd); +void perf_header__write (struct perf_header *self,int fd); + +void perf_header__add_attr (struct perf_header *self, +struct perf_header_attr *attr); + +struct perf_header_attr * +perf_header_attr__new (struct perf_counter_attr *attr); +void perf_header_attr__add_id (struct perf_header_attr *self,u64 id); + + +struct perf_header *perf_header__new (void ); + +#endif /* _PERF_HEADER_H */
tools/perf/util/string.h +1 -1
@@ -1,7 +1,7 @@#ifndef _PERF_STRING_H_#define _PERF_STRING_H_ -#include "../types.h" +#include "types.h" int hex2u64 (const char *ptr,u64 *val);
tools/perf/util/symbol.h +1 -1
@@ -2,7 +2,7 @@#define _PERF_SYMBOL_ 1#include <linux/types.h> -#include "../types.h" +#include "types.h" #include "list.h" #include "rbtree.h"