Debian Codegraph @

external/portaudio/pa_cpuload.c

raw symbols SCIP
1 /*
2 * $Id$
3 * Portable Audio I/O Library CPU Load measurement functions
4 * Portable CPU load measurement facility.
5 *
6 * Based on the Open Source API proposed by Ross Bencina
7 * Copyright (c) 2002 Ross Bencina
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files
11 * (the "Software"), to deal in the Software without restriction,
12 * including without limitation the rights to use, copy, modify, merge,
13 * publish, distribute, sublicense, and/or sell copies of the Software,
14 * and to permit persons to whom the Software is furnished to do so,
15 * subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29 /*
30 * The text above constitutes the entire PortAudio license; however,
31 * the PortAudio community also makes the following non-binding requests:
32 *
33 * Any person wishing to distribute modifications to the Software is
34 * requested to send the modifications to the original developer so that
35 * they can be incorporated into the canonical version. It is also
36 * requested that these non-binding requests be included along with the
37 * license above.
38 */
39
40 /** @file
41 @ingroup common_src
42
43 @brief Functions to assist in measuring the CPU utilization of a callback
44 stream. Used to implement the Pa_GetStreamCpuLoad() function.
45
46 @todo Dynamically calculate the coefficients used to smooth the CPU Load
47 Measurements over time to provide a uniform characterisation of CPU Load
48 independent of rate at which PaUtil_BeginCpuLoadMeasurement /
49 PaUtil_EndCpuLoadMeasurement are called. see http://www.portaudio.com/trac/ticket/113
50 */
51
52
53 #include "pa_cpuload.h"cxx . . $ `<file>/external/portaudio/pa_cpuload.h`/
54
55 #include <assert.h>
56
57 #include "pa_util.h"cxx . . $ `<file>/external/portaudio/pa_util.h`/ /* for PaUtil_GetTime() */
58
59
60 void PaUtil_InitializeCpuLoadMeasurercxx . . $ PaUtil_InitializeCpuLoadMeasurer(dc72d8645bcc5215).( PaUtilCpuLoadMeasurercxx . . $ PaUtilCpuLoadMeasurer#* measurer, double sampleRate )
61 {
62 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!( sampleRate > 0 );
63
64 measurer->samplingPeriodcxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#samplingPeriod. = 1. / sampleRate;
65 measurer->averageLoadcxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#averageLoad. = 0.;
66 }
67
68 void PaUtil_ResetCpuLoadMeasurercxx . . $ PaUtil_ResetCpuLoadMeasurer(798ecf6f58992a18).( PaUtilCpuLoadMeasurercxx . . $ PaUtilCpuLoadMeasurer#* measurer )
69 {
70 measurer->averageLoadcxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#averageLoad. = 0.;
71 }
72
73 void PaUtil_BeginCpuLoadMeasurementcxx . . $ PaUtil_BeginCpuLoadMeasurement(798ecf6f58992a18).( PaUtilCpuLoadMeasurercxx . . $ PaUtilCpuLoadMeasurer#* measurer )
74 {
75 measurer->measurementStartTimecxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#measurementStartTime. = PaUtil_GetTimecxx . . $ PaUtil_GetTime(31fa7155c10fdd13).();
76 }
77
78
79 void PaUtil_EndCpuLoadMeasurementcxx . . $ PaUtil_EndCpuLoadMeasurement(394649c2147554a2).( PaUtilCpuLoadMeasurercxx . . $ PaUtilCpuLoadMeasurer#* measurer, unsigned long framesProcessed )
80 {
81 double measurementEndTime, secondsFor100Percent, measuredLoad;
82
83 if( framesProcessed > 0 ){
84 measurementEndTime = PaUtil_GetTimecxx . . $ PaUtil_GetTime(31fa7155c10fdd13).();
85
86 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!( framesProcessed > 0 );
87 secondsFor100Percent = framesProcessed * measurer->samplingPeriodcxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#samplingPeriod.;
88
89 measuredLoad = (measurementEndTime - measurer->measurementStartTimecxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#measurementStartTime.) / secondsFor100Percent;
90
91 /* Low pass filter the calculated CPU load to reduce jitter using a simple IIR low pass filter. */
92 /** FIXME @todo these coefficients shouldn't be hardwired see: http://www.portaudio.com/trac/ticket/113 */
93 #define LOWPASS_COEFFICIENT_0cxx . . $ `external/portaudio/pa_cpuload.c:93:9`! (0.9)
94 #define LOWPASS_COEFFICIENT_1cxx . . $ `external/portaudio/pa_cpuload.c:94:9`! (0.99999 - LOWPASS_COEFFICIENT_0cxx . . $ `external/portaudio/pa_cpuload.c:93:9`!)
95
96 measurer->averageLoadcxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#averageLoad. = (LOWPASS_COEFFICIENT_0cxx . . $ `external/portaudio/pa_cpuload.c:93:9`! * measurer->averageLoadcxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#averageLoad.) +
97 (LOWPASS_COEFFICIENT_1cxx . . $ `external/portaudio/pa_cpuload.c:94:9`! * measuredLoad);
98 }
99 }
100
101
102 double PaUtil_GetCpuLoadcxx . . $ PaUtil_GetCpuLoad(6d83850f5e898215).( PaUtilCpuLoadMeasurercxx . . $ PaUtilCpuLoadMeasurer#* measurer )
103 {
104 return measurer->averageLoadcxx . . $ $anonymous_type_b8cdcef88d4fa6e4_0#averageLoad.;
105 }