Debian Codegraph @

tapset/speculative.stp

raw
1 // Speculative tapset
2 // Copyright (C) 2011-2015 Red Hat Inc.
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8
9 @__private30 global _spec_id
10 @__private30 global _spec_counter%
11 @__private30 global _spec_buff%
12
13
14 /**
15 * sfunction speculation - Allocate a new id for speculative output
16 *
17 * The speculation() function is called when a new speculation buffer is needed.
18 * It returns an id for the speculative output.
19 * There can be multiple threads being speculated on concurrently.
20 * This id is used by other speculation functions to keep the threads
21 * separate.
22 */
23 function speculation:long ()
24 {
25 _spec_id += 1
26 return _spec_id
27 }
28
29
30 /**
31 * sfunction speculate - Store a string for possible output later
32 * @id: buffer id to store the information in
33 * @output: string to write out when commit occurs
34 *
35 * Add a string to the speculaive buffer for id.
36 */
37 function speculate (id:long, output:string)
38 {
39 _spec_counter[id] += 1
40 _spec_buff[id, _spec_counter[id]] = output
41 }
42
43
44 /**
45 * sfunction discard - Discard all output related to a speculation buffer
46 * @id: of the buffer to store the information in
47 *
48 */
49 function discard (id:long)
50 {
51 delete _spec_buff[id,*]
52 }
53
54
55 /**
56 * sfunction commit - Write out all output related to a speculation buffer
57 * @id: of the buffer to store the information in
58 *
59 * Output all the output for @id in the order that it was entered into
60 * the speculative buffer by speculative().
61 */
62 function commit (id:long)
63 {
64 foreach([i, counter+] in _spec_buff [id,*]) {
65 printf("%s", _spec_buff[i, counter])
66 }
67 delete _spec_buff[id,*]
68 }