aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r--tools/perf/util/util.c35
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 */
13unsigned int page_size;
14
13bool perf_host = true; 15bool perf_host = true;
14bool perf_guest = false; 16bool 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
169static 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 */
184int 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
169void dump_stack(void) 204void dump_stack(void)