| 547 | } |
| 548 | |
| 549 | RecErrT |
| 550 | RecLookupMatchingRecords(unsigned rec_type, const char *match, void (*callback)(const RecRecord *, void *), void *data, |
| 551 | bool /* lock ATS_UNUSED */) |
| 552 | { |
| 553 | int num_records; |
| 554 | DFA regex; |
| 555 | |
| 556 | if (!regex.compile(match, RE_CASE_INSENSITIVE | RE_UNANCHORED)) { |
| 557 | return REC_ERR_FAIL; |
| 558 | } |
| 559 | |
| 560 | if ((rec_type & (RECT_PROCESS | RECT_NODE | RECT_PLUGIN))) { |
| 561 | // First find the new metrics, this is a bit of a hack, because we still use the old |
| 562 | // librecords callback with a "pseudo" record. |
| 563 | RecRecord tmp; |
| 564 | |
| 565 | tmp.rec_type = RECT_PROCESS; |
| 566 | tmp.data_type = RECD_INT; |
| 567 | |
| 568 | for (auto &&[name, val] : ts::Metrics::instance()) { |
| 569 | if (regex.match(name.data()) >= 0) { |
| 570 | tmp.name = name.data(); |
| 571 | tmp.data.rec_int = val; |
| 572 | callback(&tmp, data); |
| 573 | } |
| 574 | } |
| 575 | // Fall through to return any matching string metrics |
| 576 | } |
| 577 | |
| 578 | num_records = g_num_records; |
| 579 | for (int i = 0; i < num_records; i++) { |
| 580 | RecRecord *r = &(g_records[i]); |
| 581 | |
| 582 | if ((r->rec_type & rec_type) == 0) { |
| 583 | continue; |
| 584 | } |
| 585 | |
| 586 | if (regex.match(r->name) < 0) { |
| 587 | continue; |
| 588 | } |
| 589 | |
| 590 | rec_mutex_acquire(&(r->lock)); |
| 591 | callback(r, data); |
| 592 | rec_mutex_release(&(r->lock)); |
| 593 | } |
| 594 | |
| 595 | return REC_ERR_OKAY; |
| 596 | } |
| 597 | |
| 598 | RecErrT |
| 599 | RecGetRecordType(const char *name, RecT *rec_type, bool lock) |
no test coverage detected