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