dump exhaustive per state summary stats
| 238 | |
| 239 | // dump exhaustive per state summary stats |
| 240 | static int |
| 241 | lifecycleHandler(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata) |
| 242 | { |
| 243 | // ensure the message is for ts_lua |
| 244 | TSPluginMsg *const msgp = (TSPluginMsg *)edata; |
| 245 | if (0 != strncasecmp(msgp->tag, TS_LUA_DEBUG_TAG, strlen(msgp->tag))) { |
| 246 | return TS_EVENT_NONE; |
| 247 | } |
| 248 | |
| 249 | ts_lua_main_ctx *const main_ctx_array = (ts_lua_main_ctx *)TSContDataGet(contp); |
| 250 | |
| 251 | static char const *const remapstr = "remap"; |
| 252 | static char const *const globalstr = "global"; |
| 253 | |
| 254 | char const *labelstr = nullptr; |
| 255 | |
| 256 | if (main_ctx_array == ts_lua_main_ctx_array) { |
| 257 | labelstr = remapstr; |
| 258 | } else { |
| 259 | labelstr = globalstr; |
| 260 | } |
| 261 | |
| 262 | char timebuf[128]; |
| 263 | get_time_now_str(timebuf, 128); |
| 264 | |
| 265 | char const *const msgstr = (char *)msgp->data; |
| 266 | enum State { Print, Reset } state; |
| 267 | state = Print; |
| 268 | size_t const reset_tag_len = strlen(reset_tag); |
| 269 | |
| 270 | if (reset_tag_len <= msgp->data_size && 0 == strncasecmp(reset_tag, msgstr, reset_tag_len)) { |
| 271 | Dbg(dbg_ctl, "[%s] LIFECYCLE_MSG: %s", __FUNCTION__, reset_tag); |
| 272 | state = Reset; |
| 273 | fprintf(stderr, "[%s] %s (%s) resetting per state gc_kb_max and threads_max\n", timebuf, TS_LUA_DEBUG_TAG, labelstr); |
| 274 | } else { |
| 275 | Dbg(dbg_ctl, "[%s] LIFECYCLE_MSG: %s", __FUNCTION__, print_tag); |
| 276 | } |
| 277 | |
| 278 | for (int index = 0; index < ts_lua_max_state_count; ++index) { |
| 279 | ts_lua_main_ctx *const main_ctx = (main_ctx_array + index); |
| 280 | if (nullptr != main_ctx) { |
| 281 | ts_lua_ctx_stats *const stats = main_ctx->stats; |
| 282 | if (nullptr != main_ctx) { |
| 283 | TSMutexLock(stats->mutexp); |
| 284 | |
| 285 | switch (state) { |
| 286 | case Reset: |
| 287 | stats->threads_max = stats->threads; |
| 288 | stats->gc_kb_max = stats->gc_kb; |
| 289 | break; |
| 290 | |
| 291 | case Print: |
| 292 | default: |
| 293 | fprintf(stderr, "[%s] %s (%s) id: %3d gc_kb: %6d gc_kb_max: %6d threads: %4d threads_max: %4d\n", timebuf, |
| 294 | TS_LUA_DEBUG_TAG, labelstr, index, stats->gc_kb, stats->gc_kb_max, stats->threads, stats->threads_max); |
| 295 | break; |
| 296 | } |
| 297 |
nothing calls this directly
no test coverage detected