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
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)
34 //-----------------------------------------------------------------------------
35 #ifndef __CHUCK_STATS_H__
36 #define __CHUCK_STATS_H__
38 #include "chuck_def.h"
41 #if defined(__CHUCK_STAT_TRACK__)
43 #include "util_thread.h"
52 struct Chuck_VM_Shred
;
59 //-----------------------------------------------------------------------------
60 // name: struct Shred_Activation
62 //-----------------------------------------------------------------------------
63 struct Shred_Activation
68 Shred_Activation( t_CKTIME a
, t_CKUINT b
) { when
= a
; cycles
= b
; }
74 //-----------------------------------------------------------------------------
75 // name: struct Shred_Stat
77 //-----------------------------------------------------------------------------
81 // instructions computed
87 // current state, 0 = inactive, 1 = active, 2 = wait, 3 = deleted
89 // reference (could be pointing to garbage - see state)
90 Chuck_VM_Shred
* shred_ref
;
91 // number of activations
93 // average control rate
94 t_CKFLOAT average_ctrl
;
96 t_CKFLOAT average_cycles
;
100 t_CKTIME active_time
;
112 // ctrl rate calculation
113 std::queue
<t_CKDUR
> diffs
;
119 // exe per activation
120 std::queue
<t_CKUINT
> act_cycles
;
122 t_CKUINT act_cycles_total
;
124 t_CKUINT last_cycles
;
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
);
141 Shred_Stat() { this->clear(); num_diffs
= 8; data
= NULL
; time
= NULL
; }
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
157 //-----------------------------------------------------------------------------
161 static Chuck_Stats
* instance();
164 void set_vm_ref( Chuck_VM
* _vm
) { vm
= _vm
; }
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
);
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
;
184 static Chuck_Stats
* our_instance
;
188 std::map
<t_CKUINT
, Shred_Stat
*> shreds
;
189 std::vector
<Shred_Stat
*> done
;