00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __GTXabsl2Profiler_h_
00009 #define __GTXabsl2Profiler_h_
00010
00011 #ifdef _WIN32
00012 #pragma warning(disable:4786)
00013
00014
00015 #endif
00016
00017 #include <string>
00018 #include <vector>
00019 #include <deque>
00020
00021 #include "Platform/GTAssert.h"
00022
00023 #include "Tools/Streams/OutStreams.h"
00024 #include "Platform/SystemCall.h"
00025
00026 #include "Tools/Xabsl2/Xabsl2Engine/Xabsl2Array.h"
00027 #include "Tools/Xabsl2/Xabsl2Engine/Xabsl2Engine.h"
00028 #include "Tools/Debugging/Debugging.h"
00029
00030 #include "Tools/Streams/InStreams.h"
00031 #include "Tools/Module/SolutionRequest.h"
00032
00033
00034 #define NROFELEMW 2
00035
00036
00037
00038
00039
00040
00041 class GTXabsl2ProfilerNameTableEntry{
00042 public:
00043
00044 std::string optionName;
00045
00046 std::vector<std::string> states;
00047
00048 std::vector<std::string> parameters;
00049
00050 int maxdepth;
00051
00052
00053
00054
00055
00056 GTXabsl2ProfilerNameTableEntry(){};
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 GTXabsl2ProfilerNameTableEntry(const std::string option,std::vector<std::string> state, std::vector<std::string> params, const int depth)
00067 : optionName(option), states(state), parameters(params), maxdepth(depth){}
00068 };
00069
00070
00071
00072
00073
00074
00075 class GTXabsl2ProfilerNameTable
00076 {
00077
00078 GTXabsl2ProfilerNameTableEntry* data;
00079
00080
00081
00082 int usedSize, length;
00083 public:
00084
00085
00086
00087 GTXabsl2ProfilerNameTable():usedSize(0), length(0), data(NULL)
00088 {}
00089
00090
00091
00092
00093 ~GTXabsl2ProfilerNameTable()
00094 {
00095 if(data)
00096 delete[] data;
00097 }
00098
00099
00100
00101
00102 void init(int length_){
00103 if(data){
00104 delete[] data; data = NULL;
00105 }
00106 usedSize = 0;
00107 length = length_;
00108 data = new GTXabsl2ProfilerNameTableEntry[length];
00109 }
00110
00111
00112 void clear()
00113 {
00114 if(data){
00115 delete[] data;
00116 usedSize = 0;
00117 data = new GTXabsl2ProfilerNameTableEntry[length];
00118 }
00119
00120 }
00121
00122
00123
00124
00125
00126 int getOptionPosition(const std::string optionName) const
00127 {
00128 return findOption(optionName);
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138 int getStatePosition(const std::string optionName, const std::string state){
00139 return findState(optionName, state);
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149 void append(const std::string optionName, const std::vector<std::string> states, const std::vector<std::string> params, int depth)
00150 {
00151 if(usedSize == length)
00152 {
00153 length += length > 1 ? length / 2 : 2;
00154
00155 GTXabsl2ProfilerNameTableEntry* temp = new GTXabsl2ProfilerNameTableEntry[length];
00156 if(data){
00157 for(int i = 0; i < getSize(); ++i)
00158 temp[i] = data[i];
00159 delete[] data;
00160 }
00161 data = temp;
00162 }
00163 data[usedSize++]=GTXabsl2ProfilerNameTableEntry(optionName, states, params, depth);
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173 void setElement(int pos, GTXabsl2ProfilerNameTableEntry value)
00174 {
00175 data[pos] = value;
00176 }
00177
00178
00179
00180
00181
00182 int getSize() const {return usedSize;}
00183
00184
00185
00186
00187
00188
00189 GTXabsl2ProfilerNameTableEntry& operator[](int pos) const
00190 {
00191 return data[pos];
00192 }
00193
00194
00195
00196
00197
00198 bool exists(const std::string optionName, const std::string stateName) const
00199 {
00200 return find(optionName, stateName) >= 0;
00201 }
00202
00203
00204
00205
00206 bool existsOption(const std::string option){
00207 return findOption(option) >=0;
00208 }
00209
00210 protected:
00211
00212
00213
00214
00215 int find(const std::string optionName, const std::string state) const
00216 {
00217 for(int i = 0; i < getSize(); ++i){
00218
00219 if(data[i].optionName == optionName){
00220 for(std::vector<std::string>::iterator j = data[i].states.begin(); j != data[i].states.end(); ++j){
00221 if((*j) == state)
00222 return i;
00223 }
00224
00225 }
00226 }
00227 return -1;
00228 }
00229
00230
00231
00232
00233
00234 int findState(const std::string optionName, const std::string state) const
00235 {
00236 for(int i = 0; i < getSize(); ++i){
00237
00238 if(data[i].optionName == optionName){
00239 for(int j = 0; j < (int) data[i].states.size(); ++j){
00240 if(state == data[i].states[j])
00241 return j;
00242 }
00243
00244 }
00245 }
00246 return -1;
00247 }
00248
00249
00250
00251
00252
00253 int findOption(const std::string optionName) const
00254 {
00255 for(int i = 0; i < getSize(); ++i)
00256 if(data[i].optionName == optionName)
00257 return i;
00258 return -1;
00259 }
00260 };
00261
00262
00263
00264
00265
00266
00267 class GTXabsl2ActiveOption{
00268 public:
00269
00270 int optionNumber;
00271
00272
00273 int stateNumber;
00274
00275
00276 std::vector<double> parameters;
00277
00278
00279
00280
00281
00282 GTXabsl2ActiveOption(): optionNumber(-1), stateNumber(-1){}
00283
00284
00285
00286
00287
00288 GTXabsl2ActiveOption(int o, int st, std::vector<double> p): optionNumber(o), stateNumber(st), parameters(p){}
00289
00290
00291
00292
00293 bool operator ==(const GTXabsl2ActiveOption other)const
00294 {
00295 if(this->optionNumber == other.optionNumber && this->stateNumber == other.stateNumber
00296 && this->parameters == other.parameters)
00297 return true;
00298 return false;
00299 }
00300 };
00301
00302
00303
00304
00305
00306
00307 class GTXabsl2LogEntry{
00308 public:
00309
00310 unsigned long framenumber;
00311
00312
00313 std::vector<GTXabsl2ActiveOption> activeOptions;
00314
00315
00316
00317
00318 GTXabsl2LogEntry(unsigned long fn, std::vector<GTXabsl2ActiveOption> aO):framenumber(fn), activeOptions(aO){}
00319 GTXabsl2LogEntry(unsigned long fn):framenumber(fn){}
00320 };
00321
00322
00323
00324
00325
00326
00327 class GTXabsl2Profiler
00328 {
00329 private:
00330
00331
00332 GTXabsl2ProfilerNameTable nameTable;
00333
00334
00335 std::deque<GTXabsl2LogEntry> log;
00336
00337
00338 std::string outFileName;
00339
00340
00341 int maxDepth;
00342
00343
00344
00345
00346
00347
00348
00349 void registerOptions(const Xabsl2Option* option, int depth);
00350
00351
00352
00353
00354 void doDepthCount(const Xabsl2Option* option, int depth);
00355
00356
00357
00358
00359 void writeLogToStream(Out&);
00360
00361
00362
00363
00364 void writeCompleteLogToStream(Out&);
00365
00366
00367
00368
00369 void writeNameTableToStream(Out&);
00370
00371
00372 const unsigned long* frameNumber;
00373
00374 public:
00375
00376 enum { dontCollectProfiles, collectProfiles} profilerCollectMode;
00377 enum { dontWriteProfiles, writeProfiles, writeCompleteProfiles} profilerWriteMode;
00378
00379
00380
00381
00382 void registerSymbols(Xabsl2Engine&);
00383
00384 GTXabsl2Profiler();
00385
00386
00387
00388
00389 GTXabsl2Profiler(SolutionRequest::xabsl2EngineID id,
00390 const unsigned long* frameNumber);
00391
00392
00393
00394
00395
00396
00397 void init(Xabsl2Engine& pEngine,int length =1);
00398
00399
00400
00401
00402
00403 void doProfiling(Xabsl2Engine& pEngine);
00404
00405
00406
00407
00408 void recordCollectedLogs();
00409
00410
00411
00412
00413 void recordCompleteLog();
00414
00415
00416
00417
00418 void writeXMLtoStream(Out& out);
00419
00420
00421
00422
00423 void exportXMLFile(const char* outf);
00424
00425
00426
00427
00428
00429 bool importLogFile(const char* filename);
00430
00431
00432
00433
00434
00435
00436 std::vector<GTXabsl2ActiveOption> getActiveOptionsAtFrame(int time);
00437
00438
00439
00440
00441
00442 std::string getOptionName(int optionNumber);
00443
00444
00445
00446
00447 std::string getStateName(int optionNumber, int stateNumber);
00448
00449
00450
00451
00452 int getDepth(char* optionName);
00453
00454
00455
00456
00457 int getDepth(int optionNumber);
00458
00459
00460
00461
00462 int getMaxDepth(){ return maxDepth; }
00463
00464
00465
00466
00467 int getBeginningFramenumber(){ return log.size()?log.front().framenumber:0; }
00468
00469
00470
00471
00472
00473 int getLastFramenumber(){ return log.size()?log.back().framenumber:0;}
00474
00475
00476
00477
00478 int getNumberofLogEntries();
00479
00480
00481
00482
00483 std::vector<GTXabsl2ActiveOption> getActiveOptionsAtNumber(int frameNumber);
00484
00485
00486
00487
00488
00489 GTXabsl2LogEntry getLogEntryAtIndex(int index);
00490
00491
00492
00493
00494 int getFollowingFramenumber(int frame);
00495
00496
00497
00498
00499 int getIndex(int frameNumber);
00500
00501
00502
00503
00504
00505 GTXabsl2LogEntry& operator[](int i);
00506
00507
00508
00509
00510 int size();
00511
00512
00513
00514
00515 GTXabsl2ProfilerNameTableEntry& getNameTableEntry(int index);
00516
00517
00518
00519
00520
00521
00522
00523
00524 bool getActiveOption(int index, int maxdepth, GTXabsl2ActiveOption& retour);
00525 };
00526
00527 #endif// __GTXabsl2Profiler_h_
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582