Previous Topic

Next Topic

Book Contents

Book Index

Profiler API

The Profiler API provides methods to trigger profiling actions on certain stages of a program's execution. For example, you can start the memory or the CPU profiling at the beginning of a method and stop the profiling session at the method's end.

The commands for triggering profiling actions are part of the com.prosyst.profiler.api.ProfilerAPI.IProfilerCommands interface. They are passed as parameters to the prof_execute_cmd method part of the com.prosyst.profiler.api.ProfilerAPI class. The method accepts four arguments – the first one is the profiling command and the next three – its parameters. For example, you can start memory profiling and take a heap snapshot:

ProfilerAPI.prof_execute_cmd (IProfilerCommands.PROF_CMD_MEM_ON, IProfilerCommands.PROF_CMD_DUMP_HEAP, 0, 0);

Extended API Commands

The extended API commands are passed to the profiler frontend and include commands for controlling a mark and for exporting profiling data. They are passed as argument to the IProfilerCommands.PROF_CMD_API command. For example, to start a mark, write the following lines in the application's code:

ProfilerAPI.prof_execute_cmd(IProfilerCommands.PROF_CMD_MEM_ON, 0, 0, 0); ProfilerAPI.prof_execute_cmd (IProfilerCommands.PROF_CMD_API, IProfilerCommands.PROF_API_EXT_MARK_START, 0, 0);

The first line starts the memory profiling and the second one starts a mark.

Connecting to a Remote VM

To connect to a remote VM, call the prof_connect method of the ProfilerAPI class. It requires a host and port to connect to. After a connection has been established successfully, you can freely call any of the commands that will trigger profiling actions.