CTR Pia  4.11.3
Game Communication Engine
PiaSession Validation Testing (Profiling Tests)

Introduction

This profiling program measures the load on the CPU and the amount of memory used when communicating using Pia and NEX.

You can measure these values by changing the macros in ProfilingTest_Common.h. This program does not serve as a good sample because it implements a large number of features for profiling. A compatible NEX package is required to build this program. With this sample, communication is possible with a maximum of 12 devices by default.

Profiling Your Program

You can adjust the profiling conditions by building your program with the appropriate macros in ProfilingTest_Common.h set to 1. By default, the Pia library does not measure CPU load or memory usage during communication. Nintendo recommends running a release build to minimize the processing load caused by log output.

Macro What Is Profiled
ENABLE_CPU_PROFILING Enables profiling of the CPU load.
ENABLE_MEMORY_PROFILING Enables profiling of memory usage.
ENABLE_WATERMARK Enables profiling of the peak values of Pia's internal buffer usage.
ENABLE_LOCAL Profiles when in local communication.
When set to 0, profiles when in Internet communication (default).
ENABLE_NEX_NETZ Profiles using NEX's NetZ.
When set to 0, uses Pia for profiling (default).
ENABLE_UNRELIABLE_COMMUNICATION Profiles when using unreliable communication.
Do not enable at the same time as ENABLE_RELIABLE_COMMUNICATION.
ENABLE_RELIABLE_COMMUNICATION Profiles when using reliable communication.
Do not enable at the same time as ENABLE_UNRELIABLE_COMMUNICATION.
GAME_PARTICIPANTS_NUM Sets the maximum number of devices that can participate in a session. Operation has been confirmed for up to 12 devices.

Controlling the Program

Profiling CPU Load

  1. Set ENABLE_CPU_PROFILING in ProfilingTest_Common.h to 1 and build.
  2. The CPU load for processes other than communication are measured for the first 20 seconds after you run the program.
  3. The following information appears in the log output of the debugger.

    Press A : Start automatch
    Press B : Logout
    


    Press the A Button to perform matchmaking. The console that first started random matchmaking becomes the host. After that, consoles on which the A Button (for Internet communication) or the Y Button (for local communication) is pressed can perform matchmaking as clients until the number of devices set in the GAME_PARTICIPANTS_NUM session macro is reached.

    After the number of systems set in GAME_PARTICIPANTS_NUM have been matched, the program transitions to the profiling sequence automatically.
    Press the A Button during matchmaking to transition to the profiling sequence with the currently matched systems.

  4. The profiling sequence starts by outputting the current settings to the debugger log.
  5. After the following debugger output is written to the log, press START on any of the consoles to start communications.
    Press A : Start profiling for game loop
    Press START: Start (unreliable/reliable) communication
    

    After communication has started, pressing the A Button begins measuring the CPU load for 10 seconds.
  6. After profiling is complete, the debugger outputs the following results to the log. The Profile Result is the CPU load rate for communication processes.
    -- Profiler --
    PiaSession StationNum: 2
    Idle Profile Result: 9913 (10000 [ms], 9913)
    Base Profile Result: 9105 (10000 [ms], 9105)
    Target Profile Result: 8910 (10000 [ms], 8910)
    Profile Result: 1.97 %
    -- Packet Loss --
    StationId: 1  SendTo(Lost/Total (ratio)):(  0 / 0 (0.00%)))  Multicast: 0
    StationId: 2  SendTo(Lost/Total (ratio)):(  0 / 0 (0.00%)))  Multicast: 0
    -- ThreadStreamManager --
    ReceivePacket: 10
    SendPacket:    322
    

Profiling Memory Usage

  1. In the ProfilingTest_Common.h file, set ENABLE_CPU_PROFILING, ENABLE_MEMORY_PROFILING, and ENABLE_WATERMARK to 1, set USE_MULTIUNITHEAP to 0, and then build the program.
  2. When you run the program, the profiler counts the number of one-millisecond sleeps performed within a 10-second interval. Over the next 10 seconds, it counts the number of one-millisecond sleeps performed while processing commands not related to communication.
  3. The following information appears in the log output of the debugger.
    Press A: Start automatch
    Press B: Logout
    Press Y: Logout and NEX Finalize // Only appears during Internet communication.
    
    Press the A Button to perform matchmaking.
    The console that first started matchmaking becomes the host. After that, consoles on which the A Button (for Internet communication) or the Y Button (for local communication) is pressed can perform matchmaking as clients until the number of devices set in the GAME_PARTICIPANTS_NUM session macro is reached.

    After the number of systems set in GAME_PARTICIPANTS_NUM have been matched, the program transitions to the profiling sequence automatically.
    Press the A Button during matchmaking to transition to the profiling sequence with the number of devices that have been matched so far.
  4. The profiling sequence starts by outputting the current settings to the debugger log.
  5. After the following debugger output is written to the log, press START on any of the consoles to start communications.
    Press A : Start profiling for game loop
    Press X : Print watermark result
    Press R : Print memory report
    Press START: Start (unreliable/reliable) communication
    

    When ENABLE_RELIABLE_COMMUNICATION is enabled, Reliable communication begins automatically. When ENABLE_UNRELIABLE_COMMUNICATION is enabled, Unreliable communication begins automatically.
    After communication starts, press the A Button to measure the CPU load. This provides a measurement of the Pia library's buffer usage.
  6. After the CPU results are output, press the X and R Buttons to output the peak buffer and memory usage.
    What is output at this time is the memory usage set as the initial value for the program.
  7. On the console used for profiling, press the B Button to stop matchmaking. Next, reinitialize the Pia library by pressing the Y Button when you are using Internet communication, and the B Button when you are using local communication. This practice optimizes Pia's memory using the buffer usage that was just measured.
    The debugger then outputs the NEX memory usage to the log.
    FinalizeRuntimeMemory:Nex memory usage: Now memory usage:0, Max memory usage:241888 / 1099776
    
    If you profile using a NetZ module built with ENABLE_NEX_NETZ set to 1, this value is the memory usage.
    If you profile Internet communication using Pia with ENABLE_NEX_NETZ and ENABLE_LOCAL set to 0 during the build, this value becomes the amount of NEX memory used when Pia communicates with the server. The sum of this value and the value that results the next time you profile optimized Pia memory use is the amount of memory used.
  8. Repeat steps 2 through 7 once more.
  9. The debugger outputs the peak buffer and memory usage with the memory-optimized version of the Pia library to the log. The output appears as follows.
    Watermark: <SendThreadStream buffer num>   max: 4, min: 0, latest: 0, Updates: 3654
    Watermark: <ReceiveThreadStream buffer num>   max: 8, min: 0, latest: 0, Updates: 1840
    Watermark: <StationProtocolReliable send buffer num>   max: 3, min: 0, latest: 3, Updates: 166
    Watermark: <StationProtocolReliable receive buffer num>   max: 0, min: 0, latest: 0, Updates: 67
    Send: 916, Recv: 719
    Pia memory usage: 435160 bytes. (424 KB)
    
  10. If you are profiling local communication in the Pia library, the value output in step 9 is the memory usage of the Pia library. If you are profiling Internet communication, perform step 7 again. The total of the Pia and NEX memory usage is the memory usage of the Pia library.