perf_counter tools: Use hex2u64 in more places
PATCH 1/2 perf_counter tools: Use hex2u64 in more places
This has also a nice side effect, tools built on newer systems such as fedora 10 again work on systems with older versions of glibc:
My workstation:
[acme@doppio ~]$ rpm -q glibc.x86_64
glibc-2.9-3.x86_64
Test machine:
[acme@emilia ~]$ rpm -q glibc.x86_64
glibc-2.5-24
Before:
[acme@emilia ~]$ perf
perf: /lib64/libc.so.6: version GLIBC_2.7' not found (required by perf) [acme@emilia ~]$ nm which perf` | grep GLIBC_2\.7
U __isoc99_sscanf@@GLIBC_2.7
[acme@emilia ~]$
After:
[acme@emilia ~]$ perf
usage: perf [--version] [--help] COMMAND [ARGS]
The most commonly used perf commands are:
record Run a command and record its profile into perf.data
report Read perf.data (created by perf record) and display the
profile
stat Run a command and gather performance counter statistics
top Run a command and profile it
See 'perf help COMMAND' for more information on a specific command. [acme@emilia ~]$ nm which perf | grep GLIBC_2\.7 [acme@emilia ~]$
--- Documentation/perf_counter/Makefile | 2 + Documentation/perf_counter/builtin-record.c | 56 +++++++++++++---------- Documentation/perf_counter/builtin-report.c | 1 + Documentation/perf_counter/util/parse-events.c | 27 +++++++----- Documentation/perf_counter/util/symbol.c | 38 +--------------- 5 files changed, 54 insertions(+), 70 deletions(-)
Documentation/perf_counter/Makefile +2 -0
@@ -296,6 +296,7 @@ LIB_H += util/quote.h LIB_H += util/util.h LIB_H += util/help.h LIB_H += util/strbuf.h +LIB_H += util/string.h LIB_H += util/run-command.h LIB_H += util/sigchain.h LIB_H += util/symbol.h
@@ -315,6 +316,7 @@ LIB_OBJS += util/rbtree.o LIB_OBJS += util/run-command.o LIB_OBJS += util/quote.o LIB_OBJS += util/strbuf.o +LIB_OBJS += util/string.o LIB_OBJS += util/usage.o LIB_OBJS += util/wrapper.o LIB_OBJS += util/sigchain.o
Documentation/perf_counter/builtin-record.c +32 -24
99 lines not on this page · raw message
Documentation/perf_counter/builtin-report.c +1 -0
@@ -5,6 +5,7 @@#include "util/cache.h" #include "util/rbtree.h" #include "util/symbol.h" +#include "util/string.h" #include "perf.h"
Documentation/perf_counter/util/parse-events.c +16 -11
@@ -4,6 +4,7 @@#include "parse-options.h" #include "parse-events.h" #include "exec_cmd.h" +#include "string.h" int nr_counters;
@@ -105,22 +106,26 @@ static __u64 match_event_symbols(const char *str)__u64 config, id;int type;unsigned int i; -char mask_str[4 ]; +const char *sep, *pstr; -if (sscanf (str,"r%llx" , &config) ==1 ) +if (str[0 ] =='r' &&hex2u64 (str +1 , &config) >0 )return config |PERF_COUNTER_RAW_MASK ; -switch (sscanf (str,"%d:%llu:%2s" , &type, &id, mask_str)) { -case 3 : -if (strchr (mask_str,'k' )) + pstr = str; + sep =strchr (pstr,':' ); +if (sep) { + type =atoi (pstr); + pstr = sep +1 ; + id =atoi (pstr); + sep =strchr (pstr,':' ); +if (sep) { + pstr = sep +1 ; +if (strchr (pstr,'k' )) event_mask[nr_counters] |=EVENT_MASK_USER ; -if (strchr (mask_str,'u' )) +if (strchr (pstr,'u' )) event_mask[nr_counters] |=EVENT_MASK_KERNEL ; -case 2 : -return EID (type, id); - -default : -break ; + } +return EID (type, id); }for (i =0 ; i <ARRAY_SIZE (event_symbols); i++) {
Documentation/perf_counter/util/symbol.c +3 -35
@@ -1,5 +1,6 @@#include "util.h" #include "../perf.h" +#include "string.h" #include "symbol.h" #include <libelf.h>
@@ -122,39 +123,6 @@ size_t dso__fprintf(struct dso *self, FILE *fp)return ret; } -static int hex (char ch) -{ -if ((ch >='0' ) && (ch <='9' )) -return ch -'0' ; -if ((ch >='a' ) && (ch <='f' )) -return ch -'a' +10 ; -if ((ch >='A' ) && (ch <='F' )) -return ch -'A' +10 ; -return -1 ; -} - -/* -* While we find nice hex chars, build a long_val. -* Return number of chars processed. -*/ -static int hex2long (char *ptr,unsigned long *long_val) -{ -const char *p = ptr; - *long_val =0 ; - -while (*p) { -const int hex_val =hex (*p); - -if (hex_val <0 ) -break ; - - *long_val = (*long_val <<4 ) | hex_val; - p++; - } - -return p - ptr; -} -static int dso__load_kallsyms (struct dso *self,symbol_filter_t filter) {struct rb_node *nd, *prevnd;
@@ -166,7 +134,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) goto out_failure;while (!feof (file)) { -unsigned long start; +__u64 start;struct symbol *sym;int line_len, len;char symbol_type;
@@ -180,7 +148,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) line[--line_len] ='\0' ;/* \n */ - len =hex2long (line, &start); + len =hex2u64 (line, &start); len++;if (len +2 >= line_len)
Signature · 1 line
1.6.0.6
Commit-ID: de0ee4936ac8dc658f6bda65761474bf4f58701a Gitweb: http://git.kernel.org/tip/de0ee4936ac8dc658f6bda65761474bf4f58701a Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Mon, 1 Jun 2009 17:50:19 -0300 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Jun 2009 00:57:14 +0200
perf_counter tools: Use hex2u64 in more places
This has also a nice side effect, tools built on newer systems such as fedora 10 again work on systems with older versions of glibc:
My workstation:
[acme@doppio ~]$ rpm -q glibc.x86_64
glibc-2.9-3.x86_64
Test machine:
[acme@emilia ~]$ rpm -q glibc.x86_64
glibc-2.5-24
Before:
[acme@emilia ~]$ perf
perf: /lib64/libc.so.6: version GLIBC_2.7' not found (required by perf) [acme@emilia ~]$ nm which perf` | grep GLIBC_2\.7
U __isoc99_sscanf@@GLIBC_2.7
[acme@emilia ~]$
After:
[acme@emilia ~]$ perf
usage: perf [--version] [--help] COMMAND [ARGS]
The most commonly used perf commands are:
record Run a command and record its profile into perf.data
report Read perf.data (created by perf record) and display the
profile
stat Run a command and gather performance counter statistics
top Run a command and profile it
See 'perf help COMMAND' for more information on a specific command. [acme@emilia ~]$ nm which perf | grep GLIBC_2\.7 [acme@emilia ~]$
LKML-Reference: <[email protected]>
--- Documentation/perf_counter/Makefile | 2 + Documentation/perf_counter/builtin-record.c | 56 +++++++++++++---------- Documentation/perf_counter/builtin-report.c | 1 + Documentation/perf_counter/util/parse-events.c | 27 +++++++----- Documentation/perf_counter/util/symbol.c | 38 +--------------- 5 files changed, 54 insertions(+), 70 deletions(-)
Documentation/perf_counter/Makefile +2 -0
@@ -296,6 +296,7 @@ LIB_H += util/quote.h LIB_H += util/util.h LIB_H += util/help.h LIB_H += util/strbuf.h +LIB_H += util/string.h LIB_H += util/run-command.h LIB_H += util/sigchain.h LIB_H += util/symbol.h
@@ -315,6 +316,7 @@ LIB_OBJS += util/rbtree.o LIB_OBJS += util/run-command.o LIB_OBJS += util/quote.o LIB_OBJS += util/strbuf.o +LIB_OBJS += util/string.o LIB_OBJS += util/usage.o LIB_OBJS += util/wrapper.o LIB_OBJS += util/sigchain.o
Documentation/perf_counter/builtin-record.c +32 -24
99 lines not on this page · raw message
Documentation/perf_counter/builtin-report.c +1 -0
@@ -5,6 +5,7 @@#include "util/cache.h" #include "util/rbtree.h" #include "util/symbol.h" +#include "util/string.h" #include "perf.h"
Documentation/perf_counter/util/parse-events.c +16 -11
@@ -4,6 +4,7 @@#include "parse-options.h" #include "parse-events.h" #include "exec_cmd.h" +#include "string.h" int nr_counters;
@@ -105,22 +106,26 @@ static __u64 match_event_symbols(const char *str)__u64 config, id;int type;unsigned int i; -char mask_str[4 ]; +const char *sep, *pstr; -if (sscanf (str,"r%llx" , &config) ==1 ) +if (str[0 ] =='r' &&hex2u64 (str +1 , &config) >0 )return config |PERF_COUNTER_RAW_MASK ; -switch (sscanf (str,"%d:%llu:%2s" , &type, &id, mask_str)) { -case 3 : -if (strchr (mask_str,'k' )) + pstr = str; + sep =strchr (pstr,':' ); +if (sep) { + type =atoi (pstr); + pstr = sep +1 ; + id =atoi (pstr); + sep =strchr (pstr,':' ); +if (sep) { + pstr = sep +1 ; +if (strchr (pstr,'k' )) event_mask[nr_counters] |=EVENT_MASK_USER ; -if (strchr (mask_str,'u' )) +if (strchr (pstr,'u' )) event_mask[nr_counters] |=EVENT_MASK_KERNEL ; -case 2 : -return EID (type, id); - -default : -break ; + } +return EID (type, id); }for (i =0 ; i <ARRAY_SIZE (event_symbols); i++) {
Documentation/perf_counter/util/symbol.c +3 -35
@@ -1,5 +1,6 @@#include "util.h" #include "../perf.h" +#include "string.h" #include "symbol.h" #include <libelf.h>
@@ -122,39 +123,6 @@ size_t dso__fprintf(struct dso *self, FILE *fp)return ret; } -static int hex (char ch) -{ -if ((ch >='0' ) && (ch <='9' )) -return ch -'0' ; -if ((ch >='a' ) && (ch <='f' )) -return ch -'a' +10 ; -if ((ch >='A' ) && (ch <='F' )) -return ch -'A' +10 ; -return -1 ; -} - -/* -* While we find nice hex chars, build a long_val. -* Return number of chars processed. -*/ -static int hex2long (char *ptr,unsigned long *long_val) -{ -const char *p = ptr; - *long_val =0 ; - -while (*p) { -const int hex_val =hex (*p); - -if (hex_val <0 ) -break ; - - *long_val = (*long_val <<4 ) | hex_val; - p++; - } - -return p - ptr; -} -static int dso__load_kallsyms (struct dso *self,symbol_filter_t filter) {struct rb_node *nd, *prevnd;
@@ -166,7 +134,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) goto out_failure;while (!feof (file)) { -unsigned long start; +__u64 start;struct symbol *sym;int line_len, len;char symbol_type;
@@ -180,7 +148,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) line[--line_len] ='\0' ;/* \n */ - len =hex2long (line, &start); + len =hex2u64 (line, &start); len++;if (len +2 >= line_len)
Commit-ID: a0055ae2a4e13db9534c438cf8f3896181da6afc Gitweb: http://git.kernel.org/tip/a0055ae2a4e13db9534c438cf8f3896181da6afc Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Mon, 1 Jun 2009 17:50:19 -0300 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 2 Jun 2009 03:40:52 +0200
perf_counter tools: Use hex2u64 in more places
This has also a nice side effect, tools built on newer systems such as fedora 10 again work on systems with older versions of glibc:
My workstation:
[acme@doppio ~]$ rpm -q glibc.x86_64
glibc-2.9-3.x86_64
Test machine:
[acme@emilia ~]$ rpm -q glibc.x86_64
glibc-2.5-24
Before:
[acme@emilia ~]$ perf
perf: /lib64/libc.so.6: version GLIBC_2.7' not found (required by perf) [acme@emilia ~]$ nm which perf` | grep GLIBC_2\.7
U __isoc99_sscanf@@GLIBC_2.7
[acme@emilia ~]$
After:
[acme@emilia ~]$ perf
usage: perf [--version] [--help] COMMAND [ARGS]
The most commonly used perf commands are:
record Run a command and record its profile into perf.data
report Read perf.data (created by perf record) and display the
profile
stat Run a command and gather performance counter statistics
top Run a command and profile it
See 'perf help COMMAND' for more information on a specific command. [acme@emilia ~]$ nm which perf | grep GLIBC_2\.7 [acme@emilia ~]$
LKML-Reference: <[email protected]>
--- Documentation/perf_counter/Makefile | 2 + Documentation/perf_counter/builtin-record.c | 56 +++++++++++++---------- Documentation/perf_counter/builtin-report.c | 1 + Documentation/perf_counter/util/parse-events.c | 27 +++++++----- Documentation/perf_counter/util/symbol.c | 38 +--------------- 5 files changed, 54 insertions(+), 70 deletions(-)
Documentation/perf_counter/Makefile +2 -0
@@ -296,6 +296,7 @@ LIB_H += util/quote.h LIB_H += util/util.h LIB_H += util/help.h LIB_H += util/strbuf.h +LIB_H += util/string.h LIB_H += util/run-command.h LIB_H += util/sigchain.h LIB_H += util/symbol.h
@@ -315,6 +316,7 @@ LIB_OBJS += util/rbtree.o LIB_OBJS += util/run-command.o LIB_OBJS += util/quote.o LIB_OBJS += util/strbuf.o +LIB_OBJS += util/string.o LIB_OBJS += util/usage.o LIB_OBJS += util/wrapper.o LIB_OBJS += util/sigchain.o
Documentation/perf_counter/builtin-record.c +32 -24
99 lines not on this page · raw message
Documentation/perf_counter/builtin-report.c +1 -0
@@ -5,6 +5,7 @@#include "util/cache.h" #include "util/rbtree.h" #include "util/symbol.h" +#include "util/string.h" #include "perf.h"
Documentation/perf_counter/util/parse-events.c +16 -11
@@ -4,6 +4,7 @@#include "parse-options.h" #include "parse-events.h" #include "exec_cmd.h" +#include "string.h" int nr_counters;
@@ -105,22 +106,26 @@ static __u64 match_event_symbols(const char *str)__u64 config, id;int type;unsigned int i; -char mask_str[4 ]; +const char *sep, *pstr; -if (sscanf (str,"r%llx" , &config) ==1 ) +if (str[0 ] =='r' &&hex2u64 (str +1 , &config) >0 )return config |PERF_COUNTER_RAW_MASK ; -switch (sscanf (str,"%d:%llu:%2s" , &type, &id, mask_str)) { -case 3 : -if (strchr (mask_str,'k' )) + pstr = str; + sep =strchr (pstr,':' ); +if (sep) { + type =atoi (pstr); + pstr = sep +1 ; + id =atoi (pstr); + sep =strchr (pstr,':' ); +if (sep) { + pstr = sep +1 ; +if (strchr (pstr,'k' )) event_mask[nr_counters] |=EVENT_MASK_USER ; -if (strchr (mask_str,'u' )) +if (strchr (pstr,'u' )) event_mask[nr_counters] |=EVENT_MASK_KERNEL ; -case 2 : -return EID (type, id); - -default : -break ; + } +return EID (type, id); }for (i =0 ; i <ARRAY_SIZE (event_symbols); i++) {
Documentation/perf_counter/util/symbol.c +3 -35
@@ -1,5 +1,6 @@#include "util.h" #include "../perf.h" +#include "string.h" #include "symbol.h" #include <libelf.h>
@@ -122,39 +123,6 @@ size_t dso__fprintf(struct dso *self, FILE *fp)return ret; } -static int hex (char ch) -{ -if ((ch >='0' ) && (ch <='9' )) -return ch -'0' ; -if ((ch >='a' ) && (ch <='f' )) -return ch -'a' +10 ; -if ((ch >='A' ) && (ch <='F' )) -return ch -'A' +10 ; -return -1 ; -} - -/* -* While we find nice hex chars, build a long_val. -* Return number of chars processed. -*/ -static int hex2long (char *ptr,unsigned long *long_val) -{ -const char *p = ptr; - *long_val =0 ; - -while (*p) { -const int hex_val =hex (*p); - -if (hex_val <0 ) -break ; - - *long_val = (*long_val <<4 ) | hex_val; - p++; - } - -return p - ptr; -} -static int dso__load_kallsyms (struct dso *self,symbol_filter_t filter) {struct rb_node *nd, *prevnd;
@@ -166,7 +134,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) goto out_failure;while (!feof (file)) { -unsigned long start; +__u64 start;struct symbol *sym;int line_len, len;char symbol_type;
@@ -180,7 +148,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter) line[--line_len] ='\0' ;/* \n */ - len =hex2long (line, &start); + len =hex2u64 (line, &start); len++;if (len +2 >= line_len)