2 Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
\r
5 Physics Effects is open software; you can redistribute it and/or
\r
6 modify it under the terms of the BSD License.
\r
8 Physics Effects is distributed in the hope that it will be useful,
\r
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
11 See the BSD License for more details.
\r
13 A copy of the BSD License is distributed with
\r
14 Physics Effects under the filename: physics_effects_license.txt
\r
17 #ifndef _SCE_PFX_PERF_COUNTER_H
\r
18 #define _SCE_PFX_PERF_COUNTER_H
\r
20 #include "pfx_common.h"
\r
22 // ARA begin insert new code
\r
28 //J パフォーマンス測定する場合はPFX_USE_PERFCOUNTERを定義
\r
29 //J ブックマークを使用する場合はPFX_USE_BOOKMARKを定義
\r
31 //E Define SCE_PFX_USE_PERFCOUNTER to check performance
\r
32 //E Define SCE_PFX_USE_BOOKMARK to use bookmark
\r
35 #define SCE_PFX_MAX_PERF_STR 32
\r
36 #define SCE_PFX_MAX_PERF_COUNT 20
\r
38 //#define SCE_PFX_USE_PERFCOUNTER
\r
39 //#define SCE_PFX_USE_BOOKMARK
\r
42 namespace PhysicsEffects {
\r
43 #ifdef SCE_PFX_USE_PERFCOUNTER
\r
45 class PfxPerfCounter
\r
48 int m_count,m_strCount;
\r
49 char m_str[SCE_PFX_MAX_PERF_COUNT][SCE_PFX_MAX_PERF_STR];
\r
52 SCE_PFX_PADDING(1,4)
\r
54 LONGLONG m_cnt[SCE_PFX_MAX_PERF_COUNT*2];
\r
56 // ARA begin insert new code
\r
57 timespec m_cnt[SCE_PFX_MAX_PERF_COUNT*2];
\r
64 QueryPerformanceCounter( (LARGE_INTEGER *)&m_cnt[i] );
\r
66 // ARA begin insert new code
\r
67 clock_gettime(CLOCK_MONOTONIC, &m_cnt[i]);
\r
76 LARGE_INTEGER sPerfCountFreq;
\r
77 QueryPerformanceFrequency(&sPerfCountFreq);
\r
78 m_freq = (float)sPerfCountFreq.QuadPart;
\r
80 // ARA begin insert new code
\r
81 m_freq = 1000000000.0f; // clock_gettime reports time in nanoseconds (though accuracy is platform dependent)
\r
92 void countBegin(const char *name)
\r
94 SCE_PFX_ASSERT(m_strCount < SCE_PFX_MAX_PERF_COUNT);
\r
95 strncpy(m_str[m_strCount],name,SCE_PFX_MAX_PERF_STR-1);
\r
96 m_str[m_strCount][SCE_PFX_MAX_PERF_STR-1] = 0x00;
\r
112 float getCountTime(int i)
\r
115 return (float)(m_cnt[i+1]-m_cnt[i]) / m_freq * 1000.0f;
\r
117 // ARA begin insert new code
\r
118 return float(m_cnt[i+1].tv_sec - m_cnt[i].tv_sec) +
\r
119 (float(m_cnt[i+1].tv_nsec - m_cnt[i].tv_nsec) / m_freq);
\r
126 if(m_count%2 != 0) countEnd();
\r
127 SCE_PFX_PRINTF("*** PfxPerfCounter results ***\n");
\r
128 float total = 0.0f;
\r
129 for(int i=0;i+1<m_count;i+=2) {
\r
130 total += getCountTime(i);
\r
132 for(int i=0;i+1<m_count;i+=2) {
\r
133 SCE_PFX_PRINTF(" -- %s %fms(%.2f%%)\n",m_str[i>>1],getCountTime(i),getCountTime(i)/total*100.0f);
\r
135 SCE_PFX_PRINTF(" -- Total %fms\n",total);
\r
139 #else /* SCE_PFX_USE_PERFCOUNTER */
\r
141 class PfxPerfCounter
\r
144 PfxPerfCounter() {}
\r
145 ~PfxPerfCounter() {}
\r
146 void countBegin(const char *name) {(void) name;}
\r
148 void resetCount() {}
\r
149 float getCountTime(int i) {(void)i;return 0.0f;}
\r
150 void printCount() {}
\r
153 #endif /* SCE_PFX_USE_PERFCOUNTER */
\r
155 #define pfxInsertBookmark(bookmark)
\r
157 #ifdef SCE_PFX_USE_BOOKMARK
\r
158 #define SCE_PFX_PUSH_MARKER(name)
\r
159 #define SCE_PFX_POP_MARKER()
\r
161 #define SCE_PFX_PUSH_MARKER(name)
\r
162 #define SCE_PFX_POP_MARKER()
\r
165 } //namespace PhysicsEffects
\r
168 #endif // _SCE_PFX_PERF_COUNTER_H
\r