Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:47:27

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