Actual source code: tool.h

      1: // Copyright (c) 2019 University of Oregon
      2: // Distributed under the BSD Software License
      3: // (See accompanying file LICENSE.txt)

      5: #pragma once
      6: #include <stdint.h>

      8: /****************************************************************************/
      9: /* Declare the structures that a tool should use to return performance data. */
     10: /****************************************************************************/

     12: typedef struct ps_tool_timer_data
     13: {
     14:     unsigned int num_timers;
     15:     unsigned int num_threads;
     16:     unsigned int num_metrics;
     17:     char **timer_names;
     18:     char **metric_names;
     19:     double *values;
     20: } ps_tool_timer_data_t;

     22: typedef struct ps_tool_counter_data
     23: {
     24:     unsigned int num_counters;
     25:     unsigned int num_threads;
     26:     char **counter_names;
     27:     double *num_samples;
     28:     double *value_total;
     29:     double *value_min;
     30:     double *value_max;
     31:     double *value_sumsqr;
     32: } ps_tool_counter_data_t;

     34: typedef struct ps_tool_metadata
     35: {
     36:     unsigned int num_values;
     37:     char **names;
     38:     char **values;
     39: } ps_tool_metadata_t;

     41: /****************************************************************************/
     42: /* Declare the typedefs of the functions that a tool should implement. */
     43: /****************************************************************************/

     45: /* Logistical functions */
     46: typedef void  (*ps_initialize_t)(void);
     47: typedef void  (*ps_finalize_t)(void);
     48: typedef void  (*ps_register_thread_t)(void);
     49: typedef void  (*ps_dump_data_t)(void);
     50: /* Data entry functions */
     51: typedef void* (*ps_timer_create_t)(const char *);
     52: typedef void  (*ps_timer_start_t)(const void *);
     53: typedef void  (*ps_timer_stop_t)(const void *);
     54: typedef void  (*ps_set_parameter_t)(const char *, int64_t);
     55: typedef void  (*ps_dynamic_phase_start_t)(const char *, int);
     56: typedef void  (*ps_dynamic_phase_stop_t)(const char *, int);
     57: typedef void* (*ps_create_counter_t)(const char *);
     58: typedef void  (*ps_sample_counter_t)(const void *, double);
     59: typedef void  (*ps_set_metadata_t)(const char *, const char *);
     60: /* Data Query Functions */
     61: typedef void  (*ps_get_timer_data_t)(ps_tool_timer_data_t *);
     62: typedef void  (*ps_get_counter_data_t)(ps_tool_counter_data_t *);
     63: typedef void  (*ps_get_metadata_t)(ps_tool_metadata_t *);
     64: typedef void  (*ps_free_timer_data_t)(ps_tool_timer_data_t *);
     65: typedef void  (*ps_free_counter_data_t)(ps_tool_counter_data_t *);
     66: typedef void  (*ps_free_metadata_t)(ps_tool_metadata_t *);

     68: /****************************************************************************/
     69: /* Declare the structure used to register a tool */
     70: /****************************************************************************/

     72: typedef struct ps_plugin_data {
     73:     char * tool_name;
     74:     /* Logistical functions */
     75:     ps_initialize_t initialize;
     76:     ps_finalize_t finalize;
     77:     ps_register_thread_t register_thread;
     78:     ps_dump_data_t dump_data;
     79:     /* Data entry functions */
     80:     ps_timer_create_t timer_create;
     81:     ps_timer_start_t timer_start;
     82:     ps_timer_stop_t timer_stop;
     83:     ps_set_parameter_t set_parameter;
     84:     ps_dynamic_phase_start_t dynamic_phase_start;
     85:     ps_dynamic_phase_stop_t dynamic_phase_stop;
     86:     ps_create_counter_t create_counter;
     87:     ps_sample_counter_t sample_counter;
     88:     ps_set_metadata_t set_metadata;
     89:     /* Data Query Functions */
     90:     ps_get_timer_data_t get_timer_data;
     91:     ps_get_counter_data_t get_counter_data;
     92:     ps_get_metadata_t get_metadata;
     93:     ps_free_timer_data_t free_timer_data;
     94:     ps_free_counter_data_t free_counter_data;
     95:     ps_free_metadata_t free_metadata;
     96: } ps_plugin_data_t;

     98: /****************************************************************************/
     99: /* Declare the register/deregister weak symbols (implemented by the plugin API
    100:  * for the registration process */
    101: /****************************************************************************/

    103: typedef int  (*ps_register_t)(ps_plugin_data_t *);
    104: typedef void (*ps_deregister_t)(int);

    106: #ifdef __cplusplus
    107: extern "C" {
    108: #endif

    110: #ifdef __linux__
    111: extern __attribute__((weak)) int  ps_register_tool(ps_plugin_data_t * tool);
    112: extern __attribute__((weak)) void ps_deregister_tool(int tool_id);
    113: #else /* use _WIN32 or _WIN64 */
    114: extern int  ps_register_tool(ps_plugin_data_t * tool);
    115: extern void ps_deregister_tool(int tool_id);
    116: #endif

    118: #ifdef __cplusplus
    119: }
    120: #endif