|
|
|||
Warning, file /include/pmix/src/util/pmix_timings.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (C) 2014 Artem Polyakov <artpol84@gmail.com> 0003 * Copyright (c) 2014-2020 Intel, Inc. All rights reserved. 0004 * Copyright (c) 2015 Research Organization for Information Science 0005 * and Technology (RIST). All rights reserved. 0006 * Copyright (c) 2021-2025 Nanook Consulting All rights reserved. 0007 * $COPYRIGHT$ 0008 * 0009 * Additional copyrights may follow 0010 * 0011 * $HEADER$ 0012 */ 0013 0014 #ifndef PMIX_UTIL_TIMING_H 0015 #define PMIX_UTIL_TIMING_H 0016 0017 #include "src/include/pmix_config.h" 0018 0019 #include "src/class/pmix_list.h" 0020 0021 #if PMIX_ENABLE_TIMING 0022 0023 # define PMIX_TIMING_DESCR_MAX 1024 0024 # define PMIX_TIMING_BUFSIZE 32 0025 # define PMIX_TIMING_OUTBUF_SIZE (10 * 1024) 0026 # define PMIX_TIMING_STR_LEN 1024 0027 0028 typedef enum { 0029 PMIX_TIMING_TRACE, 0030 PMIX_TIMING_INTDESCR, 0031 PMIX_TIMING_INTBEGIN, 0032 PMIX_TIMING_INTEND 0033 } pmix_event_type_t; 0034 0035 typedef struct { 0036 pmix_list_item_t super; 0037 int fib; 0038 pmix_event_type_t type; 0039 const char *func; 0040 const char *file; 0041 int line; 0042 double ts, ts_ovh; 0043 char descr[PMIX_TIMING_DESCR_MAX]; 0044 int id; 0045 } pmix_timing_event_t; 0046 0047 typedef double (*get_ts_t)(void); 0048 0049 typedef struct pmix_timing_t { 0050 int next_id_cntr; 0051 // not thread safe! 0052 // The whole implementation is not thread safe now 0053 // since it is supposed to be used in service 0054 // thread only. Fix in the future or now? 0055 int current_id; 0056 pmix_list_t *events; 0057 pmix_timing_event_t *buffer; 0058 size_t buffer_offset, buffer_size; 0059 get_ts_t get_ts; 0060 } pmix_timing_t; 0061 0062 typedef struct { 0063 pmix_timing_t *t; 0064 pmix_timing_event_t *ev; 0065 int errcode; 0066 } pmix_timing_prep_t; 0067 0068 /* Pass down our namespace and rank for pretty-print purposes */ 0069 PMIX_EXPORT void pmix_init_id(char *nspace, int rank); 0070 0071 /** 0072 * Initialize timing structure. 0073 * 0074 * @param t pointer to the timing handler structure 0075 */ 0076 PMIX_EXPORT void pmix_timing_init(pmix_timing_t *t); 0077 0078 /** 0079 * Prepare timing event, do all printf-like processing. 0080 * Should not be directly used - for service purposes only. 0081 * 0082 * @param t pointer to the timing handler structure 0083 * @param fmt printf-like format 0084 * @param ... other parameters that should be converted to string representation 0085 * 0086 * @retval partly filled pmix_timing_prep_t structure 0087 */ 0088 PMIX_EXPORT pmix_timing_prep_t pmix_timing_prep_ev(pmix_timing_t *t, const char *fmt, ...); 0089 0090 /** 0091 * Prepare timing event, ignore printf-like processing. 0092 * Should not be directly used - for service purposes only. 0093 * 0094 * @param t pointer to the timing handler structure 0095 * @param fmt printf-like format 0096 * @param ... other parameters that should be converted to string representation 0097 * 0098 * @retval partly filled pmix_timing_prep_t structure 0099 */ 0100 PMIX_EXPORT pmix_timing_prep_t pmix_timing_prep_ev_end(pmix_timing_t *t, const char *fmt, ...); 0101 0102 /** 0103 * Enqueue timing event into the list of events in handler 't'. 0104 * 0105 * @param p result of pmix_timing_prep_ev 0106 * @param func function name where event occurs 0107 * @param file file name where event occurs 0108 * @param line line number in the file 0109 * 0110 * @retval 0111 */ 0112 PMIX_EXPORT void pmix_timing_add_step(pmix_timing_prep_t p, const char *func, const char *file, 0113 int line); 0114 0115 /** 0116 * Enqueue the description of the interval into a list of events 0117 * in handler 't'. 0118 * 0119 * @param p result of pmix_timing_prep_ev 0120 * @param func function name where event occurs 0121 * @param file file name where event occurs 0122 * @param line line number in the file 0123 * 0124 * @retval id of event interval 0125 */ 0126 PMIX_EXPORT int pmix_timing_descr(pmix_timing_prep_t p, const char *func, const char *file, 0127 int line); 0128 0129 /** 0130 * Enqueue the beginning of timing interval that already has the 0131 * description and assigned id into the list of events 0132 * in handler 't'. 0133 * 0134 * @param p result of pmix_timing_prep_ev 0135 * @param func function name where event occurs 0136 * @param file file name where event occurs 0137 * @param line line number in the file 0138 * 0139 * @retval 0140 */ 0141 PMIX_EXPORT void pmix_timing_start_id(pmix_timing_t *t, int id, const char *func, const char *file, 0142 int line); 0143 0144 /** 0145 * Enqueue the end of timing interval that already has 0146 * description and assigned id into the list of events 0147 * in handler 't'. 0148 * 0149 * @param p result of pmix_timing_prep_ev 0150 * @param func function name where event occurs 0151 * @param file file name where event occurs 0152 * @param line line number in the file 0153 * 0154 * @retval 0155 */ 0156 PMIX_EXPORT void pmix_timing_end(pmix_timing_t *t, int id, const char *func, const char *file, 0157 int line); 0158 0159 /** 0160 * Enqueue both description and start of timing interval 0161 * into the list of events and assign its id. 0162 * 0163 * @param p result of pmix_timing_prep_ev 0164 * @param func function name where event occurs 0165 * @param file file name where event occurs 0166 * @param line line number in the file 0167 * 0168 * @retval interval id 0169 */ 0170 static inline int pmix_timing_start_init(pmix_timing_prep_t p, const char *func, const char *file, 0171 int line) 0172 { 0173 int id = pmix_timing_descr(p, func, file, line); 0174 if (id < 0) 0175 return id; 0176 pmix_timing_start_id(p.t, id, func, file, line); 0177 return id; 0178 } 0179 0180 /** 0181 * The wrapper that is used to stop last measurement in PMIX_TIMING_MNEXT. 0182 * 0183 * @param p result of pmix_timing_prep_ev 0184 * @param func function name where event occurs 0185 * @param file file name where event occurs 0186 * @param line line number in the file 0187 * 0188 * @retval interval id 0189 */ 0190 PMIX_EXPORT void pmix_timing_end_prep(pmix_timing_prep_t p, const char *func, const char *file, 0191 int line); 0192 0193 /** 0194 * Report all events that were enqueued in the timing handler 't'. 0195 * - if fname == NULL the output will be done using pmix_output and 0196 * each line will be prefixed with "prefix" to ease grep'ing. 0197 * - otherwise the corresponding file will be used for output in "append" mode 0198 * WARRNING: not all filesystems provide enough support for that feature, some records may 0199 * disappear. 0200 * 0201 * @param t timing handler 0202 * @param account_overhead consider malloc overhead introduced by timing code 0203 * @param prefix prefix to use when no fname was specified to ease grep'ing 0204 * @param fname name of the output file (may be NULL) 0205 * 0206 * @retval PMIX_SUCCESS On success 0207 * @retval PMIX_ERROR or PMIX_ERR_OUT_OF_RESOURCE On failure 0208 */ 0209 PMIX_EXPORT pmix_status_t pmix_timing_report(pmix_timing_t *t, char *fname); 0210 0211 /** 0212 * Report all intervals that were enqueued in the timing handler 't'. 0213 * - if fname == NULL the output will be done using pmix_output and 0214 * each line will be prefixed with "prefix" to ease grep'ing. 0215 * - otherwise the corresponding file will be used for output in "append" mode 0216 * WARRNING: not all filesystems provide enough support for that feature, some records may 0217 * disappear. 0218 * 0219 * @param t timing handler 0220 * @param account_overhead consider malloc overhead introduced by timing code 0221 * @param fname name of the output file (may be NULL) 0222 * 0223 * @retval PMIX_SUCCESS On success 0224 * @retval PMIX_ERROR or PMIX_ERR_OUT_OF_RESOURCE On failure 0225 */ 0226 PMIX_EXPORT pmix_status_t pmix_timing_deltas(pmix_timing_t *t, char *fname); 0227 0228 /** 0229 * Release all memory allocated for the timing handler 't'. 0230 * 0231 * @param t timing handler 0232 * 0233 * @retval 0234 */ 0235 PMIX_EXPORT void pmix_timing_release(pmix_timing_t *t); 0236 0237 /** 0238 * Macro for passing down process id - compiled out 0239 * when configured without --enable-timing 0240 */ 0241 # define PMIX_TIMING_ID(n, r) pmix_timing_id((n), (r)); 0242 0243 /** 0244 * Main macro for use in declaring pmix timing handler; 0245 * will be "compiled out" when PMIX is configured without 0246 * --enable-timing. 0247 * 0248 */ 0249 # define PMIX_TIMING_DECLARE(t) \ 0250 pmix_timing_t t; /* need semicolon here to avoid warnings when not enabled */ 0251 0252 /** 0253 * Main macro for use in declaring external pmix timing handler; 0254 * will be "compiled out" when PMIX is configured without 0255 * --enable-timing. 0256 * 0257 */ 0258 # define PMIX_TIMING_DECLARE_EXT(x, t) \ 0259 x extern pmix_timing_t t; /* need semicolon here to avoid warnings when not enabled */ 0260 0261 /** 0262 * Main macro for use in initializing pmix timing handler; 0263 * will be "compiled out" when PMIX is configured without 0264 * --enable-timing. 0265 * 0266 * @see pmix_timing_init() 0267 */ 0268 # define PMIX_TIMING_INIT(t) pmix_timing_init(t) 0269 0270 /** 0271 * Macro that enqueues event with its description to the specified 0272 * timing handler; 0273 * will be "compiled out" when PMIX is configured without 0274 * --enable-timing. 0275 * 0276 * @see pmix_timing_add_step() 0277 */ 0278 # define PMIX_TIMING_EVENT(x) \ 0279 pmix_timing_add_step(pmix_timing_prep_ev x, __FUNCTION__, __FILE__, __LINE__) 0280 0281 /** 0282 * MDESCR: Measurement DESCRiption 0283 * Introduce new timing measurement with string description for the specified 0284 * timing handler; 0285 * will be "compiled out" when PMIX is configured without 0286 * --enable-timing. 0287 * 0288 * @see pmix_timing_descr() 0289 */ 0290 # define PMIX_TIMING_MDESCR(x) \ 0291 pmix_timing_descr(pmix_timing_prep_ev x, __FUNCTION__, __FILE__, __LINE__) 0292 0293 /** 0294 * MSTART_ID: Measurement START by ID. 0295 * Marks the beginning of the measurement with ID=id on the 0296 * specified timing handler; 0297 * will be "compiled out" when PMIX is configured without 0298 * --enable-timing. 0299 * 0300 * @see pmix_timing_start_id() 0301 */ 0302 # define PMIX_TIMING_MSTART_ID(t, id) \ 0303 pmix_timing_start_id(t, id, __FUNCTION__, __FILE__, __LINE__) 0304 0305 /** 0306 * MSTART: Measurement START 0307 * Introduce new timing measurement conjuncted with its start 0308 * on the specified timing handler; 0309 * will be "compiled out" when PMIX is configured without 0310 * --enable-timing. 0311 * 0312 * @see pmix_timing_start_init() 0313 */ 0314 # define PMIX_TIMING_MSTART(x) \ 0315 pmix_timing_start_init(pmix_timing_prep_ev x, __FUNCTION__, __FILE__, __LINE__) 0316 0317 /** 0318 * MSTOP: STOP Measurement 0319 * Finishes the most recent measurement on the specified timing handler; 0320 * will be "compiled out" when PMIX is configured without 0321 * --enable-timing. 0322 * 0323 * @see pmix_timing_end() 0324 */ 0325 # define PMIX_TIMING_MSTOP(t) pmix_timing_end(t, -1, __FUNCTION__, __FILE__, __LINE__) 0326 0327 /** 0328 * MSTOP_ID: STOP Measurement with ID=id. 0329 * Finishes the measurement with give ID on the specified timing handler; 0330 * will be "compiled out" when PMIX is configured without 0331 * --enable-timing. 0332 * 0333 * @see pmix_timing_end() 0334 */ 0335 # define PMIX_TIMING_MSTOP_ID(t, id) pmix_timing_end(t, id, __FUNCTION__, __FILE__, __LINE__) 0336 0337 /** 0338 * MNEXT: start NEXT Measurement 0339 * Convenient macro, may be implemented with the sequence of three previously 0340 * defined macros: 0341 * - finish current measurement (PMIX_TIMING_MSTOP); 0342 * - introduce new timing measurement (PMIX_TIMING_MDESCR); 0343 * - starts next measurement (PMIX_TIMING_MSTART_ID) 0344 * on the specified timing handler; 0345 * will be "compiled out" when PMIX is configured without 0346 * --enable-timing. 0347 * 0348 * @see pmix_timing_start_init() 0349 */ 0350 # define PMIX_TIMING_MNEXT(x) \ 0351 (pmix_timing_end_prep(pmix_timing_prep_ev_end x, __FUNCTION__, __FILE__, __LINE__), \ 0352 pmix_timing_start_init(pmix_timing_prep_ev x, __FUNCTION__, __FILE__, __LINE__)) 0353 0354 /** 0355 * The macro for use in reporting collected events with absolute values; 0356 * will be "compiled out" when PMIX is configured without 0357 * --enable-timing. 0358 * 0359 * @param enable flag that enables/disables reporting. Used for fine-grained timing. 0360 * @see pmix_timing_report() 0361 */ 0362 # define PMIX_TIMING_REPORT(enable, t) \ 0363 { \ 0364 if (enable) { \ 0365 pmix_timing_report(t, pmix_timing_output); \ 0366 } \ 0367 } 0368 0369 /** 0370 * The macro for use in reporting collected events with relative times; 0371 * will be "compiled out" when PMIX is configured without 0372 * --enable-timing. 0373 * 0374 * @param enable flag that enables/disables reporting. Used for fine-grained timing. 0375 * @see pmix_timing_deltas() 0376 */ 0377 # define PMIX_TIMING_DELTAS(enable, t) \ 0378 { \ 0379 if (enable) { \ 0380 pmix_timing_deltas(t, pmix_timing_output); \ 0381 } \ 0382 } 0383 0384 /** 0385 * Main macro for use in releasing allocated resources; 0386 * will be "compiled out" when PMIX is configured without 0387 * --enable-timing. 0388 * 0389 * @see pmix_timing_release() 0390 */ 0391 # define PMIX_TIMING_RELEASE(t) pmix_timing_release(t) 0392 0393 #else 0394 0395 # define PMIX_TIMING_ID(n, r) 0396 0397 # define PMIX_TIMING_DECLARE(t) 0398 0399 # define PMIX_TIMING_DECLARE_EXT(x, t) 0400 0401 # define PMIX_TIMING_INIT(t) 0402 0403 # define PMIX_TIMING_EVENT(x) 0404 0405 # define PMIX_TIMING_MDESCR(x) 0406 0407 # define PMIX_TIMING_MSTART_ID(t, id) 0408 0409 # define PMIX_TIMING_MSTART(x) 0410 0411 # define PMIX_TIMING_MSTOP(t) 0412 0413 # define PMIX_TIMING_MSTOP_ID(t, id) 0414 0415 # define PMIX_TIMING_MNEXT(x) 0416 0417 # define PMIX_TIMING_REPORT(enable, t) 0418 0419 # define PMIX_TIMING_DELTAS(enable, t) 0420 0421 # define PMIX_TIMING_RELEASE(t) 0422 0423 #endif 0424 0425 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|