9#include <framework/pcore/RingBuffer.h>
10#include <framework/logging/Logger.h>
27 const int* shmadr = (
int*) shmat(shmid,
nullptr, SHM_RDONLY);
28 if (shmadr == (
int*) - 1) {
29 B2FATAL(
"RingBuffer: Attaching to shared memory segment via shmat() failed");
33 long filled_bytes = m_bufinfo->
wptr - m_bufinfo->rptr;
35 filled_bytes += m_bufinfo->size;
36 filled_bytes *=
sizeof(int);
37 double filled_MB = (filled_bytes) / 1024.0 / 1024.0;
38 std::cout <<
"RB " << shmid
39 <<
" #Tx: " << m_bufinfo->numAttachedTx <<
"\t"
40 <<
" #busy: " << m_bufinfo->nbusy <<
"\t"
41 << m_bufinfo->nbuf <<
" entries\t"
42 << filled_MB <<
" MiB filled\t(" << 100.0 * filled_bytes / double(m_bufinfo->size *
sizeof(
int)) <<
" %)"
48std::vector<int> findRingBuffers()
50 std::vector<int> buffer_SHMs;
52 if ((dir = opendir(std::filesystem::temp_directory_path().c_str())) !=
nullptr) {
54 while ((ent = readdir(dir)) !=
nullptr) {
55 if (strncmp(ent->d_name,
"SHM", 3) == 0) {
58 sscanf(ent->d_name,
"SHM%d-SEM%d-%255s", &shmid, &semid, name);
61 if (shmctl(shmid, IPC_STAT, &shmInfo) == 0) {
64 if (shmInfo.shm_nattch != 0) {
65 buffer_SHMs.push_back(shmid);
80int main(
int argc,
char**)
83 printf(
"Usage : monitor_ringbuffers\n");
85 printf(
"\n Shows fill-state information on all active RingBuffers on this system.\n\n");
89 std::cout << std::setprecision(2) << std::fixed;
91 std::vector<int> buffer_SHMs = findRingBuffers();
92 if (buffer_SHMs.empty())
94 for (
int shmid : buffer_SHMs)
99 std::cout <<
"No Ringbuffers found, exiting.\n";
Internal metadata structure for RingBuffer.
int wptr
Pointer for writing entries.