Getting Started¶
This short guide explains how to get started with PSYGIG Triage SDK. Before you can start instrumenting your applications, you need to download and install the latest version of the SDK.
PSYGIG Triage SDK Download/Installation Guide
Quick Start - using psymon
¶
Without modifying your existing source code, you can instantly add instrumentation and crash reporting capabilities
to your application by using the psymon
script to run your program. For example:
psymon -c "/path/to/your/app --arg1 --arg2 --arg3"
By default, psymon
enables all instrumentation capabilities. To enable selective instrumentation, specify the
instrumentation class with the appropriate option.
See psymon man page for a complete list of options.
Sample JSON output generated by psymon
注釈
psymon
is a work-in-progress.
Please if you are interested in beta-testing this feature.
Advanced Setup - Building your application with libpsygig
¶
The rich feature set of the PSYGIG Triage SDK can be fully exploited via the PSYGIG Triage SDK API. The API can be accessed
by including a single header file and linking to the libpsygig
shared library.
Basic example: Collecting system resource metrics¶
This example enables period polling of system resource metrics and saves the data to a JSON file.
basic-example source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include "psygigsdk.h"
int main(int argc, char **argv)
{
psygig_cfg cfg; // psygig agent configuration
psygig_agent_handle pah; // handle to psygig agent
psygig_sink_cfg sink; // output sink configuration
int rc;
const char* RESULTS_DIR = "results"; // directory to store the output JSON file
const char* RESULTS_BASE = "sys"; // base filename of the output JSON file
// Initialize agent
rc = psygig_agent_init(&pah, &cfg); // Ignore return code for simplicity sake
// Add a file sink for logging metrics to JSON
sink.type = PSYGIG_SINK_FILE;
sink.format = PSYGIG_DATA_FORMAT_JSON;
strcpy(sink.file.dir,RESULTS_DIR);
strcpy(sink.file.basename,RESULTS_BASE);
rc = psygig_agent_add_sink(pah, &sink); // Ignore return code for simplicity sake
// Enable polling of system resources every 500ms
rc = psygig_metric_enable_poll_system_resources(pah, 500);
// Let it run for 15 seconds
startts = time(NULL);
endts = startts + 15;
while (time(NULL) < endts)
{
millisleep(1000);
}
// We are done. Cleanup PSYGIG Agent.
rc = psygig_agent_cleanup(&pah);
return 0;
}
|
Building basic-example using gcc
The compiler must be able to find the psygigsdk.h header and the
libpsygig
shared library. With GCC, use the -I
and -L
options respectively to achieve this.
For basic-example, the compilation command is:
gcc -I /opt/psyiage/include -L /opt/psyiage/lib -lpsygig basic-example.c -o basic-example
Assuming PSYGIG Triage SDK was installed under /opt/psyiage
Building basic-example using cmake
A better alternative for building programs using PSYGIG Triage SDK is to use cmake
, especially if you are
developing for several platforms. Assuming the following folder structure:
basic-example\
|- src\
| |- basic-example.c
|- CMakeLists.txt
CMakeLists.txt file
1 2 3 4 5 6 7 8 9 10 11 | cmake_minimum_required(VERSION 3.1)
project(basic-example)
# Add the source files to the binary
add_executable(basic-example src/basic-example.c)
# Add the psygigsdk.h folder to include path
target_include_directories(basic-example PRIVATE /opt/psyiage/include)
# Link the libpsygig.so folder to the binary
target_link_libraries(basic-example /opt/psyiage/lib/libpsygig.so)
|
Assuming PSYGIG Triage SDK was installed under /opt/psyiage
The following sequence of commands create a directory for building (avoid building in the source folder), builds
basic-example with cmake
and then runs the program:
mkdir build
cd build
cmake ..
make
./basic-example