/* Web Polygraph       http://www.web-polygraph.org/
 * (C) 2003-2006 The Measurement Factory
 * Licensed under the Apache License, Version 2.0 */

#ifndef POLYGRAPH__LOGANALYZERS_SIDEINFO_H
#define POLYGRAPH__LOGANALYZERS_SIDEINFO_H

#include "xstd/Time.h"
#include "xstd/String.h"
#include "xstd/BigSize.h"
#include "xstd/Array.h"
#include "loganalyzers/PhaseInfo.h"
#include "loganalyzers/SomeInfo.h"

class InfoScopes;
class TestInfo;
class ProcInfo;
class PhaseInfo;
class TmsSzStat;
class StatPhaseRec;
class ErrorRec;
class ErrorStat;
class XmlTable;
class BlobDb;
class Stex;


// aggregate stats and other logged information about a test side 
// (e.g., client- or server-side); 
// manages info about all processes that belong to one side
class SideInfo: public SomeInfo {
	public:
		static void CompileEmptyStats(BlobDb &db, const Scope &scope);
		static void ConfigureStex();

	public:
		SideInfo(int aLogCat);
		~SideInfo();

		int logCat() const;
		const String &name() const; // "client" or "server"
		const String &otherName() const; // "server" or "client"
		const String &benchmarkVersion() const;
		const String &pglCfg() const;
		Time startTime() const;
		int repCount(const Scope &scope) const;
		int hitCount(const Scope &scope) const;
		int offeredHitCount(const Scope &scope) const;
		BigSize repVolume(const Scope &scope) const;
		BigSize hitVolume(const Scope &scope) const;
		BigSize offeredHitVolume(const Scope &scope) const;

		void test(TestInfo *t);
		TestInfo *test();

		void add(ProcInfo *info); // absorbs
		ProcInfo &proc(int idx);
		int procCount() const;

		const PhaseInfo &phase(const Scope &scope) const;
		const PhaseInfo &phase(const String &name) const;
		const PhaseInfo &phase(int idx) const;
		int phaseCount() const;

		const Scope &scope() const { return theScope; } // all phases
		int scopes(InfoScopes &res) const;
		const Scope &execScope() const;
		const StatPhaseRec &execScopeStats() const;

		void checkConsistency();
		void compileStats(BlobDb &db);

	protected:
		static void AddStex(Stex *stex, const Stex *parent);
		static void AddStex(Stex *stex);

		void addPhase(const PhaseInfo &phase);
		const PhaseInfo *findPhase(const String &name) const;
		PhaseInfo *findPhase(const String &name);

		void checkCommonBenchmarkVersion();
		void checkCommonPglCfg();
		void checkCommonStartTime();
		void checkCommonPhases();

		void compileStats(BlobDb &db, const PhaseInfo &phase, const Scope &scope);
		void cmplLoadBlob(BlobDb &db, const Scope &scope);
		void cmplLoadTable(BlobDb &db, ReportBlob &parent, const Scope &scope);
		void cmplLoadFigure(BlobDb &db, ReportBlob &blob, const Scope &scope);
		void cmplRptmFigure(BlobDb &db, const Scope &scope);
		void cmplRptmVsLoadFigure(BlobDb &db, const PhaseInfo &phase, const Scope &scope);

		void cmplHitRatioTable(BlobDb &db, const Scope &scope);
		void cmplHrTraces(BlobDb &db, ReportBlob &blob, const Scope &scope);
		void cmplBhrTrace(BlobDb &db, ReportBlob &blob, const Scope &scope);
		void cmplDhrTrace(BlobDb &db, ReportBlob &blob, const Scope &scope);

		void cmplXactLevelTable(BlobDb &db, const PhaseInfo &phase, const Scope &scope);
		void cmplStreamTable(BlobDb &db, const PhaseInfo &phase, const Scope &scope);
		void cmplXactLevelFigure(BlobDb &db, ReportBlob &blob, const Scope &scope);
		void cmplConnLevelTable(BlobDb &db, const PhaseInfo &phase, const Scope &scope);
		void cmplConnLevelFigure(BlobDb &db, ReportBlob &blob, const Scope &scope);
		void cmplConnPipelineBlob(BlobDb &db, const Scope &scope);
		void cmplConnPipelineTable(BlobDb &db, ReportBlob &parent, const Scope &scope);
		void cmplConnPipelineTrace(BlobDb &db, ReportBlob &blob, const Scope &scope);
		void cmplConnPipelineHist(BlobDb &db, ReportBlob &blob, const Scope &scope);
		void cmplPopulLevelTable(BlobDb &db, const PhaseInfo &phase, const Scope &scope);
		void cmplPopulLevelFigure(BlobDb &db, ReportBlob &blob, const Scope &scope);
		void cmplObjectTable(BlobDb &db, const PhaseInfo &s, const Scope &scope);
		void cmplErrorTable(BlobDb &db, const PhaseInfo &phase, const Scope &scope);
		void cmplObjectBlobs(BlobDb &db, const PhaseInfo &phase, const Scope &scope);
		void cmplSideSum(BlobDb &db);

		void cmplLevelTableRec(BlobDb &db, const String &pfx, const String &state, const LevelStat &stats, const Scope &scope, XmlTable &table);
		void cmplObjectTableRec(BlobDb &db, XmlTable &table, const Stex &stex, const PhaseInfo &phase, const Scope &scope);
		void cmplStreamTableRec(BlobDb &db, XmlTable &table, const Stex &stex, const PhaseInfo &phase, const Scope &scope);
		void cmplErrorTableRec(BlobDb &db, XmlTable &table, const ErrorStat &errors, const ErrorRec &error, const Scope &scope);
		const ReportBlob &cmplObjectBlob(BlobDb &db, const Stex &stex, const PhaseInfo &phase, const Scope &scope);

	protected:
		static Stex *TheAllReps;
		static Array<Stex*> TheStex;

	protected:
		Scope theScope;
		mutable Scope theExecScope;
		int theLogCat;
		String theBenchmarkVersion;
		String thePglCfg;
		Time theStartTime;
		TestInfo *theTest;

		Array<ProcInfo*> theProcs;
		Array<PhaseInfo*> thePhases;
		PhaseInfo theExecScopePhase;
		PhaseInfo theAllPhasesPhase;
};

#endif


syntax highlighted by Code2HTML, v. 0.9.1