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