For more information visit CMX on https://cern.ch/cmx and/or https://wikis.cern.ch/display/MW/CMX
The following function are realtime compatible:
For other functions please refer to the function documentation.
Values are referenced by so called value-handles. The validity of a value-handle cannot be ensured by the semantics of the programming language. The Developer have to be aware of the possibility that a value-handle is invalid and handle the respective error code E_CMX_INVALID_HANDLE. Particularly with regard to reading CMX SHM components that are managed by other processes.
All functions except cmx_shm_create(), cmx_shm_open(), cmx_shm_open_ro() and cmx_shm_create() are thread-safe.
The functions cmx_shm_create(), cmx_shm_open(), cmx_shm_open_ro() and cmx_shm_create() are only thread-safe if every function operates with a different cmx_shm_t datastructure.
After you have configured your compiler and linker settings (see the code examples for that), you can go into your code and start making use of CMX.
The first step is to register your process with CMX. The call `cmx_process_update()` will update (and create if necessary) a CMX Component with information about the running process.
Currently this includes the process name, hostname, manifest and some resource usage information.
#include <cmw-cmx/process.h> int main(..) { // Create the CMX Component for the process cmx_process_update(); while (1) { sleep(10); // do some work // Consider calling cmx_process_update() once in a while // to update the process metrics. cmx_process_update(); } }
Before you can update metrics you need to assign meaningful names (see xref:naming[Naming conventions]) and register them in CMX.
#include <cmw-cmx/shm.h> ... // Create the CMX Component cmx_shm * cmx_shm_ptr = cmx_shm_get(getpid(), "TestComponent"); // assert cmx_shm_ptr != NULL // Add Values int metric_no_gets = cmx_shm_add_value_single(cmx_shm_ptr, CMX_TYPE_INT64, "no_of_gets"); // assert ! (metric_no_gets < 0) int metric_no_sets = cmx_shm_add_value_single(cmx_shm_ptr, CMX_TYPE_INT64, "no_of_sets"); // assert ! (metric_no_sets < 0)
We can now set or update the values of the specified metrics. The relevant timestamps (`mtime`) will be automatically updated.
... // Set Values cmx_shm_value value; value._int64 = 1234; cmx_shm_set_value_single(cmx_shm_ptr, metric_no_gets, CMX_TYPE_INT64, &value); // returns E_CMX_SUCCESS or errorcode value._int64 = 5678; cmx_shm_set_value_single(cmx_shm_ptr, metric_no_sets, CMX_TYPE_INT64, &value); // returns E_CMX_SUCCESS or errorcode