| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#ifndef __CHUCK_STATS_H__ |
| 37 |
#define __CHUCK_STATS_H__ |
| 38 |
|
| 39 |
#include "chuck_def.h" |
| 40 |
|
| 41 |
|
| 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 |
|
| 52 |
struct Chuck_VM; |
| 53 |
struct Chuck_VM_Shred; |
| 54 |
struct Shred_Data; |
| 55 |
struct Shred_Time; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 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 |
|
| 77 |
|
| 78 |
|
| 79 |
struct Shred_Stat |
| 80 |
{ |
| 81 |
public: |
| 82 |
|
| 83 |
t_CKUINT cycles; |
| 84 |
|
| 85 |
t_CKUINT xid; |
| 86 |
|
| 87 |
t_CKUINT parent; |
| 88 |
|
| 89 |
t_CKUINT state; |
| 90 |
|
| 91 |
Chuck_VM_Shred * shred_ref; |
| 92 |
|
| 93 |
t_CKUINT activations; |
| 94 |
|
| 95 |
t_CKFLOAT average_ctrl; |
| 96 |
|
| 97 |
t_CKFLOAT average_cycles; |
| 98 |
|
| 99 |
t_CKTIME spork_time; |
| 100 |
|
| 101 |
t_CKTIME active_time; |
| 102 |
|
| 103 |
t_CKTIME wake_time; |
| 104 |
|
| 105 |
t_CKTIME free_time; |
| 106 |
|
| 107 |
std::string name; |
| 108 |
|
| 109 |
std::string owner; |
| 110 |
|
| 111 |
std::string source; |
| 112 |
|
| 113 |
|
| 114 |
std::queue<t_CKDUR> diffs; |
| 115 |
|
| 116 |
t_CKUINT num_diffs; |
| 117 |
|
| 118 |
t_CKDUR diff_total; |
| 119 |
|
| 120 |
|
| 121 |
std::queue<t_CKUINT> act_cycles; |
| 122 |
|
| 123 |
t_CKUINT act_cycles_total; |
| 124 |
|
| 125 |
t_CKUINT last_cycles; |
| 126 |
|
| 127 |
|
| 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 |
|
| 135 |
XMutex mutex; |
| 136 |
|
| 137 |
|
| 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 |
|
| 157 |
|
| 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 |