00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pStatProperties.h"
00020 #include "pStatCollectorDef.h"
00021 #include "pStatClient.h"
00022 #include "config_pstats.h"
00023
00024 #include <ctype.h>
00025
00026 static const int current_pstat_major_version = 2;
00027 static const int current_pstat_minor_version = 1;
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 int
00042 get_current_pstat_major_version() {
00043 return current_pstat_major_version;
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 int
00057 get_current_pstat_minor_version() {
00058 return current_pstat_minor_version;
00059 }
00060
00061
00062 #ifdef DO_PSTATS
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 struct ColorDef {
00087 float r, g, b;
00088 };
00089
00090 struct TimeCollectorProperties {
00091 bool is_active;
00092 const char *name;
00093 ColorDef color;
00094 float suggested_scale;
00095 };
00096
00097 struct LevelCollectorProperties {
00098 bool is_active;
00099 const char *name;
00100 ColorDef color;
00101 const char *units;
00102 float suggested_scale;
00103 float inv_factor;
00104 };
00105
00106 static TimeCollectorProperties time_properties[] = {
00107 { 1, "Swap buffers", { 0.5, 1.0, 0.8 } },
00108 { 1, "App", { 0.0, 0.8, 0.4 }, 1.0 / 30.0 },
00109 { 1, "App:Animation", { 1.0, 0.0, 1.0 } },
00110 { 1, "App:Collisions", { 1.0, 0.5, 0.0 } },
00111 { 0, "App:Data graph", { 0.5, 0.8, 0.4 } },
00112 { 1, "App:Show code", { 0.8, 0.2, 1.0 } },
00113 { 0, "App:Show code:Nametags", { 0.8, 0.8, 1.0 } },
00114 { 0, "App:Show code:Nametags:2d", { 0.0, 0.0, 0.5 } },
00115 { 0, "App:Show code:Nametags:2d:Contents", { 0.0, 0.5, 0.0 } },
00116 { 0, "App:Show code:Nametags:2d:Adjust", { 0.5, 0.0, 0.5 } },
00117 { 0, "App:Show code:Nametags:3d", { 1.0, 0.0, 0.0 } },
00118 { 0, "App:Show code:Nametags:3d:Contents", { 0.0, 0.5, 0.0 } },
00119 { 0, "App:Show code:Nametags:3d:Adjust", { 0.5, 0.0, 0.5 } },
00120 { 1, "Cull", { 0.0, 1.0, 0.0 }, 1.0 / 30.0 },
00121 { 0, "Cull:Traverse", { 0.0, 1.0, 1.0 } },
00122 { 0, "Cull:Geom node", { 1.0, 0.0, 1.0 } },
00123 { 0, "Cull:Direct node", { 1.0, 0.5, 0.0 } },
00124 { 0, "Cull:Apply initial", { 0.2, 1.0, 0.8 } },
00125 { 0, "Cull:Draw", { 1.0, 1.0, 0.0 } },
00126 { 0, "Cull:Clean", { 0.0, 0.0, 1.0 } },
00127 { 0, "Cull:Bins", { 0.8, 1.0, 0.8 } },
00128 { 0, "Cull:Bins:BTF", { 1.0, 0.5, 0.5 } },
00129 { 0, "Cull:Bins:Unsorted", { 0.5, 0.5, 1.0 } },
00130 { 0, "Cull:Bins:Fixed", { 0.5, 1.0, 0.5 } },
00131 { 1, "Draw", { 1.0, 0.0, 0.0 }, 1.0 / 30.0 },
00132 { 0, "Draw:Primitive", { 0.0, 0.0, 0.5 } },
00133 { 0, "Draw:Set state", { 0.5, 0.0, 0.0 } },
00134 { 1, "Draw:Quick", { 1.0, 0.0, 0.8 } },
00135 { 1, "Draw:Direct", { 0.0, 0.4, 1.0 } },
00136 { 1, "Draw:Cull", { 0.4, 1.0, 0.0 } },
00137 { 0, "Draw:Clear", { 0.5, 0.7, 0.7 } },
00138 { 0, "Draw:Show fps", { 0.5, 0.8, 1.0 } },
00139 { 0, "Draw:Make current", { 1.0, 0.6, 0.3 } },
00140 { 0, "WRT", { 0.0, 0.0, 1.0 } },
00141 { 0, "WRT:Subtree", { 0.3, 1.0, 0.3 } },
00142 { 0, NULL }
00143 };
00144
00145 static LevelCollectorProperties level_properties[] = {
00146 { 1, "Texture usage", { 1.0, 0.0, 0.5 }, "MB", 12, 1048576 },
00147 { 1, "Texture usage:Active", { 0.5, 1.0, 0.8 } },
00148 { 1, "Texture memory", { 0.0, 0.0, 1.0 }, "MB", 12, 1048576 },
00149 { 1, "Texture memory:In use", { 0.0, 1.0, 1.0 } },
00150 { 1, "Texture manager", { 1.0, 0.0, 0.0 }, "MB", 12, 1048576 },
00151 { 1, "Texture manager:Resident", { 1.0, 1.0, 0.0 } },
00152 { 1, "Prepared Geoms", { 1.0, 0.0, 0.5 }, "", 500 },
00153 { 1, "Prepared Geoms:Active", { 0.5, 1.0, 0.8 } },
00154 { 1, "Prepared GeomNodes", { 1.0, 0.0, 0.5 }, "", 500 },
00155 { 1, "Prepared GeomNodes:Active", { 0.5, 1.0, 0.8 } },
00156 { 1, "Vertices", { 0.5, 0.2, 0.0 }, "K", 10, 1000 },
00157 { 1, "Vertices:Other", { 0.2, 0.2, 0.2 } },
00158 { 1, "Vertices:Triangles", { 0.8, 0.8, 0.8 } },
00159 { 1, "Vertices:Triangle fans", { 0.8, 0.5, 0.2 } },
00160 { 1, "Vertices:Triangle strips", { 0.2, 0.5, 0.8 } },
00161 { 1, "Vertices:Display lists", { 0.8, 0.5, 1.0 } },
00162 { 1, "Nodes", { 0.4, 0.2, 0.8 }, "", 500.0 },
00163 { 1, "Nodes:GeomNodes", { 0.8, 0.2, 0.0 } },
00164 { 1, "Cull volumes", { 0.7, 0.6, 0.9 }, "", 500.0 },
00165 { 1, "Cull volumes:Transforms", { 0.9, 0.6, 0.0 } },
00166 { 1, "State changes", { 1.0, 0.5, 0.2 }, "", 500.0 },
00167 { 1, "State changes:Transforms", { 0.2, 0.2, 0.8 } },
00168 { 1, "State changes:Textures", { 0.8, 0.2, 0.2 } },
00169 { 1, "Memory usage", { 0.5, 1.0, 0.5 }, "MB", 64, 1048576 },
00170 { 1, "Memory usage:C++", { 0.2, 0.2, 1.0 } },
00171 { 1, "Memory usage:Interpreter", { 0.8, 0.2, 0.5 } },
00172 { 1, "TransformStates", { 1.0, 0.5, 0.5 }, "", 5000 },
00173 { 1, "TransformStates:Unused", { 0.2, 0.2, 0.2 } },
00174 { 1, "RenderStates", { 0.5, 0.5, 1.0 }, "", 1000 },
00175 { 1, "RenderStates:Unused", { 0.2, 0.2, 0.2 } },
00176 { 0, NULL }
00177 };
00178
00179
00180
00181
00182
00183
00184
00185
00186 static void
00187 initialize_collector_def_from_table(const string &fullname, PStatCollectorDef *def) {
00188 int i;
00189
00190 for (i = 0;
00191 time_properties[i].name != (const char *)NULL;
00192 i++) {
00193 const TimeCollectorProperties &tp = time_properties[i];
00194 if (fullname == tp.name) {
00195 def->_sort = i;
00196 if (!def->_active_explicitly_set) {
00197 def->_is_active = tp.is_active;
00198 }
00199 def->_suggested_color.set(tp.color.r, tp.color.g, tp.color.b);
00200 if (tp.suggested_scale != 0.0) {
00201 def->_suggested_scale = tp.suggested_scale;
00202 }
00203 return;
00204 }
00205 }
00206
00207 for (i = 0;
00208 level_properties[i].name != (const char *)NULL;
00209 i++) {
00210 const LevelCollectorProperties &lp = level_properties[i];
00211 if (fullname == lp.name) {
00212 def->_sort = i;
00213 if (!def->_active_explicitly_set) {
00214 def->_is_active = lp.is_active;
00215 }
00216 def->_suggested_color.set(lp.color.r, lp.color.g, lp.color.b);
00217 if (lp.suggested_scale != 0.0) {
00218 def->_suggested_scale = lp.suggested_scale;
00219 }
00220 if (lp.units != (const char *)NULL) {
00221 def->_level_units = lp.units;
00222 }
00223 if (lp.inv_factor != 0.0) {
00224 def->_factor = 1.0 / lp.inv_factor;
00225 }
00226 return;
00227 }
00228 }
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 void
00241 initialize_collector_def(PStatClient *client, PStatCollectorDef *def) {
00242 string fullname;
00243
00244 if (def->_index == 0) {
00245 fullname = def->_name;
00246 } else {
00247 fullname = client->get_collector_fullname(def->_index);
00248 }
00249
00250
00251 initialize_collector_def_from_table(fullname, def);
00252
00253
00254
00255
00256
00257
00258 string config_name;
00259 string::const_iterator ni;
00260 for (ni = fullname.begin(); ni != fullname.end(); ++ni) {
00261 switch (*ni) {
00262 case ':':
00263 case ' ':
00264 case '\n':
00265 case '\r':
00266 case '\t':
00267 config_name += '-';
00268 break;
00269
00270 default:
00271 if (isalnum(*ni)) {
00272 config_name += tolower(*ni);
00273 }
00274 }
00275 }
00276
00277 if (!config_pstats.GetString("pstats-active-" + config_name, "").empty()) {
00278 def->_is_active =
00279 config_pstats.GetBool("pstats-active-" + config_name, true);
00280 def->_active_explicitly_set = true;
00281 }
00282
00283 def->_sort =
00284 config_pstats.GetInt("pstats-sort-" + config_name, def->_sort);
00285 def->_suggested_scale =
00286 config_pstats.GetFloat("pstats-scale-" + config_name, def->_suggested_scale);
00287 def->_level_units =
00288 config_pstats.GetString("pstats-units-" + config_name, def->_level_units);
00289 def->_level_units =
00290 config_pstats.GetString("pstats-units-" + config_name, def->_level_units);
00291 if (!config_pstats.GetString("pstats-factor-" + config_name, "").empty()) {
00292 def->_factor =
00293 1.0/config_pstats.GetFloat("pstats-factor-" + config_name, 1.0);
00294 }
00295
00296
00297
00298
00299 string color_str =
00300 config_pstats.GetString("pstats-color-" + config_name, "");
00301 if (!color_str.empty()) {
00302 const char *cstr = color_str.c_str();
00303 const char *p = cstr;
00304
00305 int i = 0;
00306 while (i < 3 && *p != '\0') {
00307 while (*p != '\0' && !(isdigit(*p) || *p == '.')) {
00308 p++;
00309 }
00310 char *q;
00311 def->_suggested_color[i] = strtod(p, &q);
00312 p = q;
00313 i++;
00314 }
00315 }
00316 }
00317
00318 #endif // DO_PSTATS