/*---------------------------------------------------------------------------* Project: Horizon File: instruments-1.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46365 $ *---------------------------------------------------------------------------*/ #include #include #include using namespace nn; // Measurement buffer #define PROF_BUF_SIZE (0x1000) u8 profBuffer[ PROF_BUF_SIZE ]; nn::dbg::CTR::Instrument inst; // Statistical buffer #define STAT_BUF_SIZE (0x1000) u8 statBuffer[ STAT_BUF_SIZE ]; nn::dbg::CTR::Statistics stat; bool isDumpInst = false; //---------------------------------------------------------------- void func3(void) { volatile int dummy = 0; if ( isDumpInst ) { inst.Dump(); } } void func2(void) { func3(); } void func1(void) { func2(); } void funcA(void) { volatile int dummy = 0; } //---------------------------------------------------------------- extern "C" void nnMain() { nn::applet::CTR::Enable(); NN_LOG("----instruments-1 start.\n"); NN_LOG(" address of func1: %x\n", func1 ); NN_LOG(" address of func2: %x\n", func2 ); NN_LOG(" address of func3: %x\n", func3 ); NN_LOG(" address of funcA: %x\n", funcA ); //---------------------------------------------------------------- // Record only calls made using the standard buffer NN_LOG("---------------- log mode\n"); inst.Initialize( profBuffer, PROF_BUF_SIZE, NN_DBG_TRACE_LOG ); stat.Clear(); inst.Enable(); funcA(); func1(); func1(); funcA(); inst.Disable(); inst.Dump(); stat.Collect( &inst ); stat.Dump(); inst.Finalize(); //---------------------------------------------------------------- // The standard buffer also performed system time measurement NN_LOG("---------------- log mode, record tick\n"); inst.Initialize( profBuffer, PROF_BUF_SIZE, NN_DBG_RECORD_TICK | NN_DBG_TRACE_LOG ); stat.Initialize( statBuffer, STAT_BUF_SIZE ); inst.Enable(); funcA(); func1(); func1(); funcA(); inst.Disable(); inst.Dump(); stat.Collect( &inst ); stat.Dump(); inst.Finalize(); //---------------------------------------------------------------- // Record only calls made using the ring buffer NN_LOG("---------------- log mode, ring buffer\n"); // Try using a smaller buffer inst.Initialize( profBuffer, 0x20, NN_DBG_TRACE_LOG ); stat.Clear(); inst.Enable(); funcA(); func1(); func1(); funcA(); inst.Disable(); inst.Dump(); stat.Collect( &inst ); stat.Dump(); inst.Finalize(); //---------------------------------------------------------------- // The ring buffer also performs system time measurement NN_LOG("---------------- log mode, record tick, ring buffer\n"); // Try using a smaller buffer inst.Initialize( profBuffer, 0x40, NN_DBG_RECORD_TICK | NN_DBG_TRACE_LOG | NN_DBG_RING_BUFFER ); stat.Clear(); inst.Enable(); funcA(); func1(); func1(); funcA(); inst.Disable(); inst.Dump(); stat.Collect( &inst ); stat.Dump(); inst.Finalize(); //---------------------------------------------------------------- // Try displaying the call status during function execution in stack mode NN_LOG("---------------- stack mode\n"); isDumpInst = true; inst.Initialize( profBuffer, PROF_BUF_SIZE, NN_DBG_TRACE_STACK ); stat.Clear(); inst.Enable(); func1(); inst.Disable(); inst.Finalize(); //---------------------------------------------------------------- // Try displaying the call status during function execution including system time measurment in stack mode NN_LOG("---------------- stack mode, record tick\n"); isDumpInst = true; inst.Initialize( profBuffer, PROF_BUF_SIZE, NN_DBG_RECORD_TICK | NN_DBG_TRACE_STACK ); stat.Clear(); inst.Enable(); func1(); inst.Disable(); inst.Finalize(); //---------------------------------------------------------------- NN_LOG("----test-1 end.\n"); while(1) { nn::os::Thread::Sleep( nn::fnd::TimeSpan::FromMilliSeconds( 10 ) ); } }