/*---------------------------------------------------------------------------* Project: NintendoWare File: lyt_Stopwatch.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. 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. $Revision: 17401 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include namespace nw { namespace lyt { namespace internal { namespace { #ifdef NW_PLATFORM_CTR inline const TimeSpan operator / (const TimeSpan& lhs, int rhs) { if (rhs != 0) { return TimeSpan::FromNanoSeconds(lhs.GetNanoSeconds() / rhs); } else { return TimeSpan(); } } #endif } // namespace {anonymous} int Stopwatch::s_TargetNoMin = INT_MAX; int Stopwatch::s_TargetNoMax = INT_MIN; #ifdef NW_PLATFORM_CTR Stopwatch::Stopwatch(int no, const char* label) : m_Count(0), m_No(no), m_Label(label), m_MinSample(S64_MAX), m_MaxSample(0) { List& list = this->GetList(); list.push_back(this); } #else Stopwatch::Stopwatch(int, const char*) { } #endif void Stopwatch::Reset() { #ifdef NW_PLATFORM_CTR m_Count = 0; m_TotalTick = Tick(); m_MinSample = S64_MAX; m_MaxSample = 0; #endif } void Stopwatch::ResetAll() { List& list = GetList(); for (List::Iterator it = list.begin(); it != list.end(); ++it) { it->Reset(); } } void Stopwatch::Enable() { SetTargetNo(INT_MIN, INT_MAX); } void Stopwatch::Disable() { SetTargetNo(INT_MAX, INT_MIN); } void Stopwatch::Dump(const Stopwatch& stopwatch) { #ifndef NW_PLATFORM_CTR NW_UNUSED_VARIABLE(stopwatch); NW_LYT_PRINT("Stopwatch::Dump is not implemented.\n"); #else TimeSpan total = stopwatch.GetElapsedTime(); int count = stopwatch.GetCount(); const char* label = stopwatch.GetLabel(); if (label == NULL) { label = "-"; } { NW_LYT_PRINT( "| %s | %lld | %lld / %d | %lld | %lld | %d |\n", label, (total / count).GetMicroSeconds(), total.GetMicroSeconds(), count, stopwatch.GetMaxSample().GetMicroSeconds(), stopwatch.GetMinSample().GetMicroSeconds(), stopwatch.GetNo()); } #endif } void Stopwatch::DumpHeader() { #ifdef NW_PLATFORM_CTR NW_LYT_PRINT("| label | average | total / count | max | min | no |h\n"); #endif } void Stopwatch::Dump() { #ifndef NW_PLATFORM_CTR NW_LYT_PRINT("Stopwatch::Dump is not implemented.\n"); #else NW_LYT_PRINT("\n"); DumpHeader(); List& list = GetList(); for (List::Iterator it = list.begin(); it != list.end(); ++it) { if (it->GetCount() > 0) { Dump(*it); } } #endif } } // namespace internal } // namespace lyt } // namespace nw