Skip to content

Profiling and Benchmarking

fitchn edited this page Jul 7, 2020 · 7 revisions

The molecool simulation engine is highly optimized for fast computation speed and usage of numerous threads on multi-processor platforms. In order to facilitate performance monitoring and to determine which parts of the codebase could benefit the most from further optimization, molecool contains profiling tools for timing functions and scopes, and gathering statistics on the measured timings. These same tools are available for usage by client applications/simulations.

Using the profiling tools

In a way, most of the work is done for you when you include the following header

#include "molecool.h"

in your user/client application/simulation. After that, profiling can be enabled using define statements in molecool/src/debug/Profiler.h. Setting #DEFINE MC_PROFILE 1 enables statistics to be gathered for individual functions/scopes, including how many times a particular section of code was run, the average time it took to execute, and more. Further defining #DEFINE MC_PROFILE_VERBOSE 1 instructs the profiling tools to save information from every profiling/timing event in a json file, which can be read and visualized using Google's 'tracing' tool available by, e.g., chrome://tracing into Chrome's search bar. Note that the verbose data generation can quickly lead to large file sizes.

Once enabled with the preprocessor define statements, a profiling session begins by implementing the following macro in your code

MC_PROFILE_BEGIN_SESSION("name");

where the session is given a unique name. The generated statistics file (.txt) will be named profile_name_stats.txt. During an active session, data is collected on individual functions or scopes by implementing one of the following macros in your code:

MC_PROFILE_FUNCTION();     // automatically extracts containing function scope + name for reporting
MC_PROFILE_SCOPE("name");  // reporting for a scope profile uses a user-specified name

The profiling session is ended, and the statistics file (and optional detailed json output file) is generated, when the macro

MC_PROFILE_END_SESSION();

is called. Only one session can be active at any one time, starting a new session automatically ends any previously-active one.

Clone this wiki locally