00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00029 #define YASAGUI_LOGFILE_PARSER_INCLUDE
00030
00031 #include <yasagui/yasagui.h>
00032 #include "datatypes.h"
00033 #include "list.h"
00034 #include "filedialog.h"
00035 #include "logfilestatistics.h"
00036
00038 class YProject;
00039 class YCPULogFile;
00040 class YCPULogFileSet;
00041 class YLogAction;
00042 class YLogFileTask;
00043 class YLogFileMutex;
00044 class YEnvironmentLogFileSet;
00045 class YProjectLogFileSet;
00046
00047 typedef unsigned char ACTIONINT;
00048 #define ACTIONINTMAX 255
00049
00051 class YLoggingParser
00052 {
00053 YASA_TIME starttime;
00054 YASA_TIME endtime;
00056
00057 int cpulogfilenumber;
00059 YEnvironmentLogFileSet *environmentlogfile;
00060 int environmentlogfilenumber;
00062 YProjectLogFileSet *projectlogfile;
00063 int projectlogfilenumber;
00064 public: YLoggingParser() :
00065 starttime(0),
00066 endtime(0),
00067 cpulogfile(0),
00068 cpulogfilenumber(0),
00069 environmentlogfile(0),
00070 environmentlogfilenumber(0),
00071 projectlogfile(0),
00072 projectlogfilenumber(0)
00073 {}
00075 void SetTime(YASA_TIME start, YASA_TIME end) { starttime=start;
00076 endtime=end; }
00077 YASA_TIME GetStart() const { return starttime; }
00078 YASA_TIME GetEnd() const { return endtime; }
00079 virtual bool TimingFilter(const YLogAction *) const { return true; }
00080 virtual void EvaluateLoggingEntry(YLogAction *)=0;
00081
00082 YCPULogFile * GetCPULogFile() const { return cpulogfile; }
00083 int GetCPULogFileNumber() const { return cpulogfilenumber; }
00084 void SetCPULogFile(YCPULogFile *t, int number) { cpulogfile=t;
00085 cpulogfilenumber=number; }
00086 YEnvironmentLogFileSet* GetEnvironmentLogFile() const { return environmentlogfile; }
00087 int GetEnvironmentLogFileNumber() const { return environmentlogfilenumber; }
00088 void SetEnvironmentLogFile(YEnvironmentLogFileSet *t, int number)
00089 { environmentlogfile=t;
00090 environmentlogfilenumber=number; }
00091 void ResetParser() { cpulogfile=0;
00092 cpulogfilenumber=0;
00093 environmentlogfile=0;
00094 environmentlogfilenumber=0;
00095 projectlogfile=0;
00096 projectlogfilenumber=0;
00097 }
00098 };
00099
00105 class YLogAction
00106 {
00107 YASA_TIME starttime;
00108 YASA_TIME endtime;
00109 YLogFileTask * thread;
00110 YLogFileMutex * mutex;
00111
00112
00113
00114
00115 ACTIONINT action;
00116 public: YLogAction() :
00117 starttime(0),
00118 endtime(0),
00119 thread(0),
00120 mutex(0),
00121 action(YASAL_UNKNOWN)
00122 {}
00123 QString DetailedInfo();
00124 YASA_TIME GetStartTime() const { return starttime; }
00125 YASA_TIME GetEndTime() const { return endtime; }
00126 YLogFileTask * GetThread() const { return thread; }
00127 YLogFileMutex * GetMutex() const { return mutex; }
00128 ACTIONINT GetAction() const { return action; }
00129 void SetStartTime(const YASA_TIME &t){ starttime=t;
00130 endtime=t; }
00131 void SetEndTime(const YASA_TIME &t) { endtime=t; }
00132 void SetThread(YLogFileTask *t) { thread=t; }
00133 void SetMutex(YLogFileMutex *m) { mutex=m; }
00134 void SetAction(ACTIONINT a) { action=a; }
00135 bool IsThreadRange() const { return !mutex && endtime; }
00136 bool IsMutexRange() const { return mutex && endtime; }
00137 bool IsExcludedThreadRange() const { return !mutex && endtime && action==YASAL_THREAD_EXCLUDED; }
00138 };
00139
00140
00143 class YLogFileTask : public YObject
00144 { int id;
00145 int number;
00146 int periods;
00147 YTaskLogFileStatistics statistics;
00148
00149 YASA_TIME thread_activated;
00150 YASA_TIME thread_computed;
00151 YASA_TIME thread_scheduledactivationtime;
00152 public: YLogFileTask(const YObjectArgs &args) : YObject(args),
00153 id(0), number(0), periods(0), thread_activated(0), thread_computed(0), thread_scheduledactivationtime(0)
00154 { statistics.SetTask(this); }
00155 int GetId() const { return id; }
00156 void SetId(int i) { id=i; }
00157 int GetNumber() const { return number; }
00158 void SetNumber(int i) { number=i; }
00159 YTaskLogFileStatistics& GetStatistics() { return statistics; }
00160 void SetThreadActivatedTmp(YASA_TIME t) { thread_activated=t; }
00161 void SetScheduledActivationTime(YASA_TIME t) { thread_scheduledactivationtime=t;}
00162 void SetThreadPeriod(YASA_TIME currenttime)
00163
00164
00165
00166
00167
00168
00169
00170 {
00171 if ( periods )
00172 {
00173 GetStatistics().SetPeriod( currenttime - thread_scheduledactivationtime);
00174 }
00175 thread_scheduledactivationtime=currenttime;
00176 periods++;
00177 }
00178 void SetThreadDeadline(YASA_TIME currentdeadline)
00179
00180
00181
00182
00183
00184
00185
00186 {
00187 if ( periods && currentdeadline>thread_scheduledactivationtime )
00188 {
00189 GetStatistics().SetDeadline( currentdeadline - thread_scheduledactivationtime);
00190 }
00191 }
00192
00193
00194 void SetThreadComputedTmp(YASA_TIME t) { thread_computed=t; }
00195 void AddThreadComputedTmp(YASA_TIME t) { thread_computed+=t; }
00196 YASA_TIME GetThreadActivatedTmp() const { return thread_activated; }
00197 YASA_TIME GetThreadComputedTmp() const { return thread_computed; }
00198 bool IsIdleTask() const { return GetId() == YASA_IDLE_ID; }
00199 bool IsSystemTask() const { return GetId() == YASA_SCHEDULER_ID;}
00200 };
00201
00204 class YLogFileTaskSet : public YSet
00205 { protected:
00206 virtual YObject* AllocNewItem(const YObjectArgs &args) { return new YLogFileTask(args); }
00207 public: YLogFileTaskSet() :
00208 YSet( 0, MSGP_LF_DEFAULT_TASKNAME, YObjectArgs(), 0 ) { }
00209 YLogFileTask * AllocTaskItemOnce(const QString &name, int threadid)
00210 { YLogFileTask *task=FindTask(threadid);
00211 if (task)
00212 return task;
00213 if (name.length() )
00214 task = (YLogFileTask*) CreateNewItem(name);
00215 else
00216 task = (YLogFileTask*) CreateNewItem(MSGP_LF_DEFAULT_TASKNAME.arg(threadid) );
00217 if (task)
00218 {
00219 task->SetId(threadid);
00220 task->SetNumber(GetCount()-1);
00221 }
00222 return task;
00223 }
00224 YLogFileTask * FindTask(int threadid)
00225 {
00226 for( unsigned int i=0; i<GetCount() ; i++)
00227 { if ( ((YLogFileTask*)At(i))->GetId() == threadid )
00228 return (YLogFileTask*)At(i);
00229 }
00230 return 0;
00231 }
00232 void SortTaskSet() { sort(); }
00233 void ResetStatistics()
00234 {
00235 for( unsigned int i=0; i<GetCount() ; i++)
00236 ((YLogFileTask*)At(i))->GetStatistics().ResetStatistics();
00237 }
00238 void GenerateStatistics(YEnvironmentLogFileSet &envlogset)
00239 {
00240 for( unsigned int i=0; i<GetCount() ; i++)
00241 ((YLogFileTask*)At(i))->GetStatistics().CalculateStatistics( envlogset );
00242 }
00243 protected: int compareItems ( QCollection::Item item1, QCollection::Item item2 )
00244 { if ( ((YLogFileTask*)item1)->GetId() < ((YLogFileTask*)item2)->GetId() )
00245 return -1;
00246 if ( ((YLogFileTask*)item1)->GetId() == ((YLogFileTask*)item2)->GetId() )
00247 return 0;
00248 return 1;
00249 }
00250 };
00253 class YLogFileMutex : public YObject
00254 { int id;
00255 int number;
00256 YMutexLogFileStatistics statistics;
00257 YASA_TIME lockingtime;
00258 public: YLogFileMutex(const YObjectArgs &args) : YObject(args), id(0), number(0), lockingtime(0)
00259 { statistics.SetMutex(this); }
00260 int GetId() const { return id; }
00261 void SetId(int i) { id=i; }
00262 int GetNumber() const { return number; }
00263 void SetNumber(int n) { number=n; }
00264 YMutexLogFileStatistics&GetStatistics() { return statistics; }
00265 void SetMutexLockingTimeTmp(YASA_TIME t) { lockingtime=t; }
00266
00267 YASA_TIME GetMutexLockingTimeTmp() const { return lockingtime; }
00268 };
00269
00272 class YLogFileMutexSet : public YSet
00273 { protected:
00274 virtual YObject* AllocNewItem(const YObjectArgs &args) { return new YLogFileMutex(args); }
00275 public: YLogFileMutexSet() :
00276 YSet( 0, MSGP_LF_DEFAULT_TASKNAME, YObjectArgs(),0 ) { }
00277 YLogFileMutex * AllocMutexItemOnce(const QString &name, int mutexid)
00278 { YLogFileMutex *mutex;
00279 for( unsigned int i=0; i<GetCount() ; i++)
00280 { if ( ((YLogFileMutex*)At(i))->GetId() == mutexid )
00281 return (YLogFileMutex*)At(i);
00282 }
00283 if ( name.length() )
00284 mutex = (YLogFileMutex*)CreateNewItem( name );
00285 else
00286 mutex = (YLogFileMutex*)CreateNewItem( MSGP_LF_DEFAULT_MUTEXNAME.arg(mutexid) );
00287 if (mutex)
00288 {
00289 mutex->SetId(mutexid);
00290 mutex->SetNumber(GetCount()-1);
00291 }
00292 return mutex;
00293 }
00294 void SortMutexSet() { sort(); }
00295 void ResetStatistics()
00296 {
00297 for( unsigned int i=0; i<GetCount() ; i++)
00298 ((YLogFileMutex*)At(i))->GetStatistics().ResetStatistics();
00299 }
00300 void GenerateStatistics(YEnvironmentLogFileSet &envlogset)
00301 {
00302 for( unsigned int i=0; i<GetCount() ; i++)
00303 ((YLogFileMutex*)At(i))->GetStatistics().CalculateStatistics( envlogset );
00304 }
00305 protected: int compareItems ( QCollection::Item item1, QCollection::Item item2 )
00306 { if ( ((YLogFileMutex*)item1)->GetId() < ((YLogFileMutex*)item2)->GetId() )
00307 return -1;
00308 if ( ((YLogFileMutex*)item1)->GetId() == ((YLogFileMutex*)item2)->GetId() )
00309 return 0;
00310 return 1;
00311 }
00312 };
00313
00314
00315
00318 class YLogFile : public YFile
00319 { int linenumber;
00320 public: YLogFile(const QString &f) :
00321 YFile(f),
00322 linenumber(0)
00323 {}
00324 int ReadLine(QString &);
00325 int GetLineNumber() const { return linenumber; }
00326 int ReadGlobalArg(YASA_TIME &time, const QString &comparestring);
00327 int ReadGlobalDoubleArg(double &value, const QString &comparestr );
00328 };
00329
00330
00331
00334 class YLogActions : public QList<YLogAction>
00335 { public: YLogActions()
00336 {
00337 setAutoDelete(TRUE);
00338 }
00339 YLogAction* InsertNewLogAction(YLogAction *log)
00340 {
00341 if ( log )
00342 append(log);
00343 return log;
00344 }
00345 void RemoveLogAction(YLogAction *log)
00346 {
00347 if ( log )
00348 removeRef(log);
00349 }
00350
00351 void EvaluateLoggingActions(YLoggingParser &p)
00352 {
00353 if ( ! count() )
00354 return;
00355 if ( !first() )
00356 return;
00357 while ( at()!=-1 && current()->GetStartTime()<p.GetEnd() )
00358 {
00359 if ( current()->GetStartTime() <= p.GetEnd() &&
00360 current()->GetEndTime() >= p.GetStart() )
00361 {
00362 p.EvaluateLoggingEntry( current() );
00363 }
00364 next();
00365 };
00366 return;
00367 }
00368 protected: int compareItems ( QCollection::Item item1, QCollection::Item item2 )
00369 { if ( ((YLogAction*)item1)->GetStartTime() < ((YLogAction*)item2)->GetStartTime() )
00370 return -1;
00371 if ( ((YLogAction*)item1)->GetStartTime() == ((YLogAction*)item2)->GetStartTime() )
00372 return 0;
00373 return 1;
00374 }
00375 };
00376
00377
00380 class YCPULogFile : public YObject
00381 { Q_OBJECT
00382 YLogActions logactions;
00383 YCPULogFileStatistics statistics;
00384 public: YCPULogFile(const YObjectArgs &i) : YObject(i) { }
00385 ~YCPULogFile()
00386 {
00387 emit RemoveLogFile();
00388 }
00390 int ParseCPUSection(YLogFile &file);
00391 int GetCPU() const { return statistics.GetNumberOfCPU()-1; }
00392 void SetCPU(int cpu) { statistics.SetNumberOfCPU(cpu+1); }
00394 YASA_TIME GetDuration() const { return statistics.GetExecutionDuration();}
00395 YCPULogFileStatistics & GetStatistics() { return statistics; }
00396 YLogActions & GetLogActions() { return logactions; }
00397 YLogAction* CreateJitterLogAction(YASA_TIME time, YASA_TIME endtime);
00398 static void SetEndRange(YLogAction **range, YLogAction *action, YASA_TIME t);
00399 static YASA_TIME ReadYasaTimeParam(const QString &str, bool &ok);
00400 static QString ExtractName(const QString src);
00401 signals:
00402 void RemoveLogFile();
00403 };
00404
00405
00408 class YEnvironmentLogFileSet : public YSet
00409 { Q_OBJECT
00410 YLogFileTaskSet taskset;
00411 YLogFileMutexSet mutexset;
00412 QDateTime readdate;
00413 YEnvironmentLogFileStatistics statistics;
00414 public: YEnvironmentLogFileSet();
00415 protected:
00416 virtual YObject* AllocNewItem(const YObjectArgs &args) { return new YCPULogFile(args); }
00417 public:
00418 YLogFileTaskSet & GetTaskSet() { return taskset; }
00419 YLogFileMutexSet & GetMutexSet() { return mutexset; }
00420 void ResetEnvironmentLogFile();
00421 void ResetStatistics();
00422 int GenerateStatistics();
00423 int ParseLogFile(const QString &filename);
00424 ~YEnvironmentLogFileSet() { CleanupLogFile(); }
00426 void CleanupLogFile()
00427 {
00428 if ( GetCount() || taskset.GetCount() || mutexset.GetCount() )
00429 {
00430 emit LogFileCleanedUp();
00431 ResetEnvironmentLogFile();
00432 emit LogFileUpdated();
00433 }
00434 }
00436 YASA_TIME GetMaxDuration()
00437 {
00438 YASA_TIME time=0;
00439 for( unsigned int index=0; index<GetCount();index++)
00440 {
00441 if (time< ((YCPULogFile*)At(index))->GetDuration() )
00442 time=((YCPULogFile*)At(index))->GetDuration();
00443 }
00444 return time;
00445 }
00446
00449 void EvaluateLoggingActions(YLoggingParser &p)
00450 { for( unsigned int index=0; index<GetCount();index++)
00451 {
00452 p.SetCPULogFile( (YCPULogFile*)At(index), index );
00453 ((YCPULogFile*)current())->GetLogActions().EvaluateLoggingActions( p );
00454 }
00455 }
00456 YEnvironmentLogFileStatistics & GetStatistics() { return statistics; }
00457 signals:
00458
00459 void LogFileUpdated();
00460 void LogFileCleanedUp();
00461 };
00462
00463
00464
00467 class YProjectLogFile : public YObject
00468 {
00469 YProject *project;
00470 void UpdateList();
00471 public: YProjectLogFile() : project(0) { }
00472 void EvaluateLoggingActions(YLoggingParser &p);
00474 void SetParent(YProject *p) { project=p; }
00475 YProject* GetProject() const { return project; }
00476 YASA_TIME GetMaxDuration() const;
00477 unsigned int GetMaxEntries() const;
00478 QStringList GetEnvironmentNames() const;
00479
00480
00482
00484
00485
00486 };
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00532 class LogFileParser
00533 {
00534 };
00535
00536
00538 class YasaLogFileParser
00539 {
00540 };
00541
00542
00544 class OldYasaLogFileParser
00545 {
00546 };
00547
00548
00549
00550
00552 #endif // ifndef YASAGUI_LOGFILE_PARSER_INCLUDE