StatsTimer.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/synch/StatsTimer.cpp#10 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/synch/StatsTimer.h"
00026 #include "fennel/common/StatsSource.h"
00027 #include "fennel/common/StatsTarget.h"
00028 
00029 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/synch/StatsTimer.cpp#10 $");
00030 
00031 StatsTimer::StatsTimer(
00032     StatsTarget &target,
00033     uint intervalInMillisInit)
00034     : timerThread(*this)
00035 {
00036     pTarget = ⌖
00037     intervalInMillis = intervalInMillisInit;
00038 }
00039 
00040 StatsTimer::StatsTimer(
00041     uint intervalInMillisInit)
00042     : timerThread(*this)
00043 {
00044     pTarget = NULL;
00045     intervalInMillis = intervalInMillisInit;
00046 }
00047 
00048 StatsTimer::~StatsTimer()
00049 {
00050 }
00051 
00052 void StatsTimer::setTarget(StatsTarget &target)
00053 {
00054     pTarget = ⌖
00055 }
00056 
00057 void StatsTimer::addSource(SharedStatsSource pSource)
00058 {
00059     sources.push_back(pSource);
00060 }
00061 
00062 void StatsTimer::start()
00063 {
00064     timerThread.start();
00065 }
00066 
00067 void StatsTimer::stop()
00068 {
00069     timerThread.stop();
00070 
00071     // clear target counters
00072     if (pTarget) {
00073         pTarget->beginSnapshot();
00074         pTarget->endSnapshot();
00075     }
00076 
00077     sources.clear();
00078 }
00079 
00080 uint StatsTimer::getTimerIntervalMillis()
00081 {
00082     return intervalInMillis;
00083 }
00084 
00085 void StatsTimer::onThreadStart()
00086 {
00087     if (pTarget) {
00088         pTarget->onThreadStart();
00089     }
00090 }
00091 
00092 void StatsTimer::onThreadEnd()
00093 {
00094     if (pTarget) {
00095         pTarget->onThreadEnd();
00096     }
00097 }
00098 
00099 void StatsTimer::onTimerInterval()
00100 {
00101     if (!pTarget) {
00102         return;
00103     }
00104     pTarget->beginSnapshot();
00105     for (uint i = 0; i < sources.size(); ++i) {
00106         sources[i]->writeStats(*pTarget);
00107     }
00108     pTarget->endSnapshot();
00109 }
00110 
00111 void StatsTarget::onThreadStart()
00112 {
00113     // by default do nothing
00114 }
00115 
00116 void StatsTarget::onThreadEnd()
00117 {
00118     // by default do nothing
00119 }
00120 
00121 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/synch/StatsTimer.cpp#10 $");
00122 
00123 // End StatsTimer.cpp

Generated on Mon Jun 22 04:00:20 2009 for Fennel by  doxygen 1.5.1