1 /** 2 * Copyright (C) Mellanox Technologies Ltd. 2001-2018. ALL RIGHTS RESERVED. 3 * 4 * See file LICENSE for terms. 5 */ 6 7 #ifndef UCS_PROFILE_DEFS_H_ 8 #define UCS_PROFILE_DEFS_H_ 9 10 #include <ucs/config/global_opts.h> 11 #include <ucs/sys/compiler_def.h> 12 #include <ucs/time/time_def.h> 13 #include <limits.h> 14 15 BEGIN_C_DECLS 16 17 /** @file profile_defs.h */ 18 19 #define UCS_PROFILE_STACK_MAX 64 20 #define UCS_PROFILE_FILE_VERSION 2u 21 22 23 /** 24 * Profiling modes 25 */ 26 enum { 27 UCS_PROFILE_MODE_ACCUM, /**< Accumulate elapsed time per location */ 28 UCS_PROFILE_MODE_LOG, /**< Record all events */ 29 UCS_PROFILE_MODE_LAST 30 }; 31 32 33 /** 34 * Profiling location type 35 */ 36 typedef enum { 37 UCS_PROFILE_TYPE_SAMPLE, /**< Sample only */ 38 UCS_PROFILE_TYPE_SCOPE_BEGIN, /**< Begin a scope */ 39 UCS_PROFILE_TYPE_SCOPE_END, /**< End a scope */ 40 UCS_PROFILE_TYPE_REQUEST_NEW, /**< New asynchronous request */ 41 UCS_PROFILE_TYPE_REQUEST_EVENT, /**< Some progress is made on a request */ 42 UCS_PROFILE_TYPE_REQUEST_FREE, /**< Asynchronous request released */ 43 UCS_PROFILE_TYPE_LAST 44 } ucs_profile_type_t; 45 46 47 /* 48 * Profile file structure: 49 * 50 * < ucs_profile_header_t > 51 * < ucs_profile_location_t > * ucs_profile_header_t::num_locaitons 52 * [ 53 * < ucs_profile_thread_header_t > 54 * < ucs_profile_thread_location_t > * ucs_profile_header_t::num_locaitons 55 * < ucs_profile_record_t > * ucs_profile_thread_header_t::num_records 56 * 57 * ] * ucs_profile_thread_header_t::num_threads 58 */ 59 60 61 /** 62 * Profile output file header 63 */ 64 typedef struct ucs_profile_header { 65 uint32_t version; /**< File format version */ 66 char ucs_path[1024];/**< UCX library path*/ 67 char cmdline[1024]; /**< Command line */ 68 char hostname[64]; /**< Host name */ 69 uint32_t pid; /**< Process ID */ 70 uint32_t mode; /**< Bitmask of profiling modes */ 71 uint32_t num_locations; /**< Number of locations in the file */ 72 uint32_t num_threads; /**< Number of threads in the file */ 73 uint64_t one_second; /**< How much time is one second on the sampled machine */ 74 } UCS_S_PACKED ucs_profile_header_t; 75 76 77 /** 78 * Profile location record 79 */ 80 typedef struct ucs_profile_location { 81 char file[64]; /**< Source file name */ 82 char function[64]; /**< Function name */ 83 char name[32]; /**< User-provided name */ 84 int line; /**< Source line number */ 85 uint8_t type; /**< From ucs_profile_type_t */ 86 } UCS_S_PACKED ucs_profile_location_t; 87 88 89 /** 90 * Profile output file thread header 91 */ 92 typedef struct ucs_profile_thread_header { 93 uint32_t tid; /**< System thread id */ 94 uint64_t start_time; /**< Time of thread start */ 95 uint64_t end_time; /**< Time of thread exit */ 96 uint64_t num_records; /**< Number of records for the thread */ 97 } UCS_S_PACKED ucs_profile_thread_header_t; 98 99 100 /** 101 * Profile thread location with samples 102 */ 103 typedef struct ucs_profile_thread_location { 104 uint64_t total_time; /**< Total interval from previous location */ 105 size_t count; /**< Number of times we've hit this location */ 106 } UCS_S_PACKED ucs_profile_thread_location_t; 107 108 109 /** 110 * Profile output file sample record 111 */ 112 typedef struct ucs_profile_record { 113 uint64_t timestamp; /**< Record timestamp */ 114 uint64_t param64; /**< Custom 64-bit parameter */ 115 uint32_t param32; /**< Custom 32-bit parameter */ 116 uint32_t location; /**< Location identifier */ 117 } UCS_S_PACKED ucs_profile_record_t; 118 119 120 extern const char *ucs_profile_mode_names[]; 121 122 123 /** 124 * Initialize profiling system. 125 */ 126 void ucs_profile_global_init(); 127 128 129 /** 130 * Save and cleanup profiling. 131 */ 132 void ucs_profile_global_cleanup(); 133 134 135 /** 136 * Save and reset profiling. 137 */ 138 void ucs_profile_dump(); 139 140 END_C_DECLS 141 142 #endif 143