2 * Copyright (C) 2005-2008 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "PerformanceStats.h"
23 #include "PerformanceSample.h"
28 CPerformanceStats::CPerformanceStats()
33 CPerformanceStats::~CPerformanceStats()
35 map
<string
, PerformanceCounter
*>::iterator iter
= m_mapStats
.begin();
36 while (iter
!= m_mapStats
.end())
44 void CPerformanceStats::AddSample(const string
&strStatName
, const PerformanceCounter
&perf
)
46 map
<string
, PerformanceCounter
*>::iterator iter
= m_mapStats
.find(strStatName
);
47 if (iter
== m_mapStats
.end())
48 m_mapStats
[strStatName
] = new PerformanceCounter(perf
);
51 iter
->second
->m_time
+= perf
.m_time
;
52 iter
->second
->m_samples
+= perf
.m_samples
;
56 void CPerformanceStats::AddSample(const string
&strStatName
, double dTime
)
58 AddSample(strStatName
, *(new PerformanceCounter(dTime
)));
61 void CPerformanceStats::DumpStats()
63 double dError
= CPerformanceSample::GetEstimatedError();
64 CLog::Log(LOGINFO
, "%s - estimated error: %f", __FUNCTION__
, dError
);
65 CLog::Log(LOGINFO
, "%s - ignore user/sys values when sample count is low", __FUNCTION__
);
67 map
<string
, PerformanceCounter
*>::iterator iter
= m_mapStats
.begin();
68 while (iter
!= m_mapStats
.end())
70 double dAvg
= iter
->second
->m_time
/ (double)iter
->second
->m_samples
;
71 double dAvgUser
= iter
->second
->m_user
/ (double)iter
->second
->m_samples
;
72 double dAvgSys
= iter
->second
->m_sys
/ (double)iter
->second
->m_samples
;
73 CLog::Log(LOGINFO
, "%s - counter <%s>. avg duration: <%f sec>, avg user: <%f>, avg sys: <%f> (%llu samples)",
74 __FUNCTION__
, iter
->first
.c_str(), dAvg
, dAvgUser
, dAvgSys
, iter
->second
->m_samples
);