1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: dev_ParticleProfile.cpp
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: 21122 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nw/dev/dev_ParticleProfile.h>
17 #include <nw/ut/ut_Inlines.h>
18 #include <nw/dev/dev_Utility.h>
19
20 #include <nn/os.h>
21
22 namespace nw
23 {
24 namespace dev
25 {
26
27 #if defined( NW_DEV_ENABLED ) && defined( NW_PARTICLE_PROFILE_ENABLED )
28
29
30 // singleton
31 ParticleProfileCenter* ParticleProfileCenter::m_Instance = NULL;
32
33
34 //---------------------------------------------------------------------------
35 //! @brief パーティクルプロファイラを初期化します。
36 //---------------------------------------------------------------------------
37 void
Initialize(int maxReport,os::IAllocator * allocator)38 ParticleProfileCenter::Initialize(int maxReport, os::IAllocator* allocator)
39 {
40 NW_ASSERT(m_Instance == NULL);
41
42 nw::dev::ProfileManager::Description description;
43 description.maxReport = (maxReport);
44 description.exportFormat = nw::dev::ProfileManager::CHART;
45 description.accuracy = nw::dev::ProfileManager::MILI_SECOND;
46 description.mode = nw::dev::ProfileManager::TIMER;
47
48 nw::dev::ProfileManager* profileManager = nw::dev::ProfileManager::CreateProfileManager( description, (allocator) );
49 void* memory = allocator->Alloc(sizeof(ParticleProfileCenter));
50 m_Instance = new(memory) ParticleProfileCenter();
51 m_Instance->m_ProfileManager = profileManager;
52
53 // パーティクルの各機能測定用プロファイラ
54 profileManager = nw::dev::ProfileManager::CreateProfileManager( description, (allocator) );
55 m_Instance->m_IntervalProfileManager = profileManager;
56
57 m_Instance->m_IsRuning = false;
58 }
59
60
61 //---------------------------------------------------------------------------
62 //! @brief パーティクルプロファイラを終了します。
63 //---------------------------------------------------------------------------
64 void
Finalize(os::IAllocator * allocator)65 ParticleProfileCenter::Finalize(os::IAllocator* allocator)
66 {
67 if (m_Instance->m_ProfileManager)
68 {
69 m_Instance->m_ProfileManager->Destroy(allocator);
70 m_Instance->m_ProfileManager = NULL;
71 }
72
73 if (m_Instance->m_IntervalProfileManager)
74 {
75 m_Instance->m_IntervalProfileManager->Destroy(allocator);
76 m_Instance->m_IntervalProfileManager = NULL;
77 }
78 os::SafeFree(m_Instance, allocator);
79 }
80
81
82
83
84 //---------------------------------------------------------------------------
85 //! @brief 区間計測を開始します。
86 //---------------------------------------------------------------------------
Start(const char * name)87 bool ParticleProfileCenter::Start(const char* name)
88 {
89 if (!m_Instance) return false;
90 if (m_Instance->m_IsRuning) return false;
91
92 m_Instance->m_Report.name = name;
93 m_Instance->m_Time = m_Instance->GetTime();
94 m_Instance->m_IsRuning = true;
95
96 return true;
97 }
98
99
100 //---------------------------------------------------------------------------
101 //! @brief @brief 区間計測を終了します。
102 //---------------------------------------------------------------------------
Stop()103 void ParticleProfileCenter::Stop()
104 {
105 if (!m_Instance) return;
106 if (!m_Instance->m_IsRuning) return;
107
108 m_Instance->m_Time = m_Instance->GetTime() - m_Instance->m_Time;
109 m_Instance->m_Report.elapsedTime = m_Instance->m_Time;
110 m_Instance->m_Report.callCount = 1;
111 m_Instance->m_Report.maxElapsedTime = m_Instance->m_Time;
112 m_Instance->m_Report.minElapsedTime = m_Instance->m_Time;
113
114 m_Instance->m_IntervalProfileManager->StoreReport(m_Instance->m_Report);
115
116 m_Instance->m_IsRuning = false;
117 }
118
119
120 //---------------------------------------------------------------------------
121 //! @brief タイマを取得します。
122 //---------------------------------------------------------------------------
123 s64
GetTime()124 ParticleProfileCenter::GetTime()
125 {
126 return nn::os::Tick::GetSystemCurrent().ToTimeSpan().GetNanoSeconds();
127 // return static_cast<s64>(nn::os::Tick::GetSystemCurrent());
128 }
129
130
131
132 #endif // defined( NW_DEV_ENABLED ) && defined( NW_PARTICLE_PROFILE_ENABLED )
133
134
135 } // namespace dev
136 } // namespace nw
137