From 3d5d2d3d4534c23e1bb69b72bddca9406e917ff2 Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Wed, 14 Feb 2024 14:56:08 +0000 Subject: [PATCH] cleanup(libsinsp): populate procinfo event params with scap_event_encode_params Signed-off-by: Luca Guerra --- userspace/libsinsp/sinsp.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/userspace/libsinsp/sinsp.cpp b/userspace/libsinsp/sinsp.cpp index b99c969619..84648eb9ad 100644 --- a/userspace/libsinsp/sinsp.cpp +++ b/userspace/libsinsp/sinsp.cpp @@ -1111,20 +1111,18 @@ void sinsp::get_procs_cpu_from_driver(uint64_t ts) continue; } - // create scap event uint32_t evlen = sizeof(scap_evt) + 2 * sizeof(uint16_t) + 2 * sizeof(uint64_t); auto piscapevt_buf = std::unique_ptr>(new uint8_t[evlen]); - uint16_t* evt_lens = (uint16_t*) (piscapevt_buf.get() + sizeof(ppm_evt_hdr)); auto piscapevt = (scap_evt*) piscapevt_buf.get(); - piscapevt->len = evlen; - piscapevt->type = PPME_PROCINFO_E; - piscapevt->nparams = 2; piscapevt->tid = pi->pid; piscapevt->ts = ts; - evt_lens[0] = 8; // cpu_usr (len) - evt_lens[1] = 8; // cpu_sys (len) - ((uint64_t*)(evt_lens + 2))[0] = pi->utime; // cpu_usr (val) - ((uint64_t*)(evt_lens + 2))[1] = pi->stime; // cpu_sys (val) + int32_t encode_res = scap_event_encode_params(scap_sized_buffer{piscapevt_buf.get(), evlen}, nullptr, error, + PPME_PROCINFO_E, 2, pi->utime, pi->stime); + + if (encode_res != SCAP_SUCCESS) + { + throw sinsp_exception(std::string("could not encode PPME_PROCINFO_E event: ") + error); + } // push event into async event queue handle_async_event(sinsp_evt::from_scap_evt(std::move(piscapevt_buf)));