Debian Codegraph @

src/core/chuck_stats.h

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler, Virtual Machine, and Synthesis Engine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the dual-license terms of EITHER the MIT License OR the GNU
11 General Public License (the latter as published by the Free Software
12 Foundation; either version 2 of the License or, at your option, any
13 later version).
14
15 This program is distributed in the hope that it will be useful and/or
16 interesting, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 MIT Licence and/or the GNU General Public License for details.
19
20 You should have received a copy of the MIT License and the GNU General
21 Public License (GPL) along with this program; a copy of the GPL can also
22 be obtained by writing to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 U.S.A.
24 -----------------------------------------------------------------------------*/
25
26 //-----------------------------------------------------------------------------
27 // file: chuck_stats.h
28 // desc: statistics - for audicle
29 //
30 // author: Ge Wang ([email protected])
31 // Perry R. Cook ([email protected])
32 // Philip Davidson ([email protected])
33 // Ananya Misra ([email protected])
34 // date: Autumn 2004
35 //-----------------------------------------------------------------------------
36 #ifndef __CHUCK_STATS_H__
37 #define __CHUCK_STATS_H__
38
39 #include "chuck_def.h"
40
41 // tracking
42 #if defined(__CHUCK_STAT_TRACK__)
43
44 #include "util_thread.h"
45
46 #include <string>
47 #include <map>
48 #include <queue>
49
50
51 // forward reference
52 struct Chuck_VM;
53 struct Chuck_VM_Shred;
54 struct Shred_Data;
55 struct Shred_Time;
56
57
58
59
60 //-----------------------------------------------------------------------------
61 // name: struct Shred_Activation
62 // desc: ...
63 //-----------------------------------------------------------------------------
64 struct Shred_Activation
65 {
66 t_CKTIME when;
67 t_CKUINT cycles;
68
69 Shred_Activation( t_CKTIME a, t_CKUINT b ) { when = a; cycles = b; }
70 };
71
72
73
74
75 //-----------------------------------------------------------------------------
76 // name: struct Shred_Stat
77 // desc: ...
78 //-----------------------------------------------------------------------------
79 struct Shred_Stat
80 {
81 public:
82 // instructions computed
83 t_CKUINT cycles;
84 // shred id
85 t_CKUINT xid;
86 // parent
87 t_CKUINT parent;
88 // current state, 0 = inactive, 1 = active, 2 = wait, 3 = deleted
89 t_CKUINT state;
90 // reference (could be pointing to garbage - see state)
91 Chuck_VM_Shred * shred_ref;
92 // number of activations
93 t_CKUINT activations;
94 // average control rate
95 t_CKFLOAT average_ctrl;
96 // average cycles
97 t_CKFLOAT average_cycles;
98 // spork time
99 t_CKTIME spork_time;
100 // active time
101 t_CKTIME active_time;
102 // wake time
103 t_CKTIME wake_time;
104 // free time
105 t_CKTIME free_time;
106 // name
107 std::string name;
108 // owner
109 std::string owner;
110 // source
111 std::string source;
112
113 // ctrl rate calculation
114 std::queue<t_CKDUR> diffs;
115 // number of diffs
116 t_CKUINT num_diffs;
117 // total diffs
118 t_CKDUR diff_total;
119
120 // exe per activation
121 std::queue<t_CKUINT> act_cycles;
122 // total
123 t_CKUINT act_cycles_total;
124 // last
125 t_CKUINT last_cycles;
126
127 // children
128 std::vector<Shred_Stat *> children;
129 void get_sporked( std::vector<Shred_Stat *> & out );
130
131 std::vector<Shred_Activation> activationss;
132 void get_activations( std::vector<Shred_Activation> & out );
133
134 // mutex
135 XMutex mutex;
136
137 // audicle info
138 Shred_Data * data;
139 Shred_Time * time;
140
141 public:
142 Shred_Stat() { this->clear(); num_diffs = 8; data = NULL; time = NULL; }
143 void clear()
144 { xid = 0; parent = 0; state = 0; cycles = 0; activations = 0;
145 average_ctrl = 0.0; spork_time = 0.0; active_time = 0.0; wake_time = 0.0;
146 free_time = 0.0; name = "no name"; owner = "none"; source = "nowhere";
147 while( diffs.size() ) diffs.pop(); diff_total = 0.0;
148 while( act_cycles.size() ) act_cycles.pop(); act_cycles_total = 0;
149 last_cycles = 0; children.clear(); }
150 };
151
152
153
154
155 //-----------------------------------------------------------------------------
156 // name: struct Chuck_Stats
157 // desc: ...
158 //-----------------------------------------------------------------------------
159 struct Chuck_Stats
160 {
161 public:
162 static Chuck_Stats * instance();
163
164 public:
165 void set_vm_ref( Chuck_VM * _vm ) { vm = _vm; }
166
167 public:
168 void add_shred( Chuck_VM_Shred * shred );
169 void activate_shred( Chuck_VM_Shred * shred );
170 void advance_time( Chuck_VM_Shred * shred, t_CKTIME to );
171 void deactivate_shred( Chuck_VM_Shred * shred );
172 void remove_shred( Chuck_VM_Shred * shred );
173
174 public:
175 Shred_Stat * get_shred( t_CKUINT xid )
176 { mutex.acquire(); Shred_Stat * s = shreds[xid]; mutex.release(); return s; }
177 void get_shreds( std::vector<Shred_Stat *> & out,
178 std::map<Shred_Stat *, Shred_Stat *> & d );
179 static t_CKBOOL activations_yes;
180
181 protected:
182 Chuck_Stats();
183 ~Chuck_Stats();
184
185 static Chuck_Stats * our_instance;
186
187 protected:
188 Chuck_VM * vm;
189 std::map<t_CKUINT, Shred_Stat *> shreds;
190 std::vector<Shred_Stat *> done;
191 XMutex mutex;
192 };
193
194
195
196
197 #endif
198
199 #endif