/*---------------------------------------------------------------------------* Project: Horizon File: rdt_Stopwatch.cpp Copyright (C)2009-2012 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: 46347 $ *---------------------------------------------------------------------------*/ #include "rdt_Stopwatch.h" #include #include #include #include #ifdef ENABLE_RDT_STOPWATCH namespace { } // End of anonymous namespace namespace nn { namespace rdt { namespace CTR { namespace detail{ bool Stopwatch::s_initialized = false; Stopwatch* Stopwatch::s_paStopwatches[MAX_STOPWATCHES]; void Stopwatch::Initialize(void) { if(!s_initialized) { for(int i=0; iReset(); } } } // Display all stopwatch content void Stopwatch::PrintAll(void) { printHeadLine(); for(int i=0; iprintContents(); } } } Stopwatch::Stopwatch(void) { if(!IsInitialized()) { NN_LOG("Initialize Stopwatch...\n"); Initialize(); } bool ret = initInstance("(No name)"); if(!ret) { NN_LOG("Failed to initInstance().\n"); } } Stopwatch::Stopwatch(const char *name) { NN_NULL_ASSERT(name); if(!IsInitialized()) { NN_LOG("Initialize Stopwatch...\n"); Initialize(); } bool ret = initInstance(name); if(!ret) { NN_LOG("Failed to initInstance().\n"); } } Stopwatch::~Stopwatch(void) { removeFromList(); } void Stopwatch::Stop(void) { s64 diff = nn::os::Tick::GetSystemCurrent() - m_start; if(diff > m_max) { m_max = diff; } if(diff < m_min) { m_min = diff; } m_total += diff; ++m_times; } void Stopwatch::Print(void) const { printHeadLine(); printContents(); } void Stopwatch::printHeadLine(void) { nn::dbg::detail::Printf( " Average, Min, Max, Total, Times, Name (Unit is usec)\n" ); } void Stopwatch::printContents(void) const { using nn::dbg::detail::Printf; if(m_times > 0) { // The unit is displayed in microseconds. s64 total = nnosTickConvertToMicroSeconds(m_total); s64 min = nnosTickConvertToMicroSeconds(m_min); s64 max = nnosTickConvertToMicroSeconds(m_max); f64 avg = static_cast(total) / m_times; Printf( "%10.2llf, %8lld, %8lld, %10lld, %8d, \"%s\"\n", avg, min, max, total, m_times, m_name); } else if(m_times == 0) { Printf( " ------ NO DATA ------ %s\"\n", m_name); } else { NN_PANIC("m_times is negative! (%d)\n", m_times); } } bool Stopwatch::initInstance(const char *name) { Reset(); setName(name); return addToList(); } // Register own instance in the management list. bool Stopwatch::addToList(void) { for(int i=0; i