Belle II Software development
RFFlowStat.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include "daq/rfarm/manager/RFFlowStat.h"
10#include <ctime>
11
12using namespace Belle2;
13using namespace std;
14
15RFFlowStat::RFFlowStat(const char* shmname, int id, RingBuffer* rbuf)
16{
17 m_rfshm = new RFSharedMem(shmname);
18 m_cell = &(m_rfshm->GetCell(id));
19 m_rbuf = rbuf;
20 m_flowsize = 0.0;
21 m_nevtint = 0;
22 m_interval = 100;
23 gettimeofday(&m_t0, 0);
24}
25
26RFFlowStat::RFFlowStat(const char* shmname)
27{
28 m_rfshm = new RFSharedMem(shmname);
29}
30
31RFFlowStat::~RFFlowStat()
32{
33}
34
35// Filler function
36void RFFlowStat::log(int size)
37{
38 struct timeval tnow;
39
40 m_cell->nevent++;
41 if (m_rbuf != NULL)
42 m_cell->nqueue = m_rbuf->numq();
43 else
44 m_cell->nqueue = 0;
45 m_flowsize += (float)size;
46 m_nevtint++;
47 if (m_cell->nevent % m_interval == 0) {
48 gettimeofday(&tnow, 0);
49 float delta = (float)((tnow.tv_sec - m_t0.tv_sec) * 1000000 +
50 (tnow.tv_usec - m_t0.tv_usec));
51 m_cell->flowrate = m_flowsize / delta;
52 // m_cell->flowrate = delta;
53 m_cell->avesize = m_flowsize / (float)m_nevtint / 1000.0;
54 m_cell->evtrate = (float)m_nevtint / delta * 1000000.0;
55 m_cell->elapsed = time(NULL);
56 m_flowsize = 0.0;
57 m_nevtint = 0;
58 m_t0 = tnow;
59 }
60}
61void RFFlowStat::clear(int cellid)
62{
63 RfShm_Cell& cell = getinfo(cellid);
64 cell.nevent = 0;
65 cell.nqueue = 0;
66 cell.flowrate = 0;
67 cell.avesize = 0;
68 cell.evtrate = 0;
69 cell.elapsed = 0;
70}
71
72// Retriever function
73RfShm_Cell& RFFlowStat::getinfo(int id)
74{
75 return m_rfshm->GetCell(id);
76}
77
78void RFFlowStat::fillNodeInfo(int id, RfNodeInfo* info, bool outflag)
79{
80 const RfShm_Cell& cell = getinfo(id);
81 //DEBUG printf ( "fillNodeInfo: celleid = %d, nevent = %d\n", id, cell.nevent );
82 if (!outflag) {
83 info->nevent_in = cell.nevent;
84 info->nqueue_in = cell.nqueue;
85 info->flowrate_in = cell.flowrate;
86 info->avesize_in = cell.avesize;
87 info->evtrate_in = cell.evtrate;
88 } else {
89 info->nevent_out = cell.nevent;
90 info->nqueue_out = cell.nqueue;
91 info->flowrate_out = cell.flowrate;
92 info->avesize_out = cell.avesize;
93 info->evtrate_out = cell.evtrate;
94 }
95 double loads[3];
96 if (getloadavg(loads, 3) > 0)
97 info->loadave = (float)loads[0];
98
99 /* Test
100 info->nevent_in = 99999;
101 info->nqueue_in = 123;
102 info->flowrate_in = 10.0;
103 info->avesize_in = 100.0;
104 info->evtrate_in = 1000.0;
105 */
106
107}
108
109void RFFlowStat::fillProcessStatus(RfNodeInfo* info, int input, int output, int basf2, int hserver, int hrelay)
110{
111 info->pid_input = input;
112 info->pid_output = output;
113 info->pid_basf2 = basf2;
114 info->pid_hserver = hserver;
115 info->pid_hrelay = hrelay;
116}
117
118
119
120
121
122
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
int numq() const
Returns number of entries/buffers in the RingBuffer.
Definition: RingBuffer.cc:368
Abstract base class for different kinds of events.
STL namespace.