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