1 /************************************************************************ 2 Copyright (c) 2015, The Linux Foundation. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions are 6 met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above 10 copyright notice, this list of conditions and the following 11 disclaimer in the documentation and/or other materials provided 12 with the distribution. 13 * Neither the name of The Linux Foundation nor the names of its 14 contributors may be used to endorse or promote products derived 15 from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 ************************************************************************/ 29 30 /** 31 * @file datatop_interface.h 32 * @brief Declares functions held within datatop.c and datatop_helpers.c 33 * 34 * Declares functions which are held within datatop.c and datatop_helpers.c. 35 * Also defines data structures used for storing data gathered during polling 36 * such as datapoint names, values, and prefixes along with other valuable 37 * information. 38 */ 39 40 #ifndef DATATOP_INTERFACE_H 41 #define DATATOP_INTERFACE_H 42 43 #include <inttypes.h> 44 #include "datatop_linked_list.h" 45 46 #define DTOP_ULONG 0 47 #define DTOP_LONG 1 48 #define DTOP_UINT 2 49 #define DTOP_INT 3 50 #define DTOP_UCHAR 4 51 #define DTOP_CHAR 5 52 #define DTOP_STR 6 53 54 #define FILE_ERROR -1 55 #define FILE_SUCCESS 0 56 #define SKIP 1 57 #define DO_NOT_SKIP 0 58 #define POPULATED 1 59 #define NOT_POPULATED 0 60 61 #define DTOP_POLL_OK 0 62 #define DTOP_POLL_IO_ERR 1 63 #define NOT_CHECKED 0 64 65 #define QUIT 1 66 67 #define DTOP_DP_MAX_STR_LEN 32 68 69 #define DTOP_DP_HFILL .initial_data_populated = NOT_POPULATED, \ 70 .skip = 0 71 72 /** 73 * @struct dtop_data_union 74 * @brief Provides the type for dp value. 75 */ 76 union dtop_data_union { 77 uint64_t d_ulong; 78 int64_t d_long; 79 uint32_t d_uint; 80 int32_t d_int; 81 uint8_t d_uchar; 82 int8_t d_char; 83 char d_str[DTOP_DP_MAX_STR_LEN]; 84 }; 85 86 /** 87 * @struct dtop_data_point 88 * @brief Individual datapoint in a file. 89 * 90 * @var dtop_data_point::name 91 * Stores the datapoints name. 92 * @var dtop_data_point::prefix 93 * Stores the individual prefix for the dp. 94 * @var dtop_data_point::type 95 * Type dp value is, see definitions. 96 * @var dtop_data_point::initial_data 97 * Holds the initial value of the dp the first time it was polled. 98 * @var dtop_data_point::initial_data_populated 99 * Variable that is changed when initial_data is populated. 100 * @var dtop_data_point::data 101 * Value of the dp at the most recent poll. 102 */ 103 struct dtop_data_point { 104 char *name; 105 char *prefix; 106 107 /* Results of polling */ 108 char type; 109 union dtop_data_union initial_data; 110 char initial_data_populated; 111 union dtop_data_union data; 112 113 /* Skip on subsequent polls */ 114 char skip; 115 }; 116 117 /** 118 * @struct dtop_data_point_gatherer 119 * @brief Struct used to hold data about a set of collected data. 120 * 121 * @var dtop_data_point_gatherer::prefix 122 * Name of directory which data is collected from. 123 * @var dtop_data_point_gatherer::file 124 * File path that data is collected from. 125 * @var dtop_data_point_gatherer::poll 126 * Poll function takes a dtop_data_point_gatherer as parameter. 127 * int equals, DTOP_POLL_IO_ERR - Poll of dpg unsuccessful, or 128 * DTOP_POLL_OK - Poll of dpg successful. 129 * @var dtop_data_point_gatherer::data_points 130 * Pointer to a dtop_data_point struct (dp). 131 * @var dtop_data_point_gatherer::data_points_len 132 * Number of elements in the array of dp's the dpg accesses. 133 */ 134 struct dtop_data_point_gatherer { 135 char *prefix; 136 char *file; 137 int (*poll)(struct dtop_data_point_gatherer *dpg); 138 void (*deconstruct)(struct dtop_data_point_gatherer *dpg); 139 140 struct dtop_data_point *data_points; 141 int data_points_len; 142 143 /* Private data */ 144 void *priv; 145 }; 146 147 void dtop_register(struct dtop_data_point_gatherer *dpg); 148 void dtop_store_dp(struct dtop_data_point *dp, const char *str); 149 void dtop_print_dpg(struct dtop_data_point_gatherer *dpg); 150 void get_snapshot_diff(struct dtop_linked_list *dpg_list); 151 void dtop_print_snapshot_diff(struct dtop_linked_list *dpg_list); 152 void dtop_poll(struct dtop_linked_list *dpg_list); 153 int dtop_print_time_at_poll(FILE *fw); 154 int dtop_print_dpg_names_csv(struct dtop_data_point_gatherer *dpg, FILE *fw); 155 int dtop_write_pollingdata_csv(struct dtop_linked_list *dpg_list, FILE *fw); 156 void dtop_reset_dp_initial_values(struct dtop_linked_list *dpg_list); 157 void deconstruct_dpgs(struct dtop_linked_list *dpg_list); 158 int dtop_print_system_snapshot(char *file); 159 160 161 #ifndef HAVE_STRL_FUNCTIONS 162 #define strlcpy(X,Y,Z) strcpy(X,Y) 163 #define strlcat(X,Y,Z) strcat(X,Y) 164 #endif /* HAVE_STRL_FUNCTIONS */ 165 166 #endif /* DATATOP_INTERFACE_H */ 167