1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: instruments-1.cpp
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd. 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 $Rev: 46365 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nn.h>
17 #include <nn/applet.h>
18 #include <nn/dbg/dbg_Instrument.h>
19
20 using namespace nn;
21
22 // Measurement buffer
23 #define PROF_BUF_SIZE (0x1000)
24 u8 profBuffer[ PROF_BUF_SIZE ];
25 nn::dbg::CTR::Instrument inst;
26
27 // Statistical buffer
28 #define STAT_BUF_SIZE (0x1000)
29 u8 statBuffer[ STAT_BUF_SIZE ];
30 nn::dbg::CTR::Statistics stat;
31
32 bool isDumpInst = false;
33
34 //----------------------------------------------------------------
func3(void)35 void func3(void)
36 {
37 volatile int dummy = 0;
38
39 if ( isDumpInst )
40 {
41 inst.Dump();
42 }
43 }
44
func2(void)45 void func2(void)
46 {
47 func3();
48 }
49
func1(void)50 void func1(void)
51 {
52 func2();
53 }
54
funcA(void)55 void funcA(void)
56 {
57 volatile int dummy = 0;
58 }
59
60 //----------------------------------------------------------------
nnMain()61 extern "C" void nnMain()
62 {
63 nn::applet::CTR::Enable();
64
65 NN_LOG("----instruments-1 start.\n");
66 NN_LOG(" address of func1: %x\n", func1 );
67 NN_LOG(" address of func2: %x\n", func2 );
68 NN_LOG(" address of func3: %x\n", func3 );
69 NN_LOG(" address of funcA: %x\n", funcA );
70
71 //----------------------------------------------------------------
72 // Record only calls made using the standard buffer
73 NN_LOG("---------------- log mode\n");
74 inst.Initialize( profBuffer, PROF_BUF_SIZE, NN_DBG_TRACE_LOG );
75 stat.Clear();
76
77 inst.Enable();
78 funcA();
79 func1();
80 func1();
81 funcA();
82 inst.Disable();
83
84 inst.Dump();
85 stat.Collect( &inst );
86 stat.Dump();
87
88 inst.Finalize();
89
90 //----------------------------------------------------------------
91 // The standard buffer also performed system time measurement
92 NN_LOG("---------------- log mode, record tick\n");
93 inst.Initialize( profBuffer, PROF_BUF_SIZE, NN_DBG_RECORD_TICK | NN_DBG_TRACE_LOG );
94 stat.Initialize( statBuffer, STAT_BUF_SIZE );
95
96 inst.Enable();
97 funcA();
98 func1();
99 func1();
100 funcA();
101 inst.Disable();
102
103 inst.Dump();
104 stat.Collect( &inst );
105 stat.Dump();
106
107 inst.Finalize();
108
109 //----------------------------------------------------------------
110 // Record only calls made using the ring buffer
111 NN_LOG("---------------- log mode, ring buffer\n");
112 // Try using a smaller buffer
113 inst.Initialize( profBuffer, 0x20, NN_DBG_TRACE_LOG );
114 stat.Clear();
115
116 inst.Enable();
117 funcA();
118 func1();
119 func1();
120 funcA();
121 inst.Disable();
122
123 inst.Dump();
124 stat.Collect( &inst );
125 stat.Dump();
126
127 inst.Finalize();
128
129 //----------------------------------------------------------------
130 // The ring buffer also performs system time measurement
131 NN_LOG("---------------- log mode, record tick, ring buffer\n");
132 // Try using a smaller buffer
133 inst.Initialize( profBuffer, 0x40, NN_DBG_RECORD_TICK | NN_DBG_TRACE_LOG | NN_DBG_RING_BUFFER );
134 stat.Clear();
135
136 inst.Enable();
137 funcA();
138 func1();
139 func1();
140 funcA();
141 inst.Disable();
142
143 inst.Dump();
144 stat.Collect( &inst );
145 stat.Dump();
146
147 inst.Finalize();
148
149 //----------------------------------------------------------------
150 // Try displaying the call status during function execution in stack mode
151 NN_LOG("---------------- stack mode\n");
152 isDumpInst = true;
153 inst.Initialize( profBuffer, PROF_BUF_SIZE, NN_DBG_TRACE_STACK );
154 stat.Clear();
155
156 inst.Enable();
157 func1();
158 inst.Disable();
159
160 inst.Finalize();
161
162 //----------------------------------------------------------------
163 // Try displaying the call status during function execution including system time measurment in stack mode
164 NN_LOG("---------------- stack mode, record tick\n");
165 isDumpInst = true;
166 inst.Initialize( profBuffer, PROF_BUF_SIZE, NN_DBG_RECORD_TICK | NN_DBG_TRACE_STACK );
167 stat.Clear();
168
169 inst.Enable();
170 func1();
171 inst.Disable();
172
173 inst.Finalize();
174
175 //----------------------------------------------------------------
176 NN_LOG("----test-1 end.\n");
177 while(1)
178 {
179 nn::os::Thread::Sleep( nn::fnd::TimeSpan::FromMilliSeconds( 10 ) );
180 }
181 }
182