/*-------------------------------------------------------------------------- Project: Horizon File: rdt_Stopwatch.h Copyright (C)2010 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 22867 $ *-------------------------------------------------------------------------*/ #ifndef NN_RDT_STOPWATCH_H_ #define NN_RDT_STOPWATCH_H_ #ifdef _WIN32 // Windows環境ではストップウォッチは使わないことにする。 // ビルドエラーの問題が解決できれば、使えるようにしたいのだが。 #else // #define ENABLE_RDT_STOPWATCH #endif #ifdef ENABLE_RDT_STOPWATCH #include #include namespace nn { namespace rdt { namespace CTR { namespace detail { /*! @brief これはRDTライブラリのパフォーマンス計測のために用意したクラスです。 */ class Stopwatch{ public: // 管理領域のクリア等を行う。Initialize()が明示的に呼ばれていなくても、 // コンストラクタの中で適宜呼ばれる。 static void Initialize(void); // 後始末。Stopwatchを利用するつもりが無くなったら、呼ぶこと。 static void Finalize(void); // 初期化されて、利用可能な状態? static bool IsInitialized(void) { return s_initialized; } // 名前なしストップウォッチ。 Stopwatch(void); // 名前付きストップウォッチ。32文字まで。 Stopwatch(const char *name); // デストラクタ。リストから自分を取り除く。 ~Stopwatch(void); // 計測開始。 void Start(void); // 計測終了。 void Stop(void); // 何度測定を実行したか? int GetTimes(void) const; // 計測した数値をリセット。ストップウォッチに付けた名前まではリセットしない。 void Reset(void); // ストップウォッチの結果をコンソールにプリント。 void Print(void) const; // 全ストップウォッチの内容をリセット static void ResetAll(void); // 全ストップウォッチの内容を表示 static void PrintAll(void); // 単体テスト。 static bool Test(void); private: // 定数 static const int MAX_STOPWATCHES = 32; static const int MAX_NAME_LENGTH = 32; // インスタンスの管理リスト static Stopwatch *s_paStopwatches[MAX_STOPWATCHES]; // 初期化済みかどうかを保持する変数。 static bool s_initialized; // インスタンスの初期化 bool initInstance(const char *name); // 管理リストに自分のインスタンスを登録。 // 登録するスペースがなかった場合にfalseが返る。 bool addToList(void); // 管理リストから自分のインスタンスを削除。 void removeFromList(void); // 名前を付ける。NULLポインタが渡された場合は、 // "(NULL)"という名前がセットされる。 void setName(const char *name); // 項目名を表示。 static void printHeadLine(void); // 中身(計測結果)を表示。 void printContents(void) const; // トータル時間。 s64 m_total; // Start()が呼ばれた時点でのTick s64 m_start; // 計測したなかで、最小だったもの s64 m_min; // 計測したなかで、最大だったもの s64 m_max; // これまでの計測回数。 s32 m_times; // パディング。このクラスにはs64型が含まれているため、8バイトアライメントが要求される。 NN_PADDING4; // ストップウォッチに付けられた名前。 char m_name[MAX_NAME_LENGTH]; }; inline void Stopwatch::Start(void) { m_start = nn::os::Tick::GetSystemCurrent(); } inline int Stopwatch::GetTimes(void) const { return m_times; } inline void Stopwatch::Reset(void) { m_total = 0; m_start = 0; m_min = LLONG_MAX; m_max = 0; m_times = 0; } }}}} // namespace nn::rdt::CTR::detail #else // else of ENABLE_RDT_STOPWATCH namespace nn { namespace rdt { namespace CTR { namespace detail { class Stopwatch { public: static void Initialize (void) { } static void Finalize (void) { } static bool IsInitialized(void) { return false; } Stopwatch (void) { } Stopwatch (const char*) { } ~Stopwatch (void) { } void Start (void) { } void Stop (void) { } int GetTimes (void) const { return 0; } void Reset (void) { } void Print (void) const { } static void ResetAll (void) { } static void PrintAll (void) { } static bool Test (void) { return false; } }; }}}} // namespace nn::rdt::CTR::detail #endif // end of ENABLE_RDT_STOPWATCH #endif // end of NN_RDT_STOPWATCH_H_