|
1 /* |
|
2 * LIBOIL - Library of Optimized Inner Loops |
|
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org> |
|
4 * All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions |
|
8 * are met: |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
12 * notice, this list of conditions and the following disclaimer in the |
|
13 * documentation and/or other materials provided with the distribution. |
|
14 * |
|
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
|
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
25 * POSSIBILITY OF SUCH DAMAGE. |
|
26 */ |
|
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
28 |
|
29 #ifdef HAVE_CONFIG_H |
|
30 #include <config.h> |
|
31 #endif |
|
32 |
|
33 #include <liboil/liboilprofile.h> |
|
34 #include <liboil/liboildebug.h> |
|
35 |
|
36 #ifdef HAVE_SYS_TIME_H |
|
37 #include <sys/time.h> |
|
38 #endif |
|
39 #include <time.h> |
|
40 #include <string.h> |
|
41 #include <math.h> |
|
42 |
|
43 #ifdef __SYMBIAN32__ |
|
44 #ifdef __ARMCC__ |
|
45 #pragma diag_remark 68 |
|
46 #endif//__ARMCC__ |
|
47 #endif//__SYMBIAN32__ |
|
48 |
|
49 /** |
|
50 * SECTION:liboilprofile |
|
51 * @title:OilProfile |
|
52 * @short_description: |
|
53 * Measuring the length of time needed to execute Liboil functions. |
|
54 * |
|
55 */ |
|
56 |
|
57 /** |
|
58 * oil_profile_init: |
|
59 * @prof: the OilProfile structure |
|
60 * |
|
61 * Initializes a profiling structure. |
|
62 */ |
|
63 #ifdef __SYMBIAN32__ |
|
64 EXPORT_C |
|
65 #endif |
|
66 void |
|
67 oil_profile_init (OilProfile *prof) |
|
68 { |
|
69 memset(prof, 0, sizeof(OilProfile)); |
|
70 |
|
71 prof->min = -1; |
|
72 |
|
73 } |
|
74 |
|
75 /** |
|
76 * oil_profile_stop_handle: |
|
77 * @prof: the OilProfile structure |
|
78 * |
|
79 * Handles post-processing of a single profiling run. |
|
80 * |
|
81 * FIXME: need more info |
|
82 */ |
|
83 #ifdef __SYMBIAN32__ |
|
84 EXPORT_C |
|
85 #endif |
|
86 void |
|
87 oil_profile_stop_handle (OilProfile *prof) |
|
88 { |
|
89 int i; |
|
90 |
|
91 prof->last = prof->stop - prof->start; |
|
92 |
|
93 prof->total += prof->last; |
|
94 prof->n++; |
|
95 |
|
96 if (prof->last < prof->min) prof->min = prof->last; |
|
97 |
|
98 for(i=0;i<prof->hist_n;i++) { |
|
99 if (prof->last == prof->hist_time[i]) { |
|
100 prof->hist_count[i]++; |
|
101 break; |
|
102 } |
|
103 } |
|
104 if (i == prof->hist_n && prof->hist_n < OIL_PROFILE_HIST_LENGTH) { |
|
105 prof->hist_time[prof->hist_n] = prof->last; |
|
106 prof->hist_count[prof->hist_n] = 1; |
|
107 prof->hist_n++; |
|
108 } |
|
109 } |
|
110 |
|
111 /** |
|
112 * oil_profile_get_ave_std: |
|
113 * @prof: the OilProfile structure |
|
114 * @ave_p: pointer to average |
|
115 * @std_p: pointer to standard deviation |
|
116 * |
|
117 * Calculates the average and standard deviation of a number of |
|
118 * profiling runs, and places the results in the locations |
|
119 * provided by @ave_p and @std_p. Either @ave_p and @std_p may |
|
120 * be NULL, in which case the values will not be written. |
|
121 */ |
|
122 #ifdef __SYMBIAN32__ |
|
123 EXPORT_C |
|
124 #endif |
|
125 void |
|
126 oil_profile_get_ave_std (OilProfile *prof, double *ave_p, double *std_p) |
|
127 { |
|
128 double ave; |
|
129 double std; |
|
130 int max_i; |
|
131 double off; |
|
132 double s; |
|
133 double s2; |
|
134 int i; |
|
135 int n; |
|
136 double x; |
|
137 |
|
138 do { |
|
139 s = s2 = 0; |
|
140 n = 0; |
|
141 max_i = -1; |
|
142 for(i=0;i<10;i++){ |
|
143 x = prof->hist_time[i]; |
|
144 s2 += x * x * prof->hist_count[i]; |
|
145 s += x * prof->hist_count[i]; |
|
146 n += prof->hist_count[i]; |
|
147 if (prof->hist_count[i] > 0) { |
|
148 if (max_i == -1 || prof->hist_time[i] > prof->hist_time[max_i]) { |
|
149 max_i = i; |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 ave = s / n; |
|
155 std = sqrt (s2 - s * s / n + n*n) / (n-1); |
|
156 off = (prof->hist_time[max_i] - ave)/std; |
|
157 |
|
158 if (off > 4.0) { |
|
159 prof->hist_count[max_i] = 0; |
|
160 } |
|
161 } while (off > 4.0); |
|
162 |
|
163 if (ave_p) *ave_p = ave; |
|
164 if (std_p) *std_p = std; |
|
165 } |
|
166 |
|
167 unsigned long (*_oil_profile_stamp)(void); |
|
168 |
|
169 /** |
|
170 * oil_profile_stamp: |
|
171 * |
|
172 * Creates a timestamp based on a CPU-specific high-frequency |
|
173 * counter, if available. |
|
174 * |
|
175 * Returns: a timestamp |
|
176 */ |
|
177 #ifdef __SYMBIAN32__ |
|
178 EXPORT_C |
|
179 #endif |
|
180 unsigned long |
|
181 oil_profile_stamp (void) |
|
182 { |
|
183 return _oil_profile_stamp(); |
|
184 } |
|
185 |