From: Keith F. <ven...@us...> - 2005-01-09 00:33:43
|
Update of /cvsroot/planeshift/planeshift/src/common/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21961 Modified Files: psstring.h psstring.cpp psprofile.h psprofile.cpp dbprofile.h dbprofile.cpp Log Message: Refactored sql string handling and clarified some member names. Index: psstring.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/util/psstring.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** psstring.h 14 Oct 2004 23:39:25 -0000 1.10 --- psstring.h 9 Jan 2005 00:33:27 -0000 1.11 *************** *** 39,42 **** --- 39,44 ---- int FindSubStringReverse(psString& sub, size_t start, bool caseInsense=XML_CASE_SENSITIVE); void GetSubString(psString& str, size_t from, size_t to); + bool FindNumber(int & pos, int & end); + bool FindString(const char *border, int & pos, int & end); enum Index: psstring.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/util/psstring.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** psstring.cpp 14 Oct 2004 23:39:25 -0000 1.12 --- psstring.cpp 9 Jan 2005 00:33:33 -0000 1.13 *************** *** 19,22 **** --- 19,54 ---- } + bool psString::FindString(const char *border, int & pos, int & end) + { + pos = FindSubString(border, pos); + if (pos == -1) + return false; + + end = pos + strlen(border); + end = FindSubString(border, end); + if (end == -1) + return false; + + return true; + } + + bool psString::FindNumber(int & pos, int & end) + { + while (pos < (int) Length() && !isdigit(Data[pos])) + pos++; + + if (pos < (int) Length()) + { + end = pos; + while (end< (int) Length() && isdigit(Data[end])) + end++; + end--; + return true; + } + else + return false; + } + + int psString::FindSubString(const char *sub, size_t start, bool caseInsense) { Index: psprofile.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/util/psprofile.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** psprofile.h 8 Jan 2005 22:00:33 -0000 1.2 --- psprofile.h 9 Jan 2005 00:33:33 -0000 1.3 *************** *** 29,40 **** public: psOperProfile(const csString & desc); ! void AddCons(double cons); void Reset(); ! csString Dump(double totalCons, const csString & unitName); ! double GetCons(); protected: ! csString desc; // textual description ! double count; // number of operations of this kind that took place ! double cons ; // total resource consumption by this kind of operation double maxCons; // the maximum resource consumption per operation // that we witnessed --- 29,42 ---- public: psOperProfile(const csString & desc); ! void AddConsumption(double cons); void Reset(); ! csString Dump(double totalConsumption, const csString & unitName); ! double GetConsumption(); ! static int cmpProfs(const void * a, const void * b); ! protected: ! csString desc; /// textual description ! double count; /// number of operations of this kind that took place ! double consumption ; /// total resource consumption by this kind of operation double maxCons; // the maximum resource consumption per operation // that we witnessed *************** *** 46,53 **** */ ! class psOperProfiles { public: ! psOperProfiles(); void Dump(const csString & unitName, csString & header, csString & list); void Reset(); --- 48,55 ---- */ ! class psOperProfileSet { public: ! psOperProfileSet(); void Dump(const csString & unitName, csString & header, csString & list); void Reset(); *************** *** 65,69 **** void Start(); /** Measure the time interval from marked start (in msec) */ ! unsigned Stop(); protected: csTicks start; --- 67,71 ---- void Start(); /** Measure the time interval from marked start (in msec) */ ! csTicks Stop(); protected: csTicks start; Index: psprofile.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/util/psprofile.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** psprofile.cpp 8 Jan 2005 22:00:33 -0000 1.3 --- psprofile.cpp 9 Jan 2005 00:33:33 -0000 1.4 *************** *** 45,64 **** } ! void psOperProfile::AddCons(double cons) { count ++; ! this->cons += cons; if (cons > maxCons) maxCons = cons; } ! csString psOperProfile::Dump(double totalCons, const csString & unitName) { ! int perc = (int)floor(cons/totalCons*100); if (perc > 0) return csString().Format( ! "Name=%s perc=%i %s=%i count=%u avg-%s=%f max=%f\n", ! desc.GetData(), perc, unitName.GetData(), int(cons), ! unsigned(count), unitName.GetData(), cons/count, maxCons); else return ""; --- 45,64 ---- } ! void psOperProfile::AddConsumption(double cons) { count ++; ! consumption += cons; if (cons > maxCons) maxCons = cons; } ! csString psOperProfile::Dump(double totalConsumption, const csString & unitName) { ! int perc = (int)floor(consumption/totalConsumption*100); if (perc > 0) return csString().Format( ! "count=%u perc=%i%% %s=%i avg-%s=%f max=%f Name=%s\n", ! unsigned(count), perc, unitName.GetData(), int(consumption), ! unitName.GetData(), consumption/count, maxCons, desc.GetData()); else return ""; *************** *** 67,87 **** void psOperProfile::Reset() { ! count = 0; ! cons = 0; maxCons = 0; } ! double psOperProfile::GetCons() { ! return cons; } ! int cmpProfs(const void * a, const void * b) { psOperProfile * pA = *((psOperProfile**)a); psOperProfile * pB = *((psOperProfile**)b); ! if (pA->GetCons() > pB->GetCons()) return -1; ! if (pA->GetCons() == pB->GetCons()) return 0; else --- 67,87 ---- void psOperProfile::Reset() { ! count = 0; ! consumption = 0; maxCons = 0; } ! double psOperProfile::GetConsumption() { ! return consumption; } ! int psOperProfile::cmpProfs(const void * a, const void * b) { psOperProfile * pA = *((psOperProfile**)a); psOperProfile * pB = *((psOperProfile**)b); ! if (pA->GetConsumption() > pB->GetConsumption()) return -1; ! if (pA->GetConsumption() == pB->GetConsumption()) return 0; else *************** *** 95,104 **** ****************************************************************/ ! psOperProfiles::psOperProfiles() { profStart = csGetTicks(); } ! void psOperProfiles::Dump(const csString & unitName, csString & header, csString & list) { double totalCons=0; --- 95,104 ---- ****************************************************************/ ! psOperProfileSet::psOperProfileSet() { profStart = csGetTicks(); } ! void psOperProfileSet::Dump(const csString & unitName, csString & header, csString & list) { double totalCons=0; *************** *** 108,112 **** for (i=0; i < profs.Length(); i++) ! totalCons += profs[i]->GetCons(); time = double(csGetTicks()) - double(profStart); --- 108,112 ---- for (i=0; i < profs.Length(); i++) ! totalCons += profs[i]->GetConsumption(); time = double(csGetTicks()) - double(profStart); *************** *** 122,126 **** for (i=0; i < profs.Length(); i++) sortedProfs[i] = profs[i]; ! qsort(sortedProfs, profs.Length(), sizeof(psOperProfile*), cmpProfs); for (i=0; i < profs.Length(); i++) list += sortedProfs[i]->Dump(totalCons, unitName); --- 122,126 ---- for (i=0; i < profs.Length(); i++) sortedProfs[i] = profs[i]; ! qsort(sortedProfs, profs.Length(), sizeof(psOperProfile*), psOperProfile::cmpProfs); for (i=0; i < profs.Length(); i++) list += sortedProfs[i]->Dump(totalCons, unitName); *************** *** 128,132 **** } ! void psOperProfiles::Reset() { profStart = csGetTicks(); --- 128,132 ---- } ! void psOperProfileSet::Reset() { profStart = csGetTicks(); Index: dbprofile.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/util/dbprofile.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dbprofile.h 7 Jan 2005 20:10:44 -0000 1.1 --- dbprofile.h 9 Jan 2005 00:33:33 -0000 1.2 *************** *** 26,37 **** #include "util/psprofile.h" /** Statistics of time consumed by SQL statements */ ! class psDBProfiles : public psOperProfiles { public: void AddSQLTime(const csString & sql, double time); csString Dump(); void Reset(); protected: csHash<psOperProfile*, csString, csConstCharHashKeyHandler> sqlProfs; }; --- 26,44 ---- #include "util/psprofile.h" + class psString; + /** Statistics of time consumed by SQL statements */ ! class psDBProfiles : public psOperProfileSet { public: + void AddSQLTime(const csString & sql, double time); csString Dump(); void Reset(); + protected: + + void StripConstantsFromSQL(psString & sql); + csHash<psOperProfile*, csString, csConstCharHashKeyHandler> sqlProfs; }; Index: dbprofile.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/util/dbprofile.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dbprofile.cpp 7 Jan 2005 20:10:44 -0000 1.1 --- dbprofile.cpp 9 Jan 2005 00:33:33 -0000 1.2 *************** *** 19,76 **** #include <psconfig.h> #include "dbprofile.h" #include "util/log.h" - bool FindString(const csString & sql, const csString & border, int & pos, int & end) - { - assert(border.Length() == 1); - while (pos<sql.Length() && sql.GetAt(pos)!=border.GetAt(0)) - pos++; - - if (pos+1 < sql.Length()) - { - end = pos+1; - while (end<sql.Length()) - { - if (sql.GetAt(end) == border.GetAt(0)) - { - if (end+1<sql.Length() && sql.GetAt(end+1)==border.GetAt(0)) - end += 2; - else - return true; - } - else - end ++; - } - return false; - } - else - return false; - } - - bool FindNumber(const csString & sql, int & pos, int & end) - { - while (pos<sql.Length() && !isdigit(sql.GetAt(pos))) - pos++; - if (pos < sql.Length()) - { - end = pos; - while (end<sql.Length() && isdigit(sql.GetAt(end))) - end++; - end--; - return true; - } - else - return false; - } - // Removes all constants from given SQL - i.e. strings and numbers // The purpose is to get rid of "details", so that get "essence" of the SQL ! void StripConstantsFromSQL(csString & sql) { int pos, end; pos = 0; ! while (FindNumber(sql, pos, end)) { sql.DeleteAt(pos, end-pos+1); --- 19,34 ---- #include <psconfig.h> + #include "util/psstring.h" #include "dbprofile.h" #include "util/log.h" // Removes all constants from given SQL - i.e. strings and numbers // The purpose is to get rid of "details", so that get "essence" of the SQL ! void psDBProfiles::StripConstantsFromSQL(psString & sql) { int pos, end; pos = 0; ! while (sql.FindNumber(pos, end)) { sql.DeleteAt(pos, end-pos+1); *************** *** 79,83 **** pos = 0; ! while (FindString(sql, "\"", pos, end)) { sql.DeleteAt(pos, end-pos+1); --- 37,41 ---- pos = 0; ! while (sql.FindString("\"", pos, end)) { sql.DeleteAt(pos, end-pos+1); *************** *** 86,90 **** pos = 0; ! while (FindString(sql, "\'", pos, end)) { sql.DeleteAt(pos, end-pos+1); --- 44,48 ---- pos = 0; ! while (sql.FindString("\'", pos, end)) { sql.DeleteAt(pos, end-pos+1); *************** *** 95,99 **** void psDBProfiles::AddSQLTime(const csString & sql, double time) { ! csString strippedSQL; strippedSQL = sql; --- 53,57 ---- void psDBProfiles::AddSQLTime(const csString & sql, double time) { ! psString strippedSQL; strippedSQL = sql; *************** *** 107,111 **** prof = sqlProfs.GetElementPointer(strippedSQL); assert(prof); ! (*prof)->AddCons(time); } else --- 65,69 ---- prof = sqlProfs.GetElementPointer(strippedSQL); assert(prof); ! (*prof)->AddConsumption(time); } else *************** *** 114,118 **** sqlProfs.Put(strippedSQL, newProf); profs.Push(newProf); ! newProf->AddCons(time); } } --- 72,76 ---- sqlProfs.Put(strippedSQL, newProf); profs.Push(newProf); ! newProf->AddConsumption(time); } } *************** *** 122,126 **** csString header, list; ! psOperProfiles::Dump("msec", header, list); return "=================\nDatabase profile\n=================\n" + header + list; } --- 80,84 ---- csString header, list; ! psOperProfileSet::Dump("msec", header, list); return "=================\nDatabase profile\n=================\n" + header + list; } *************** *** 129,132 **** { sqlProfs.DeleteAll(); ! psOperProfiles::Reset(); } --- 87,90 ---- { sqlProfs.DeleteAll(); ! psOperProfileSet::Reset(); } |