root/branches/ppalmers-streaming/src/libutil/StreamStatistics.cpp

Revision 707, 2.2 kB (checked in by ppalmers, 16 years ago)

- code cleanup
- make transmit handler AMDTP compliant (don't send too much in advance)

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #include "StreamStatistics.h"
25 #include <stdio.h>
26
27 namespace Streaming {
28 IMPL_DEBUG_MODULE( StreamStatistics, StreamStatistics, DEBUG_LEVEL_VERBOSE );
29
30 StreamStatistics::StreamStatistics()
31     : m_name("")
32     , m_count(0)
33     , m_average(0.0)
34     , m_min(0x7FFFFFFF)
35     , m_max(0)
36     , m_sum(0)
37 {
38     reset();
39 }
40
41 void StreamStatistics::mark(int value) {
42     if(value>m_max) m_max=value;
43     if(value<m_min) m_min=value;
44     m_count++;
45     m_sum+=value;
46     m_average=(1.0*m_sum)/(1.0*m_count);
47 }
48
49 void StreamStatistics::signal(unsigned int val) {
50     if (val <= MAX_SIGNAL_VALUE) {
51         m_signalled[val]++;
52     }
53 }
54
55 void StreamStatistics::dumpInfo() {
56     debugOutputShort( DEBUG_LEVEL_VERBOSE,
57                       "--- Stats for %s: min=%ld avg=%f max=%ld cnt=%ld sum=%ld\n",
58                       m_name.c_str(), m_min, m_average, m_max, m_count, m_sum);
59     debugOutputShort( DEBUG_LEVEL_VERBOSE, "    Signal stats\n");
60     for (unsigned int i=0;i <= MAX_SIGNAL_VALUE; i++) {
61         debugOutputShort(DEBUG_LEVEL_VERBOSE,
62                          "     Stats for %3u: %8u\n",
63                          i, m_signalled[i]);
64     }
65 }
66
67 void StreamStatistics::reset() {
68     m_count=0;
69     m_average= 0.0;
70     m_min=0x7FFFFFFF;
71     m_max=0;
72     m_sum=0;
73
74     for (unsigned int i=0;i <= MAX_SIGNAL_VALUE; i++) {
75         m_signalled[i]=0;
76     }
77 }
78
79 }
Note: See TracBrowser for help on using the browser.