reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
StatisticsManager.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#include "rutil/Logger.hxx"
10
11using namespace resip;
12using std::vector;
13
14#define RESIPROCATE_SUBSYSTEM Subsystem::TRANSACTION
15
16StatisticsManager::StatisticsManager(SipStack& stack, unsigned long intervalSecs)
17 : StatisticsMessage::Payload(),
18 mStack(stack),
19 mInterval(intervalSecs*1000),
20 mNextPoll(Timer::getTimeMs() + mInterval),
21 mExternalHandler(NULL),
22 mPublicPayload(NULL)
23{}
24
26{
27 if ( mPublicPayload )
28 delete mPublicPayload;
29}
30
31void
32StatisticsManager::setInterval(unsigned long intervalSecs)
33{
34 mInterval = intervalSecs * 1000;
35 mNextPoll = Timer::getTimeMs() + mInterval;
36}
37
38void
39StatisticsManager::poll()
40{
41 // get snapshot data now..
42 tuFifoSize = mStack.mTransactionController->getTuFifoSize();
43 transportFifoSizeSum = mStack.mTransactionController->sumTransportFifoSizes();
44 transactionFifoSize = mStack.mTransactionController->getTransactionFifoSize();
45 activeTimers = mStack.mTransactionController->getTimerQueueSize();
46 activeClientTransactions = mStack.mTransactionController->getNumClientTransactions();
47 activeServerTransactions = mStack.mTransactionController->getNumServerTransactions();
48
49 // .kw. At last check payload was > 146kB, which seems too large
50 // to alloc on stack. Also, the post'd message has reference
51 // to the appStats, so not safe queue as ref to stack element.
52 // Converted to dynamic memory allocation.
53 if ( mPublicPayload==NULL )
54 {
55 mPublicPayload = new StatisticsMessage::AtomicPayload;
56 // re-used each time, free'd in destructor
57 }
58 mPublicPayload->loadIn(*this);
59
60 bool postToStack = true;
61 StatisticsMessage msg(*mPublicPayload);
62 // WATCHOUT: msg contains reference to the payload, and this reference
63 // is preserved thru clone().
64
65 if( mExternalHandler )
66 {
67 postToStack = (*mExternalHandler)(msg);
68 }
69
70 if( postToStack )
71 {
72 // let the app do what it wants with it
73 mStack.post(msg);
74 }
75
76 // !bwc! TODO maybe change this? Or is a flexible implementation of
77 // CongestionManager::logCurrentState() enough?
78 if(mStack.mCongestionManager)
79 {
80 mStack.mCongestionManager->logCurrentState();
81 }
82}
83
84void
86{
87 if (Timer::getTimeMs() >= mNextPoll)
88 {
89 poll();
90 mNextPoll += mInterval;
91 }
92}
93
94bool
95StatisticsManager::sent(SipMessage* msg)
96{
97 MethodTypes met = msg->method();
98
99 if (msg->isRequest())
100 {
101 ++requestsSent;
103 }
104 else if (msg->isResponse())
105 {
106 int code = msg->const_header(h_StatusLine).statusCode();
107 if (code < 0 || code >= MaxCode)
108 {
109 code = 0;
110 }
111
114 ++responsesSentByMethodByCode[met][code];
115 }
116
117 return false;
118}
119
120bool
121StatisticsManager::retransmitted(MethodTypes met,
122 bool request,
123 unsigned int code)
124{
125 if(request)
126 {
129 }
130 else
131 {
135 }
136 return false;
137}
138
139bool
140StatisticsManager::received(SipMessage* msg)
141{
142 MethodTypes met = msg->header(h_CSeq).method();
143
144 if (msg->isRequest())
145 {
148 }
149 else if (msg->isResponse())
150 {
153 int code = msg->const_header(h_StatusLine).statusCode();
154 if (code < 0 || code >= MaxCode)
155 {
156 code = 0;
157 }
159 }
160
161 return false;
162}
163
164/* ====================================================================
165 * The Vovida Software License, Version 1.0
166 *
167 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
168 *
169 * Redistribution and use in source and binary forms, with or without
170 * modification, are permitted provided that the following conditions
171 * are met:
172 *
173 * 1. Redistributions of source code must retain the above copyright
174 * notice, this list of conditions and the following disclaimer.
175 *
176 * 2. Redistributions in binary form must reproduce the above copyright
177 * notice, this list of conditions and the following disclaimer in
178 * the documentation and/or other materials provided with the
179 * distribution.
180 *
181 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
182 * and "Vovida Open Communication Application Library (VOCAL)" must
183 * not be used to endorse or promote products derived from this
184 * software without prior written permission. For written
185 * permission, please contact vocal@vovida.org.
186 *
187 * 4. Products derived from this software may not be called "VOCAL", nor
188 * may "VOCAL" appear in their name, without prior written
189 * permission of Vovida Networks, Inc.
190 *
191 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
192 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
193 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
194 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
195 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
196 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
197 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
198 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
199 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
200 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
201 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
202 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
203 * DAMAGE.
204 *
205 * ====================================================================
206 *
207 * This software consists of voluntary contributions made by Vovida
208 * Networks, Inc. and many individuals on behalf of Vovida Networks,
209 * Inc. For more information on Vovida Networks, Inc., please see
210 * <http://www.vovida.org/>.
211 *
212 */
virtual void logCurrentState() const =0
Log the current state of all monitored fifos.
MethodTypes & method()
Represents a SIP message.
bool isRequest() const
Returns true if message is a request, false otherwise.
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
bool isResponse() const
Returns true if message is a response, false otherwise.
const RequestLine & const_header(const RequestLineType &l) const
resip::MethodTypes method() const
returns the method type of the message
This is the primary point of interaction between the app-layer and the stack.
Definition SipStack.hxx:160
void post(std::unique_ptr< ApplicationMessage > message, unsigned int secondsLater, TransactionUser *tu=0)
Makes the message available to the TU at some later time, specified in seconds.
StatisticsManager(SipStack &stack, unsigned long intervalSecs=60)
void setInterval(unsigned long intvSecs)
This class is used to get the current system time.
Definition Timer.hxx:31
static uint64_t getTimeMs()
Returns the current clock time in milliseconds.
Definition Timer.hxx:72
unsigned int getTransactionFifoSize() const
unsigned int getNumClientTransactions() const
unsigned int getNumServerTransactions() const
dcm! – add UnusedChecking(_enum) below;
StatusLineType h_StatusLine
Definition Headers.cxx:348
unsigned int responsesSentByMethod[MAX_METHODS]
unsigned int responsesSentByMethodByCode[MAX_METHODS][MaxCode]
unsigned int requestsSentByMethod[MAX_METHODS]
unsigned int responsesRetransmittedByMethod[MAX_METHODS]
unsigned int responsesReceivedByMethodByCode[MAX_METHODS][MaxCode]
unsigned int requestsRetransmittedByMethod[MAX_METHODS]
unsigned int responsesRetransmittedByMethodByCode[MAX_METHODS][MaxCode]
unsigned int requestsReceivedByMethod[MAX_METHODS]
unsigned int responsesReceivedByMethod[MAX_METHODS]