/*---------------------------------------------------------------------------* Project: NintendoWare File: dev_ParticleProfile.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: 21122 $ *---------------------------------------------------------------------------*/ #include #include #include #include namespace nw { namespace dev { #if defined( NW_DEV_ENABLED ) && defined( NW_PARTICLE_PROFILE_ENABLED ) // singleton ParticleProfileCenter* ParticleProfileCenter::m_Instance = NULL; //--------------------------------------------------------------------------- //! @brief パーティクルプロファイラを初期化します。 //--------------------------------------------------------------------------- void ParticleProfileCenter::Initialize(int maxReport, os::IAllocator* allocator) { NW_ASSERT(m_Instance == NULL); nw::dev::ProfileManager::Description description; description.maxReport = (maxReport); description.exportFormat = nw::dev::ProfileManager::CHART; description.accuracy = nw::dev::ProfileManager::MILI_SECOND; description.mode = nw::dev::ProfileManager::TIMER; nw::dev::ProfileManager* profileManager = nw::dev::ProfileManager::CreateProfileManager( description, (allocator) ); void* memory = allocator->Alloc(sizeof(ParticleProfileCenter)); m_Instance = new(memory) ParticleProfileCenter(); m_Instance->m_ProfileManager = profileManager; // パーティクルの各機能測定用プロファイラ profileManager = nw::dev::ProfileManager::CreateProfileManager( description, (allocator) ); m_Instance->m_IntervalProfileManager = profileManager; m_Instance->m_IsRuning = false; } //--------------------------------------------------------------------------- //! @brief パーティクルプロファイラを終了します。 //--------------------------------------------------------------------------- void ParticleProfileCenter::Finalize(os::IAllocator* allocator) { if (m_Instance->m_ProfileManager) { m_Instance->m_ProfileManager->Destroy(allocator); m_Instance->m_ProfileManager = NULL; } if (m_Instance->m_IntervalProfileManager) { m_Instance->m_IntervalProfileManager->Destroy(allocator); m_Instance->m_IntervalProfileManager = NULL; } os::SafeFree(m_Instance, allocator); } //--------------------------------------------------------------------------- //! @brief 区間計測を開始します。 //--------------------------------------------------------------------------- bool ParticleProfileCenter::Start(const char* name) { if (!m_Instance) return false; if (m_Instance->m_IsRuning) return false; m_Instance->m_Report.name = name; m_Instance->m_Time = m_Instance->GetTime(); m_Instance->m_IsRuning = true; return true; } //--------------------------------------------------------------------------- //! @brief @brief 区間計測を終了します。 //--------------------------------------------------------------------------- void ParticleProfileCenter::Stop() { if (!m_Instance) return; if (!m_Instance->m_IsRuning) return; m_Instance->m_Time = m_Instance->GetTime() - m_Instance->m_Time; m_Instance->m_Report.elapsedTime = m_Instance->m_Time; m_Instance->m_Report.callCount = 1; m_Instance->m_Report.maxElapsedTime = m_Instance->m_Time; m_Instance->m_Report.minElapsedTime = m_Instance->m_Time; m_Instance->m_IntervalProfileManager->StoreReport(m_Instance->m_Report); m_Instance->m_IsRuning = false; } //--------------------------------------------------------------------------- //! @brief タイマを取得します。 //--------------------------------------------------------------------------- s64 ParticleProfileCenter::GetTime() { return nn::os::Tick::GetSystemCurrent().ToTimeSpan().GetNanoSeconds(); // return static_cast(nn::os::Tick::GetSystemCurrent()); } #endif // defined( NW_DEV_ENABLED ) && defined( NW_PARTICLE_PROFILE_ENABLED ) } // namespace dev } // namespace nw