reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TimeAccumulate.hxx
Go to the documentation of this file.
1#ifndef TimeAccumulate_hxx
2#define TimeAccumulate_hxx
3
4#include <map>
5
6#include "rutil/Data.hxx"
7#include "rutil/Lock.hxx"
8#include "rutil/Mutex.hxx"
9#include "rutil/Timer.hxx"
10
11namespace resip
12{
13
20{
21 private:
22 struct Accumulator
23 {
24 uint64_t totalTime;
25 size_t count;
26 };
27
28 public:
29#if 1
30 TimeAccumulate(const Data& name)
31 : mName(name),
32 mStart(Timer::getTimeMs())
33 {}
34
36 {
38 end -= mStart;
39 Lock lock(TimeAccumulate::mMutex);
40
41 Accumulator& acc = TimeAccumulate::mTimes[mName];
42 acc.count += 1;
43 acc.totalTime += end;
44 }
45#else
46 TimeAccumulate(const char* chars)
47 : mName(Data::Empty),
48 mStart(0)
49 {}
50
51 TimeAccumulate(const Data& name)
52 : mName(Data::Empty),
53 mStart(0)
54 {}
55
57 {
58 }
59#endif
60
61 static uint64_t getTime(const Data& name)
62 {
63 Lock lock(TimeAccumulate::mMutex);
64 return TimeAccumulate::mTimes[name].totalTime;
65 }
66
67 static size_t getCount(const Data& name)
68 {
69 Lock lock(TimeAccumulate::mMutex);
70 return TimeAccumulate::mTimes[name].count;
71 }
72
73 static void dump();
74 static void clear();
75
76 class Guard
77 {
78 public:
79 explicit Guard(uint64_t& accumulator)
80 : mAccumulator(accumulator)
81 {
82 mAccumulator -= Timer::getTimeMs();
83 }
85 {
86 mAccumulator += Timer::getTimeMs();
87 }
88
89 private:
90 uint64_t& mAccumulator;
91 };
92
93 private:
94 typedef std::map<Data, Accumulator> TimeMap;
95
96 const Data mName;
97 const uint64_t mStart;
98
99 static Mutex mMutex;
100 static TimeMap mTimes;
101};
102
103}
104#endif
105
106/* ====================================================================
107 * The Vovida Software License, Version 1.0
108 *
109 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
110 *
111 * Redistribution and use in source and binary forms, with or without
112 * modification, are permitted provided that the following conditions
113 * are met:
114 *
115 * 1. Redistributions of source code must retain the above copyright
116 * notice, this list of conditions and the following disclaimer.
117 *
118 * 2. Redistributions in binary form must reproduce the above copyright
119 * notice, this list of conditions and the following disclaimer in
120 * the documentation and/or other materials provided with the
121 * distribution.
122 *
123 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
124 * and "Vovida Open Communication Application Library (VOCAL)" must
125 * not be used to endorse or promote products derived from this
126 * software without prior written permission. For written
127 * permission, please contact vocal@vovida.org.
128 *
129 * 4. Products derived from this software may not be called "VOCAL", nor
130 * may "VOCAL" appear in their name, without prior written
131 * permission of Vovida Networks, Inc.
132 *
133 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
134 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
135 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
136 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
137 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
138 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
139 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
140 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
141 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
142 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
144 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
145 * DAMAGE.
146 *
147 * ====================================================================
148 *
149 * This software consists of voluntary contributions made by Vovida
150 * Networks, Inc. and many individuals on behalf of Vovida Networks,
151 * Inc. For more information on Vovida Networks, Inc., please see
152 * <http://www.vovida.org/>.
153 *
154 */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
Guard(uint64_t &accumulator)
Accumulates time and count by distinct string.
static uint64_t getTime(const Data &name)
static size_t getCount(const Data &name)
TimeAccumulate(const Data &name)
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
dcm! – add UnusedChecking(_enum) below;
std::mutex Mutex
A semaphore that can be locked by only one thread at a time.
Definition Mutex.hxx:37
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...
Definition Lock.hxx:28
unsigned long long uint64_t
Definition Stun.hxx:39