1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: dev_ParticleProfile.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_DEV_PARTICLEPROFILE_H_ 19 #define NW_DEV_PARTICLEPROFILE_H_ 20 21 #include <nw/dev.h> 22 23 // パーティクル専用のプロファイルのマクロ有効にします。 24 //#define NW_PARTICLE_PROFILE_ENABLED 25 26 namespace nw 27 { 28 namespace dev 29 { 30 31 //! NW_DEV_ENABLED と NW_PARTICLE_PROFILE_ENABLED がともに定義されていたらプロファイルマクロを有効にします。 32 #if defined( NW_DEV_ENABLED ) && defined( NW_PARTICLE_PROFILE_ENABLED ) 33 34 35 //--------------------------------------------------------------------------- 36 //! @brief パーティクル専用のProfileManager を管理するクラスです。 37 //--------------------------------------------------------------------------- 38 class ParticleProfileCenter 39 { 40 private: 41 NW_DISALLOW_COPY_AND_ASSIGN(ParticleProfileCenter); 42 43 public: 44 //! @brief プロファイルの管理クラスを初期化します。 45 static void Initialize(int maxReport, os::IAllocator* allocator); 46 47 //! @brief プロファイルの管理クラスを削除します。 48 static void Finalize(os::IAllocator* allocator); 49 50 //! @brief レポートを出力します。 DumpCost()51 static void DumpCost() 52 { 53 if (!m_Instance) return; 54 m_Instance->m_ProfileManager->DumpReports(); 55 } 56 57 //! @brief 区間計測レポートを出力します。 DumpIntervalCost()58 static void DumpIntervalCost() 59 { 60 if (!m_Instance) return; 61 m_Instance->m_IntervalProfileManager->DumpReports(); 62 } 63 64 //! @brief プロファイルをクリアします。 Clear()65 static void Clear() 66 { 67 if (!m_Instance) return; 68 m_Instance->m_ProfileManager->ClearReports(); 69 m_Instance->m_IntervalProfileManager->ClearReports(); 70 } 71 72 //! @brief インスタンスを取得します。 GetInstance()73 static ParticleProfileCenter& GetInstance() 74 { 75 NW_NULL_ASSERT(m_Instance); 76 return *m_Instance; 77 } 78 79 //! @brief プロファイルマネージャインスタンスを取得します。 GetProfileManager()80 static nw::dev::ProfileManager* GetProfileManager() 81 { 82 if (!m_Instance) return NULL; 83 return GetInstance().m_ProfileManager; 84 } 85 86 //! @brief コスト計測を開始します。 87 static bool Start(const char* name); 88 89 //! @brief コスト計測を終了します。 90 static void Stop(); 91 92 private: 93 s64 GetTime(); 94 ParticleProfileCenter()95 ParticleProfileCenter() 96 : m_ProfileManager(NULL) 97 {} 98 99 static ParticleProfileCenter* m_Instance; 100 101 nw::dev::ProfileManager* m_ProfileManager; 102 nw::dev::ProfileManager* m_IntervalProfileManager; 103 104 bool m_IsRuning; 105 106 nw::dev::ProfileManager::Report m_Report; 107 s64 m_Time; 108 }; 109 110 #else 111 112 113 class ParticleProfileCenter 114 { 115 private: 116 NW_DISALLOW_COPY_AND_ASSIGN(ParticleProfileCenter); 117 public: 118 static void Initialize(int, os::IAllocator*){} 119 static void Finalize(os::IAllocator*){} 120 static void Report(){} 121 static nw::dev::ProfileManager* GetProfileManager(){ return NULL; } 122 private: 123 ParticleProfileCenter(){} 124 }; 125 126 127 #endif // defined( NW_DEV_ENABLED ) && defined( NW_PARTICLE_PROFILE_ENABLED ) 128 129 130 } // namespace dev 131 } // namespace nw 132 133 134 //! NW_DEV_ENABLED と NW_PARTICLE_PROFILE_ENABLED がともに定義されていたらプロファイルマクロを有効にします。 135 #if defined( NW_DEV_ENABLED ) && defined( NW_PARTICLE_PROFILE_ENABLED ) 136 137 138 // パーティクル用のプロファイラ登録マクロです。 139 // 計測したい区間を START と END で括ってください。 140 #define NW_PARTICLE_PROFILE_START(name) bool ret = nw::dev::ParticleProfileCenter::Start(name) 141 142 #define NW_PARTICLE_PROFILE_STOP() if(ret) nw::dev::ParticleProfileCenter::Stop() 143 144 // パーティクル用の計測用プロファイラ登録マクロです。 145 #define NW_PARTICLE_PROFILE(name) \ 146 nw::dev::AutoProfile p(name, nw::dev::ParticleProfileCenter::GetProfileManager()) 147 148 // パーティクル用のプロファイラ初期化マクロです。 149 #define NW_INITIALIZE_PARTICLE_PROFILE(maxReport, allocator) nw::dev::ParticleProfileCenter::Initialize(maxReport, allocator) 150 151 // パーティクル用のプロファイラ終了マクロです。 152 #define NW_FINALIZE_PARTICLE_PROFILE(allocator) nw::dev::ParticleProfileCenter::Finalize(allocator) 153 154 // パーティクル用のプロファイラログ出力マクロです。 155 #define NW_REPORT_PARTICLE_INTERVAL_PROFILE() nw::dev::ParticleProfileCenter::DumpIntervalCost() 156 #define NW_REPORT_PARTICLE_PROFILE() nw::dev::ParticleProfileCenter::DumpCost() 157 158 // パーティクル用の保存したプロファイルをクリアします。 159 #define NW_CLEAR_PARTICLE_PROFILE() nw::dev::ParticleProfileCenter::Clear() 160 161 162 #else 163 164 165 #define NW_PARTICLE_PROFILE_START(name) (void)0 166 #define NW_PARTICLE_PROFILE_STOP() (void)0 167 #define NW_PARTICLE_PROFILE(name) (void)0 168 #define NW_INITIALIZE_PARTICLE_PROFILE(maxReport, allocator) (void)0 169 #define NW_FINALIZE_PARTICLE_PROFILE(allocator) (void)0 170 #define NW_REPORT_PARTICLE_INTERVAL_PROFILE() (void)0 171 #define NW_REPORT_PARTICLE_PROFILE() (void)0 172 #define NW_CLEAR_PARTICLE_PROFILE() (void)0 173 174 175 #endif 176 177 178 179 #endif // NW_DEV_PARTICLEPROFILE_H_ 180