Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pstatclient/pStatProperties.cxx

Go to the documentation of this file.
00001 // Filename: pStatProperties.cxx
00002 // Created by:  drose (17May01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
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 // Initialized at 2.0 on 5/18/01, when version numbers were first added.
00029 // Incremented to 2.1 on 5/21/01 to add support for TCP frame data.
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: get_current_pstat_major_version
00033 //  Description: Returns the current major version number of the
00034 //               PStats protocol.  This is the version number that
00035 //               will be reported by clients running this code, and
00036 //               that will be expected by servers running this code.
00037 //
00038 //               The major version numbers must match exactly in order
00039 //               for a communication to be successful.
00040 ////////////////////////////////////////////////////////////////////
00041 int
00042 get_current_pstat_major_version() {
00043   return current_pstat_major_version;
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: get_current_pstat_minor_version
00048 //  Description: Returns the current minor version number of the
00049 //               PStats protocol.  This is the version number that
00050 //               will be reported by clients running this code, and
00051 //               that will be expected by servers running this code.
00052 //
00053 //               The minor version numbers need not match exactly, but
00054 //               the server must be >= the client.
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 // The rest of this file defines the predefined properties (color,
00067 // sort, etc.) for the various PStatCollectors that may be defined
00068 // within Panda or even elsewhere.
00069 //
00070 // It is a little strange to defined these properties here instead of
00071 // where the collectors are actually declared, but it's handy to have
00072 // them all in one place, so we can easily see which colors are
00073 // available, etc.  It also makes the declarations a lot simpler,
00074 // since there are quite a few esoteric parameters to specify.
00075 //
00076 // We could define these in some external data file that is read in at
00077 // runtime, so that you could extend this list without having to
00078 // relink panda, but then there are the usual problems with ensuring
00079 // that the file is available to you at runtime.  The heck with it.
00080 //
00081 // At least, no other file depends on this file, so it may be modified
00082 // without forcing anything else to be recompiled.
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 //     Function: initialize_collector_def_from_table
00182 //  Description: Looks up the collector in the compiled-in table
00183 //               defined above, and sets its properties appropriately
00184 //               if it is found.
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 //     Function: initialize_collector_def
00234 //  Description: This is the only accessor function into this table.
00235 //               The PStatCollectorDef constructor calls it when a new
00236 //               PStatCollectorDef is created.  It should look up in
00237 //               the table and find a matching definition for this def
00238 //               by name; if one is found, the properties are applied.
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   // First, check the compiled-in defaults.
00251   initialize_collector_def_from_table(fullname, def);
00252 
00253   // Then, look to Config for more advice.  To do this, we first
00254   // change the name to something more like a Config variable name.
00255   // We replace colons and spaces with hyphens, eliminate other
00256   // punctuation, and make all letters lowercase.
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   // Get and decode the color string.  We allow any three
00297   // floating-point numbers, with any kind of non-digit characters
00298   // between them.
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

Generated on Fri May 2 00:43:28 2003 for Panda by doxygen1.3