| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2024 Barcelona Supercomputing Center */ | ||
| 3 | /* */ | ||
| 4 | /* This file is part of the DLB library. */ | ||
| 5 | /* */ | ||
| 6 | /* DLB is free software: you can redistribute it and/or modify */ | ||
| 7 | /* it under the terms of the GNU Lesser General Public License as published by */ | ||
| 8 | /* the Free Software Foundation, either version 3 of the License, or */ | ||
| 9 | /* (at your option) any later version. */ | ||
| 10 | /* */ | ||
| 11 | /* DLB is distributed in the hope that it will be useful, */ | ||
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | ||
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | ||
| 14 | /* GNU Lesser General Public License for more details. */ | ||
| 15 | /* */ | ||
| 16 | /* You should have received a copy of the GNU Lesser General Public License */ | ||
| 17 | /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 18 | /*********************************************************************************/ | ||
| 19 | |||
| 20 | #include "extra_tests.h" | ||
| 21 | #include "unique_shmem.h" | ||
| 22 | |||
| 23 | #include "LB_core/spd.h" | ||
| 24 | #include "LB_core/thread_ctx.h" | ||
| 25 | #include "LB_comm/shmem_talp.h" | ||
| 26 | #include "apis/dlb_talp.h" | ||
| 27 | #include "apis/dlb_errors.h" | ||
| 28 | #include "support/atomic.h" | ||
| 29 | #include "support/mask_utils.h" | ||
| 30 | #include "support/options.h" | ||
| 31 | #include "talp/regions.h" | ||
| 32 | #include "talp/talp.h" | ||
| 33 | #include "talp/talp_mpi.h" | ||
| 34 | #include "talp/talp_types.h" | ||
| 35 | |||
| 36 | #include <sched.h> | ||
| 37 | #include <string.h> | ||
| 38 | #include <unistd.h> | ||
| 39 | #include <stdint.h> | ||
| 40 | #include <assert.h> | ||
| 41 | |||
| 42 | int check_internal_dlb_monitor_t(void); | ||
| 43 | int check_internal_dlb_pop_metrics_t(void); | ||
| 44 | int check_internal_dlb_node_metrics_t(void); | ||
| 45 | |||
| 46 | /* Test simple TALP & Monitoring Regions functionalities */ | ||
| 47 | |||
| 48 | enum { USLEEP_TIME = 1000 }; | ||
| 49 | |||
| 50 | 1 | int main(int argc, char *argv[]) { | |
| 51 | |||
| 52 | enum { NUM_MEASUREMENTS = 10 }; | ||
| 53 | |||
| 54 | 1 | int cpu = sched_getcpu(); | |
| 55 | cpu_set_t process_mask; | ||
| 56 | 1 | CPU_ZERO(&process_mask); | |
| 57 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CPU_SET(cpu, &process_mask); |
| 58 | |||
| 59 | 1 | char options[64] = "--talp=papi --shm-key="; | |
| 60 | 1 | strcat(options, SHMEM_KEY); | |
| 61 | 1 | subprocess_descriptor_t spd = {.id = 111}; | |
| 62 | 1 | options_init(&spd.options, options); | |
| 63 | 1 | memcpy(&spd.process_mask, &process_mask, sizeof(cpu_set_t)); | |
| 64 | 1 | spd_enter_dlb(&spd); | |
| 65 | 1 | thread_ctx_set_main(THREAD_MAIN_SEQUENTIAL); | |
| 66 | 1 | talp_init(&spd); | |
| 67 | |||
| 68 | 1 | talp_info_t *talp_info = spd.talp_info; | |
| 69 | 1 | dlb_monitor_t *global_monitor = talp_info->monitor; | |
| 70 | |||
| 71 | /* Check internal and public structs are equivalent */ | ||
| 72 | #ifdef HAVE_TEST_LIB | ||
| 73 | assert( check_internal_dlb_monitor_t() == 0); | ||
| 74 | assert( check_internal_dlb_pop_metrics_t() == 0); | ||
| 75 | assert( check_internal_dlb_node_metrics_t() == 0); | ||
| 76 | #endif | ||
| 77 | |||
| 78 | /* Check that global monitor was started during talp_init and reset it | ||
| 79 | * for the following tests */ | ||
| 80 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, global_monitor) == DLB_SUCCESS ); |
| 81 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_reset(&spd, global_monitor) == DLB_SUCCESS ); |
| 82 | |||
| 83 | /* Register custom monitoring region */ | ||
| 84 | 1 | dlb_monitor_t *monitor = region_register(&spd, "Test monitor"); | |
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor != NULL ); |
| 86 | |||
| 87 | /* Check for forbidden names */ | ||
| 88 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_register(&spd, "ALL") == NULL ); |
| 89 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_register(&spd, "all") == NULL ); |
| 90 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_register(&spd, DLB_LAST_OPEN_REGION) == NULL ); |
| 91 | |||
| 92 | /* Check that registering "global_region_name" or DLB_GLOBAL_REGION_NAME is | ||
| 93 | * allowed and that it does not reset the region */ | ||
| 94 | { | ||
| 95 | /* Force num_measurements = 1 */ | ||
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, global_monitor) == DLB_SUCCESS ); |
| 97 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, global_monitor) == DLB_SUCCESS ); |
| 98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_measurements == 1 ); |
| 99 | |||
| 100 | 1 | dlb_monitor_t *another_global_1 = region_register(&spd, | |
| 101 | region_get_global_name()); | ||
| 102 | 1 | dlb_monitor_t *another_global_2 = region_register(&spd, | |
| 103 | DLB_GLOBAL_REGION_NAME); | ||
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( another_global_1 == global_monitor); |
| 105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( another_global_2 == global_monitor); |
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_measurements == 1 ); |
| 107 | |||
| 108 | /* Reset region for subsequent tests */ | ||
| 109 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_reset(&spd, global_monitor) == DLB_SUCCESS ); |
| 110 | } | ||
| 111 | |||
| 112 | /* Test MPI + nested user defined region */ | ||
| 113 | { | ||
| 114 | /* TALP initial values */ | ||
| 115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->mpi_time == 0 ); |
| 116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->useful_time == 0 ); |
| 117 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_get_global(&spd) == global_monitor ); |
| 118 | |||
| 119 | /* Start global monitor */ | ||
| 120 | 1 | talp_mpi_init(&spd); | |
| 121 | |||
| 122 | /* Start and Stop custom monitoring region */ | ||
| 123 | 1 | region_start(&spd, monitor); | |
| 124 | 1 | region_stop(&spd, monitor); | |
| 125 | |||
| 126 | /* Perform 1 MPI call and 1 DLB_Barrier */ | ||
| 127 | 1 | sync_call_flags_t mpi_flags = { .is_mpi = true }; | |
| 128 | 1 | talp_into_sync_call(&spd, mpi_flags); | |
| 129 | 1 | talp_out_of_sync_call(&spd, mpi_flags); | |
| 130 | 1 | sync_call_flags_t dlb_barrier_flags = { .is_dlb_barrier = true }; | |
| 131 | 1 | talp_into_sync_call(&spd, dlb_barrier_flags); | |
| 132 | 1 | talp_out_of_sync_call(&spd, dlb_barrier_flags); | |
| 133 | |||
| 134 | /* Stop global monitor */ | ||
| 135 | 1 | talp_mpi_finalize(&spd); | |
| 136 | |||
| 137 | /* Test number of MPI calls is correct */ | ||
| 138 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->num_mpi_calls == 0 ); |
| 139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_mpi_calls == 3 ); // Init + Custom + Finalize |
| 140 | |||
| 141 | /* Test global monitor values are correct and greater than custom monitor */ | ||
| 142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->mpi_time > 0 ); |
| 143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->useful_time > 0 ); |
| 144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->useful_time > monitor->useful_time ); |
| 145 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->elapsed_time > monitor->elapsed_time ); |
| 146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (talp_info->flags.have_hwc) { |
| 147 | ✗ | assert( global_monitor->instructions > monitor->instructions ); | |
| 148 | ✗ | assert( global_monitor->cycles > monitor->cycles ); | |
| 149 | } | ||
| 150 | |||
| 151 | /* Test custom monitor values */ | ||
| 152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->num_measurements == 1 ); |
| 153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->mpi_time == 0 ); |
| 154 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->useful_time != 0 ); |
| 155 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_reset(&spd, monitor) == DLB_SUCCESS ); |
| 156 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->num_resets == 1 ); |
| 157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->mpi_time == 0 ); |
| 158 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->useful_time == 0 ); |
| 159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (talp_info->flags.have_hwc) { |
| 160 | ✗ | assert( monitor->instructions == 0 ); | |
| 161 | ✗ | assert( monitor->cycles == 0 ); | |
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | /* Test that reset/start/stop/report may also be invoked with the global DLB_GLOBAL_REGION */ | ||
| 166 | { | ||
| 167 | /* Reset global monitoring region */ | ||
| 168 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_reset(&spd, DLB_GLOBAL_REGION) == DLB_SUCCESS ); |
| 169 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( !region_is_started(global_monitor) ); |
| 170 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->elapsed_time == 0 ); |
| 171 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_measurements == 0 ); |
| 172 | |||
| 173 | /* Start global monitor */ | ||
| 174 | 1 | talp_mpi_init(&spd); | |
| 175 | |||
| 176 | /* Stop global monitoring region */ | ||
| 177 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, DLB_GLOBAL_REGION) == DLB_SUCCESS ); |
| 178 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( !region_is_started(global_monitor) ); |
| 179 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->elapsed_time > 0 ); |
| 180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_measurements == 1 ); |
| 181 | |||
| 182 | /* Start global monitoring region */ | ||
| 183 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, DLB_GLOBAL_REGION) == DLB_SUCCESS ); |
| 184 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_is_started(global_monitor) ); |
| 185 | |||
| 186 | /* Stop global monitor */ | ||
| 187 | 1 | talp_mpi_finalize(&spd); | |
| 188 | |||
| 189 | /* Report global region */ | ||
| 190 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_report(&spd, DLB_GLOBAL_REGION) == DLB_SUCCESS ); |
| 191 | } | ||
| 192 | |||
| 193 | /* Test number of measurements */ | ||
| 194 | { | ||
| 195 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (int i = 0; i < NUM_MEASUREMENTS; ++i) { |
| 196 | 10 | region_start(&spd, monitor); | |
| 197 | 10 | region_stop(&spd, monitor); | |
| 198 | } | ||
| 199 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->num_measurements == NUM_MEASUREMENTS ); |
| 200 | 1 | int64_t last_elapsed_measurement = monitor->stop_time - monitor->start_time; | |
| 201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( last_elapsed_measurement > 0 ); |
| 202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( last_elapsed_measurement * NUM_MEASUREMENTS/10 < monitor->elapsed_time ); |
| 203 | } | ||
| 204 | |||
| 205 | /* Test invalid start/stop call order */ | ||
| 206 | { | ||
| 207 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor) == DLB_NOUPDT ); |
| 208 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor) == DLB_SUCCESS ); |
| 209 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor) == DLB_NOUPDT ); |
| 210 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor) == DLB_SUCCESS ); |
| 211 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor) == DLB_NOUPDT ); |
| 212 | } | ||
| 213 | |||
| 214 | /* Test reset with open region */ | ||
| 215 | { | ||
| 216 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( talp_info->open_regions == NULL ); |
| 217 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor) == DLB_SUCCESS ); |
| 218 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( talp_info->open_regions && |
| 219 | talp_info->open_regions->data == monitor ); | ||
| 220 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_reset(&spd, monitor) == DLB_SUCCESS ); |
| 221 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( talp_info->open_regions == NULL ); |
| 222 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor) == DLB_NOUPDT ); |
| 223 | } | ||
| 224 | |||
| 225 | /* Test nested regions */ | ||
| 226 | { | ||
| 227 | 1 | dlb_monitor_t *monitor1 = region_register(&spd, "Test nested 1"); | |
| 228 | 1 | dlb_monitor_t *monitor2 = region_register(&spd, "Test nested 2"); | |
| 229 | 1 | dlb_monitor_t *monitor3 = region_register(&spd, "Test nested 3"); | |
| 230 | 1 | region_start(&spd, monitor1); | |
| 231 | 1 | usleep(USLEEP_TIME); | |
| 232 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (int i = 0; i < NUM_MEASUREMENTS; ++i) { |
| 233 | 10 | region_start(&spd, monitor2); | |
| 234 | 10 | usleep(USLEEP_TIME); | |
| 235 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 10 times.
|
110 | for (int j = 0; j < NUM_MEASUREMENTS; ++j) { |
| 236 | 100 | region_start(&spd, monitor3); | |
| 237 | 100 | usleep(USLEEP_TIME); | |
| 238 | 100 | region_stop(&spd, monitor3); | |
| 239 | } | ||
| 240 | 10 | usleep(USLEEP_TIME); | |
| 241 | 10 | region_stop(&spd, monitor2); | |
| 242 | } | ||
| 243 | 1 | usleep(USLEEP_TIME); | |
| 244 | 1 | region_stop(&spd, monitor1); | |
| 245 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor1->num_measurements == 1 ); |
| 246 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor2->num_measurements == NUM_MEASUREMENTS ); |
| 247 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor3->num_measurements == NUM_MEASUREMENTS * NUM_MEASUREMENTS ); |
| 248 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor1->elapsed_time > monitor2->elapsed_time ); |
| 249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor2->elapsed_time > monitor3->elapsed_time ); |
| 250 | } | ||
| 251 | |||
| 252 | /* Test monitor register with repeated or NULL names */ | ||
| 253 | { | ||
| 254 | 1 | dlb_monitor_t *monitor3 = region_register(&spd, "Test nested 3"); | |
| 255 | 1 | dlb_monitor_t *monitor4 = region_register(&spd, "Test nested 3"); | |
| 256 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor4 == monitor3 ); |
| 257 | 1 | dlb_monitor_t *monitor5 = region_register(&spd, NULL); | |
| 258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor5 != NULL ); |
| 259 | 1 | dlb_monitor_t *monitor6 = region_register(&spd, NULL); | |
| 260 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor6 != NULL ); |
| 261 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor6 != monitor5 ); |
| 262 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( strcmp(monitor5->name, "Anonymous Region 1") == 0 ); |
| 263 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( strcmp(monitor6->name, "Anonymous Region 2") == 0 ); |
| 264 | } | ||
| 265 | |||
| 266 | /* Test monitor name length */ | ||
| 267 | { | ||
| 268 | 1 | const char *long_name = "This is a very long name. It is so long that" | |
| 269 | " it is more than DLB_MONITOR_NAME_MAX which, at the time of writing," | ||
| 270 | " should be 128 characters."; | ||
| 271 | 1 | dlb_monitor_t *monitor7 = region_register(&spd, long_name); | |
| 272 | 1 | dlb_monitor_t *monitor8 = region_register(&spd, long_name); | |
| 273 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor7 == monitor8 ); |
| 274 | 1 | region_report(&spd, monitor7); | |
| 275 | 1 | region_report(&spd, global_monitor); | |
| 276 | } | ||
| 277 | |||
| 278 | /* Test internal monitor */ | ||
| 279 | { | ||
| 280 | 1 | dlb_monitor_t *monitor9 = region_register(&spd, "Hidden monitor"); | |
| 281 | 1 | region_set_internal(monitor9, true); | |
| 282 | 1 | region_report(&spd, monitor9); | |
| 283 | } | ||
| 284 | |||
| 285 | /* Test --talp-region-select */ | ||
| 286 | { | ||
| 287 | 1 | strcpy(spd.options.talp_region_select, "exclude:all"); | |
| 288 | 1 | dlb_monitor_t *monitor1 = region_register(&spd, "disabled_monitor"); | |
| 289 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor1) == DLB_NOUPDT ); |
| 290 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor1) == DLB_NOUPDT ); |
| 291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor1->num_measurements == 0 ); |
| 292 | |||
| 293 | 1 | strcpy(spd.options.talp_region_select, "other_monitor"); | |
| 294 | 1 | dlb_monitor_t *monitor2 = region_register(&spd, "not_enabled_monitor"); | |
| 295 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor2) == DLB_NOUPDT ); |
| 296 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor2) == DLB_NOUPDT ); |
| 297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor2->num_measurements == 0 ); |
| 298 | |||
| 299 | 1 | strcpy(spd.options.talp_region_select, "monitor4,monitor5"); | |
| 300 | 1 | dlb_monitor_t *monitor3 = region_register(&spd, "monitor3"); | |
| 301 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor3) == DLB_NOUPDT ); |
| 302 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor3) == DLB_NOUPDT ); |
| 303 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor3->num_measurements == 0 ); |
| 304 | 1 | dlb_monitor_t *monitor4 = region_register(&spd, "monitor4"); | |
| 305 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor4) == DLB_SUCCESS ); |
| 306 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor4) == DLB_SUCCESS ); |
| 307 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor4->num_measurements == 1 ); |
| 308 | 1 | dlb_monitor_t *monitor5 = region_register(&spd, "monitor5"); | |
| 309 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor5) == DLB_SUCCESS ); |
| 310 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor5) == DLB_SUCCESS ); |
| 311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor5->num_measurements == 1 ); |
| 312 | |||
| 313 | 1 | strcpy(spd.options.talp_region_select, "exclude:monitor7,monitor8"); | |
| 314 | 1 | dlb_monitor_t *monitor6 = region_register(&spd, "monitor6"); | |
| 315 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor6) == DLB_SUCCESS ); |
| 316 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor6) == DLB_SUCCESS ); |
| 317 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor6->num_measurements == 1 ); |
| 318 | 1 | dlb_monitor_t *monitor7 = region_register(&spd, "monitor7"); | |
| 319 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor7) == DLB_NOUPDT ); |
| 320 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor7) == DLB_NOUPDT ); |
| 321 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor7->num_measurements == 0 ); |
| 322 | 1 | dlb_monitor_t *monitor8 = region_register(&spd, "monitor8"); | |
| 323 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor8) == DLB_NOUPDT ); |
| 324 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor8) == DLB_NOUPDT ); |
| 325 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor8->num_measurements == 0 ); |
| 326 | |||
| 327 | 1 | strcpy(spd.options.talp_region_select, ""); | |
| 328 | 1 | dlb_monitor_t *monitor9 = region_register(&spd, "monitor9"); | |
| 329 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor9) == DLB_SUCCESS ); |
| 330 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor9) == DLB_SUCCESS ); |
| 331 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor9->num_measurements == 1 ); |
| 332 | |||
| 333 | 1 | strcpy(spd.options.talp_region_select, "all"); | |
| 334 | 1 | dlb_monitor_t *monitor10 = region_register(&spd, "monitor10"); | |
| 335 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor10) == DLB_SUCCESS ); |
| 336 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor10) == DLB_SUCCESS ); |
| 337 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor10->num_measurements == 1 ); |
| 338 | |||
| 339 | 1 | strcpy(spd.options.talp_region_select, "include:all"); | |
| 340 | 1 | dlb_monitor_t *monitor11 = region_register(&spd, "monitor11"); | |
| 341 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor11) == DLB_SUCCESS ); |
| 342 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor11) == DLB_SUCCESS ); |
| 343 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor11->num_measurements == 1 ); |
| 344 | |||
| 345 | 1 | strcpy(spd.options.talp_region_select, "include:monitor13"); | |
| 346 | 1 | dlb_monitor_t *monitor12 = region_register(&spd, "monitor12"); | |
| 347 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor12) == DLB_NOUPDT ); |
| 348 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor12) == DLB_NOUPDT ); |
| 349 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor12->num_measurements == 0 ); |
| 350 | 1 | dlb_monitor_t *monitor13 = region_register(&spd, "monitor13"); | |
| 351 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, monitor13) == DLB_SUCCESS ); |
| 352 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, monitor13) == DLB_SUCCESS ); |
| 353 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor13->num_measurements == 1 ); |
| 354 | |||
| 355 | // Reset talp_region_select for the following tests | ||
| 356 | 1 | strcpy(spd.options.talp_region_select, ""); | |
| 357 | } | ||
| 358 | |||
| 359 | /* Test creation of N regions */ | ||
| 360 | { | ||
| 361 | enum { N = 1000 }; | ||
| 362 | char name[DLB_MONITOR_NAME_MAX]; | ||
| 363 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
|
1001 | for (int i = 0; i < N; ++i) { |
| 364 | 1000 | snprintf(name, DLB_MONITOR_NAME_MAX, "Loop Region %d", i); | |
| 365 | 1000 | dlb_monitor_t *loop_monitor = region_register(&spd, name); | |
| 366 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1000 times.
|
1000 | assert( loop_monitor != NULL ); |
| 367 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1000 times.
|
1000 | assert( strncmp(name, loop_monitor->name, DLB_MONITOR_NAME_MAX) == 0 ); |
| 368 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
|
1000 | assert( region_start(&spd, loop_monitor) == DLB_SUCCESS ); |
| 369 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
|
1000 | assert( region_stop(&spd, loop_monitor) == DLB_SUCCESS ); |
| 370 | } | ||
| 371 | } | ||
| 372 | |||
| 373 | /* Test DLB_LAST_OPEN_REGION */ | ||
| 374 | { | ||
| 375 | 1 | dlb_monitor_t *first = region_register(&spd, "first"); | |
| 376 | 1 | dlb_monitor_t *last = region_register(&spd, "last"); | |
| 377 | |||
| 378 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, first) == DLB_SUCCESS ); |
| 379 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, last) == DLB_SUCCESS ); |
| 380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( last->num_measurements == 0 ); |
| 381 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( first->num_measurements == 0 ); |
| 382 | |||
| 383 | /* Stop last */ | ||
| 384 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, DLB_LAST_OPEN_REGION) == DLB_SUCCESS ); |
| 385 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( last->num_measurements == 1 ); |
| 386 | |||
| 387 | /* Re-open and stop */ | ||
| 388 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, last) == DLB_SUCCESS ); |
| 389 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, DLB_LAST_OPEN_REGION) == DLB_SUCCESS ); |
| 390 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( last->num_measurements == 2 ); |
| 391 | |||
| 392 | /* Stop first */ | ||
| 393 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, DLB_LAST_OPEN_REGION) == DLB_SUCCESS ); |
| 394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( first->num_measurements == 1 ); |
| 395 | |||
| 396 | /* No open regions */ | ||
| 397 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, DLB_LAST_OPEN_REGION) == DLB_ERR_NOENT ); |
| 398 | |||
| 399 | 1 | dlb_monitor_t *mid = region_register(&spd, "mid"); | |
| 400 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, first) == DLB_SUCCESS ); |
| 401 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, mid) == DLB_SUCCESS ); |
| 402 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, last) == DLB_SUCCESS ); |
| 403 | |||
| 404 | /* Not properly nested, weird but still supported */ | ||
| 405 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, mid) == DLB_SUCCESS ); |
| 406 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( mid->num_measurements == 1 ); |
| 407 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, DLB_LAST_OPEN_REGION) == DLB_SUCCESS ); |
| 408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( last->num_measurements == 3 ); |
| 409 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_stop(&spd, DLB_LAST_OPEN_REGION) == DLB_SUCCESS ); |
| 410 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( first->num_measurements == 2 ); |
| 411 | } | ||
| 412 | |||
| 413 | /* Test Collect POP metrics */ | ||
| 414 | { | ||
| 415 | dlb_pop_metrics_t pop_metrics; | ||
| 416 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( talp_collect_pop_metrics(&spd, global_monitor, &pop_metrics) == DLB_SUCCESS ); |
| 417 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( strcmp(pop_metrics.name, DLB_GLOBAL_REGION_NAME) == 0 ); |
| 418 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pop_metrics.elapsed_time > 0 ); |
| 419 | |||
| 420 | dlb_node_metrics_t node_metrics; | ||
| 421 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( talp_collect_pop_node_metrics(&spd, global_monitor, &node_metrics) |
| 422 | == DLB_SUCCESS ); | ||
| 423 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( strcmp(node_metrics.name, DLB_GLOBAL_REGION_NAME) == 0 ); |
| 424 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( node_metrics.total_useful_time > 0 ); |
| 425 | } | ||
| 426 | |||
| 427 | 1 | talp_finalize(&spd); | |
| 428 | |||
| 429 | /* Test --talp-region-select with global region, and finalize with open regions */ | ||
| 430 | { | ||
| 431 | 1 | strcpy(spd.options.talp_region_select, "region1,global"); | |
| 432 | 1 | talp_init(&spd); | |
| 433 | 1 | global_monitor = region_get_global(&spd); | |
| 434 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, global_monitor) == DLB_NOUPDT ); |
| 435 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_is_started(global_monitor) ); |
| 436 | 1 | talp_finalize(&spd); | |
| 437 | 1 | strcpy(spd.options.talp_region_select, ""); | |
| 438 | } | ||
| 439 | |||
| 440 | /* Test --talp-region-select without global region */ | ||
| 441 | { | ||
| 442 | 1 | strcpy(spd.options.talp_region_select, "region1"); | |
| 443 | 1 | talp_init(&spd); | |
| 444 | 1 | global_monitor = region_get_global(&spd); | |
| 445 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_start(&spd, global_monitor) == DLB_NOUPDT ); |
| 446 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( !region_is_started(global_monitor) ); |
| 447 | 1 | talp_finalize(&spd); | |
| 448 | 1 | strcpy(spd.options.talp_region_select, ""); | |
| 449 | } | ||
| 450 | |||
| 451 | /* Test --shm-size-multiplier */ | ||
| 452 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (DLB_EXTRA_TESTS) |
| 453 | { | ||
| 454 | enum { KNOWN_NUM_REGIONS_PER_PROC = 100 }; | ||
| 455 | char name[DLB_MONITOR_NAME_MAX]; | ||
| 456 | 1 | spd.options.talp_external_profiler = true; | |
| 457 | 1 | spd.options.talp_summary = SUMMARY_NONE; | |
| 458 | |||
| 459 | /* Choose multipliers based on the size of the current node. | ||
| 460 | * This test can significantly increase execution time on big nodes. | ||
| 461 | * The following numbers are chosen somewhat arbitrarily: | ||
| 462 | */ | ||
| 463 | int initial_multiplier, final_multiplier; | ||
| 464 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (mu_get_system_size() < 64 ) { |
| 465 | 1 | initial_multiplier = 1; | |
| 466 | 1 | final_multiplier = 3; | |
| 467 | } else { | ||
| 468 | ✗ | initial_multiplier = 2; | |
| 469 | ✗ | final_multiplier = 2; | |
| 470 | } | ||
| 471 | |||
| 472 | /* Try multipliers */ | ||
| 473 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (int multiplier = initial_multiplier; multiplier <= final_multiplier; ++multiplier) { |
| 474 | 3 | spd.options.shm_size_multiplier = multiplier; | |
| 475 | 3 | talp_init(&spd); | |
| 476 | 3 | int expected_max_regions = KNOWN_NUM_REGIONS_PER_PROC | |
| 477 | 3 | * mu_get_system_size() * multiplier; | |
| 478 | /* start at 1 because of global region */ | ||
| 479 |
2/2✓ Branch 0 taken 1197 times.
✓ Branch 1 taken 3 times.
|
1200 | for (int i = 1; i < expected_max_regions; ++i) { |
| 480 | 1197 | snprintf(name, DLB_MONITOR_NAME_MAX, "Loop Region %d", i); | |
| 481 | 1197 | dlb_monitor_t *loop_monitor = region_register(&spd, name); | |
| 482 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1197 times.
|
1197 | assert( loop_monitor != NULL ); |
| 483 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1197 times.
|
1197 | assert( strncmp(name, loop_monitor->name, DLB_MONITOR_NAME_MAX) == 0 ); |
| 484 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1197 times.
|
1197 | assert( region_start(&spd, loop_monitor) == DLB_SUCCESS ); |
| 485 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1197 times.
|
1197 | assert( region_stop(&spd, loop_monitor) == DLB_SUCCESS ); |
| 486 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1197 times.
|
1197 | assert( shmem_talp__get_num_regions() == i+1 ); |
| 487 | } | ||
| 488 | |||
| 489 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | assert( shmem_talp__get_num_regions() == expected_max_regions ); |
| 490 | 3 | snprintf(name, DLB_MONITOR_NAME_MAX, | |
| 491 | "Doesn't fit in shmem (multiplier: %d)", multiplier); | ||
| 492 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | assert( region_register(&spd, name) != NULL ); |
| 493 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | assert( shmem_talp__get_num_regions() == expected_max_regions ); |
| 494 | 3 | talp_finalize(&spd); | |
| 495 | } | ||
| 496 | } | ||
| 497 | |||
| 498 | 1 | return 0; | |
| 499 | } | ||
| 500 |