diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-18 11:19:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-18 11:19:03 -0400 |
commit | 4d7b4ac22fbec1a03206c6cde353f2fd6942f828 (patch) | |
tree | 2d96a9e9c28cf6fa628a278decc00ad55a8b043b /tools/perf/util/pstack.c | |
parent | 3aaf51ace5975050ab43c7d4d7e439e0ae7d13d7 (diff) | |
parent | 94f3ca95787ada3d64339a4ecb2754236ab563f6 (diff) |
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (311 commits)
perf tools: Add mode to build without newt support
perf symbols: symbol inconsistency message should be done only at verbose=1
perf tui: Add explicit -lslang option
perf options: Type check all the remaining OPT_ variants
perf options: Type check OPT_BOOLEAN and fix the offenders
perf options: Check v type in OPT_U?INTEGER
perf options: Introduce OPT_UINTEGER
perf tui: Add workaround for slang < 2.1.4
perf record: Fix bug mismatch with -c option definition
perf options: Introduce OPT_U64
perf tui: Add help window to show key associations
perf tui: Make <- exit menus too
perf newt: Add single key shortcuts for zoom into DSO and threads
perf newt: Exit browser unconditionally when CTRL+C, q or Q is pressed
perf newt: Fix the 'A'/'a' shortcut for annotate
perf newt: Make <- exit the ui_browser
x86, perf: P4 PMU - fix counters management logic
perf newt: Make <- zoom out filters
perf report: Report number of events, not samples
perf hist: Clarify events_stats fields usage
...
Fix up trivial conflicts in kernel/fork.c and tools/perf/builtin-record.c
Diffstat (limited to 'tools/perf/util/pstack.c')
-rw-r--r-- | tools/perf/util/pstack.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tools/perf/util/pstack.c b/tools/perf/util/pstack.c new file mode 100644 index 000000000000..13d36faf64eb --- /dev/null +++ b/tools/perf/util/pstack.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * Simple pointer stack | ||
3 | * | ||
4 | * (c) 2010 Arnaldo Carvalho de Melo <acme@redhat.com> | ||
5 | */ | ||
6 | |||
7 | #include "util.h" | ||
8 | #include "pstack.h" | ||
9 | #include <linux/kernel.h> | ||
10 | #include <stdlib.h> | ||
11 | |||
12 | struct pstack { | ||
13 | unsigned short top; | ||
14 | unsigned short max_nr_entries; | ||
15 | void *entries[0]; | ||
16 | }; | ||
17 | |||
18 | struct pstack *pstack__new(unsigned short max_nr_entries) | ||
19 | { | ||
20 | struct pstack *self = zalloc((sizeof(*self) + | ||
21 | max_nr_entries * sizeof(void *))); | ||
22 | if (self != NULL) | ||
23 | self->max_nr_entries = max_nr_entries; | ||
24 | return self; | ||
25 | } | ||
26 | |||
27 | void pstack__delete(struct pstack *self) | ||
28 | { | ||
29 | free(self); | ||
30 | } | ||
31 | |||
32 | bool pstack__empty(const struct pstack *self) | ||
33 | { | ||
34 | return self->top == 0; | ||
35 | } | ||
36 | |||
37 | void pstack__remove(struct pstack *self, void *key) | ||
38 | { | ||
39 | unsigned short i = self->top, last_index = self->top - 1; | ||
40 | |||
41 | while (i-- != 0) { | ||
42 | if (self->entries[i] == key) { | ||
43 | if (i < last_index) | ||
44 | memmove(self->entries + i, | ||
45 | self->entries + i + 1, | ||
46 | (last_index - i) * sizeof(void *)); | ||
47 | --self->top; | ||
48 | return; | ||
49 | } | ||
50 | } | ||
51 | pr_err("%s: %p not on the pstack!\n", __func__, key); | ||
52 | } | ||
53 | |||
54 | void pstack__push(struct pstack *self, void *key) | ||
55 | { | ||
56 | if (self->top == self->max_nr_entries) { | ||
57 | pr_err("%s: top=%d, overflow!\n", __func__, self->top); | ||
58 | return; | ||
59 | } | ||
60 | self->entries[self->top++] = key; | ||
61 | } | ||
62 | |||
63 | void *pstack__pop(struct pstack *self) | ||
64 | { | ||
65 | void *ret; | ||
66 | |||
67 | if (self->top == 0) { | ||
68 | pr_err("%s: underflow!\n", __func__); | ||
69 | return NULL; | ||
70 | } | ||
71 | |||
72 | ret = self->entries[--self->top]; | ||
73 | self->entries[self->top] = NULL; | ||
74 | return ret; | ||
75 | } | ||