1 2 /* Web Polygraph http://www.web-polygraph.org/ 3 * Copyright 2003-2011 The Measurement Factory 4 * Licensed under the Apache License, Version 2.0 */ 5 6 #include "base/polygraph.h" 7 8 #include "loganalyzers/PhaseTrace.h" 9 #include "loganalyzers/PhaseInfo.h" 10 PhaseInfo()11PhaseInfo::PhaseInfo(): theIntvlCount(0), theTrace(0), gotPhaseStats(false) { 12 } 13 ~PhaseInfo()14PhaseInfo::~PhaseInfo() { 15 delete theTrace; 16 } 17 name() const18const String PhaseInfo::name() const { 19 return thePhase.theName; 20 } 21 hasStats() const22const StatPhaseRec *PhaseInfo::hasStats() const { 23 return gotPhaseStats ? &thePhase : 0; 24 } 25 availStats() const26const StatIntvlRec &PhaseInfo::availStats() const { 27 Assert(theIntvl.theDuration >= 0); 28 return hasStats() ? (const StatIntvlRec &)stats() : theIntvl; 29 } 30 merge(const PhaseInfo & phase)31void PhaseInfo::merge(const PhaseInfo &phase) { 32 if (!thePhase.theName) 33 thePhase.theName = phase.thePhase.theName; 34 35 if (phase.hasStats()) { 36 thePhase.merge(phase.stats()); 37 gotPhaseStats = true; 38 } 39 theIntvl.merge(phase.theIntvl); 40 theIntvlCount = Max(theIntvlCount, phase.theIntvlCount); 41 42 Assert(phase.theTrace); 43 if (!theTrace) { 44 theTrace = new PhaseTrace; 45 theTrace->concat(phase.trace()); 46 } else { 47 theTrace->merge(phase.trace()); 48 } 49 } 50 concat(const PhaseInfo & phase)51void PhaseInfo::concat(const PhaseInfo &phase) { 52 if (!thePhase.theName) 53 thePhase.theName = phase.thePhase.theName; 54 55 if (phase.hasStats()) { 56 thePhase.concat(phase.stats()); 57 gotPhaseStats = true; 58 } 59 theIntvl.concat(phase.theIntvl); 60 theIntvlCount = theIntvlCount + phase.theIntvlCount; 61 62 Assert(phase.theTrace); 63 if (!theTrace) 64 theTrace = new PhaseTrace; 65 theTrace->concat(phase.trace()); 66 } 67 startTrace()68PhaseTrace *PhaseInfo::startTrace() { 69 theTrace = new PhaseTrace; 70 theTrace->configure(theIntvl); 71 return theTrace; 72 } 73 noteIntvl(const StatIntvlRec & r,const String & phaseName)74void PhaseInfo::noteIntvl(const StatIntvlRec &r, const String &phaseName) { 75 Assert(!theTrace); 76 77 if (thePhase.theName) 78 Should(thePhase.theName == phaseName); 79 else 80 thePhase.theName = phaseName; 81 82 theIntvl.concat(r); 83 theIntvlCount++; 84 } 85 noteEndOfLog()86void PhaseInfo::noteEndOfLog() { 87 Assert(!theTrace); 88 if (thePhase.theDuration < 0) 89 ((StatIntvlRec&)thePhase).merge(theIntvl); // restore what we can 90 } 91 notePhase(const StatPhaseRec & r)92void PhaseInfo::notePhase(const StatPhaseRec &r) { 93 Assert(!theTrace); 94 Assert(!thePhase.name() || thePhase.name() == r.name()); 95 Assert(thePhase.theDuration < 0); 96 thePhase.concat(r); 97 gotPhaseStats = true; 98 } 99 checkConsistency()100void PhaseInfo::checkConsistency() { 101 if (!theIntvlCount) 102 cerr << thePhase.theName << ": strange, no stat intervals within a phase" << endl; 103 } 104 compileStats(BlobDb &)105void PhaseInfo::compileStats(BlobDb &) { 106 } 107