diff options
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r-- | tools/perf/util/util.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 99664598bc1a..5906e8426cc7 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -10,6 +10,8 @@ | |||
10 | /* | 10 | /* |
11 | * XXX We need to find a better place for these things... | 11 | * XXX We need to find a better place for these things... |
12 | */ | 12 | */ |
13 | unsigned int page_size; | ||
14 | |||
13 | bool perf_host = true; | 15 | bool perf_host = true; |
14 | bool perf_guest = false; | 16 | bool perf_guest = false; |
15 | 17 | ||
@@ -164,6 +166,39 @@ size_t hex_width(u64 v) | |||
164 | return n; | 166 | return n; |
165 | } | 167 | } |
166 | 168 | ||
169 | static int hex(char ch) | ||
170 | { | ||
171 | if ((ch >= '0') && (ch <= '9')) | ||
172 | return ch - '0'; | ||
173 | if ((ch >= 'a') && (ch <= 'f')) | ||
174 | return ch - 'a' + 10; | ||
175 | if ((ch >= 'A') && (ch <= 'F')) | ||
176 | return ch - 'A' + 10; | ||
177 | return -1; | ||
178 | } | ||
179 | |||
180 | /* | ||
181 | * While we find nice hex chars, build a long_val. | ||
182 | * Return number of chars processed. | ||
183 | */ | ||
184 | int hex2u64(const char *ptr, u64 *long_val) | ||
185 | { | ||
186 | const char *p = ptr; | ||
187 | *long_val = 0; | ||
188 | |||
189 | while (*p) { | ||
190 | const int hex_val = hex(*p); | ||
191 | |||
192 | if (hex_val < 0) | ||
193 | break; | ||
194 | |||
195 | *long_val = (*long_val << 4) | hex_val; | ||
196 | p++; | ||
197 | } | ||
198 | |||
199 | return p - ptr; | ||
200 | } | ||
201 | |||
167 | /* Obtain a backtrace and print it to stdout. */ | 202 | /* Obtain a backtrace and print it to stdout. */ |
168 | #ifdef BACKTRACE_SUPPORT | 203 | #ifdef BACKTRACE_SUPPORT |
169 | void dump_stack(void) | 204 | void dump_stack(void) |