1 | <?php |
||||||
2 | // This file is part of BOINC. |
||||||
3 | // http://boinc.berkeley.edu |
||||||
4 | // Copyright (C) 2008 University of California |
||||||
5 | // |
||||||
6 | // BOINC is free software; you can redistribute it and/or modify it |
||||||
7 | // under the terms of the GNU Lesser General Public License |
||||||
8 | // as published by the Free Software Foundation, |
||||||
9 | // either version 3 of the License, or (at your option) any later version. |
||||||
10 | // |
||||||
11 | // BOINC is distributed in the hope that it will be useful, |
||||||
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
14 | // See the GNU Lesser General Public License for more details. |
||||||
15 | // |
||||||
16 | // You should have received a copy of the GNU Lesser General Public License |
||||||
17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||||||
18 | |||||||
19 | // tool for estimating FLOPS per job for a given app |
||||||
20 | |||||||
21 | error_reporting(E_ALL); |
||||||
22 | ini_set('display_errors', true); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
23 | ini_set('display_startup_errors', true); |
||||||
24 | |||||||
25 | require_once("../inc/db.inc"); |
||||||
26 | require_once("../inc/util_ops.inc"); |
||||||
27 | |||||||
28 | db_init(); |
||||||
29 | |||||||
30 | $hist = array(); |
||||||
31 | $quantum = 1e10; |
||||||
32 | $mean = 0; |
||||||
33 | $count = 0; |
||||||
34 | $varsum = 0; |
||||||
35 | |||||||
36 | function handle_result($result) { |
||||||
37 | global $hist; |
||||||
38 | global $quantum; |
||||||
39 | global $mean; |
||||||
40 | global $count; |
||||||
41 | global $varsum; |
||||||
42 | |||||||
43 | $flops = $result->elapsed_time * $result->flops_estimate; |
||||||
44 | //printf("%e<br>\n", $flops); |
||||||
45 | $n = (int) ($flops/$quantum); |
||||||
46 | if (!array_key_exists($n, $hist)) { |
||||||
47 | $hist[$n] = 0; |
||||||
48 | } |
||||||
49 | $hist[$n]++; |
||||||
50 | $count++; |
||||||
51 | $delta = $flops - $mean; |
||||||
52 | $mean += $delta/$count; |
||||||
53 | $varsum += $delta*($flops-$mean); |
||||||
54 | } |
||||||
55 | |||||||
56 | function show_stats() { |
||||||
57 | global $mean; |
||||||
58 | global $count; |
||||||
59 | global $varsum; |
||||||
60 | global $sum; |
||||||
61 | |||||||
62 | $stdev = sqrt($varsum/($count-1)); |
||||||
63 | printf("mean: %e<br>stdev: %e<br>samples: %d", $mean, $stdev, $count); |
||||||
64 | } |
||||||
65 | |||||||
66 | function show_stats_hist() { //deprecated |
||||||
0 ignored issues
–
show
|
|||||||
67 | global $hist; |
||||||
68 | global $quantum; |
||||||
69 | |||||||
70 | $sum = 0; |
||||||
71 | $n = 0; |
||||||
72 | foreach ($hist as $i=>$v) { |
||||||
0 ignored issues
–
show
|
|||||||
73 | $sum += $quantum*$i*$v; |
||||||
74 | $n += $v; |
||||||
75 | } |
||||||
76 | $mean = $sum/$n; |
||||||
77 | echo "mean: "; |
||||||
78 | printf("%e", $mean); |
||||||
79 | |||||||
80 | $sum = 0; |
||||||
81 | foreach ($hist as $i=>$v) { |
||||||
0 ignored issues
–
show
|
|||||||
82 | $d = ($mean - $quantum*$i); |
||||||
83 | $sum += $d*$d*$v; |
||||||
84 | } |
||||||
85 | $stdev = sqrt($sum/$n); |
||||||
86 | echo "<br>stdev: "; |
||||||
87 | printf("%e", $stdev); |
||||||
88 | } |
||||||
89 | |||||||
90 | function show_as_xml() { |
||||||
91 | global $hist; |
||||||
92 | global $quantum; |
||||||
93 | echo "<pre>"; |
||||||
94 | foreach ($hist as $i=>$v) { |
||||||
0 ignored issues
–
show
|
|||||||
95 | echo "<bin> |
||||||
96 | <value>"; |
||||||
97 | printf("%e", $quantum*$i); |
||||||
98 | echo "</value> |
||||||
99 | <count>$v</count> |
||||||
100 | </bin> |
||||||
101 | "; |
||||||
102 | } |
||||||
103 | echo "</pre>"; |
||||||
104 | } |
||||||
105 | |||||||
106 | function show_as_table() { |
||||||
107 | global $quantum; |
||||||
108 | global $hist; |
||||||
109 | |||||||
110 | echo "<table width=600 border=0 cellborder=0 cellpadding=0>"; |
||||||
111 | $keys = array_keys($hist); |
||||||
112 | $start = reset($keys); |
||||||
113 | $end = end($keys); |
||||||
114 | |||||||
115 | $max = $hist[$start]; |
||||||
116 | foreach ($hist as $v) { |
||||||
117 | if ($v > $max) $max = $v; |
||||||
118 | } |
||||||
119 | |||||||
120 | for ($i=$start; $i<=$end; $i++) { |
||||||
121 | if (array_key_exists($i, $hist)) { |
||||||
122 | $w = 600*$hist[$i]/$max; |
||||||
123 | } else { |
||||||
124 | $w = 0; |
||||||
125 | } |
||||||
126 | $f = $i*$quantum; |
||||||
127 | echo "<tr><td><font size=-2>"; |
||||||
128 | printf("%e ", $f); |
||||||
129 | echo "</font></td><td><img vspace=0 src=https://boinc.berkeley.edu/colors/000000.gif height=10 width=$w></td></tr>\n"; |
||||||
130 | } |
||||||
131 | echo "</table>"; |
||||||
132 | } |
||||||
133 | |||||||
134 | function version_select($appid) { |
||||||
135 | $x = "<select name=app_version_id> |
||||||
136 | <option value=0>All |
||||||
137 | "; |
||||||
138 | $avs = BoincAppVersion::enum("appid=$appid"); |
||||||
139 | $avs = current_versions($avs); |
||||||
140 | foreach ($avs as $av) { |
||||||
141 | $platform = BoincPlatform::lookup_id($av->platformid); |
||||||
142 | $n = $platform->name; |
||||||
143 | if (strlen($av->plan_class)) { |
||||||
144 | $n .= " ($av->plan_class)"; |
||||||
145 | } |
||||||
146 | $x .= "<option value=$av->id> $n\n"; |
||||||
147 | } |
||||||
148 | $x .= "</select>\n"; |
||||||
149 | return $x; |
||||||
150 | } |
||||||
151 | |||||||
152 | function analyze($appid, $app_version_id, $nresults) { |
||||||
153 | global $hist; |
||||||
154 | |||||||
155 | $clause = $app_version_id?" and app_version_id = $app_version_id ":""; |
||||||
156 | |||||||
157 | $query = "select id, server_state, outcome, elapsed_time, flops_estimate from result where server_state=5 and appid=$appid and outcome=1 and validate_state=1 $clause order by id desc limit $nresults"; |
||||||
158 | $r = _mysql_query($query); |
||||||
159 | |||||||
160 | $n = 0; |
||||||
161 | while ($result = _mysql_fetch_object($r)) { |
||||||
162 | handle_result($result); |
||||||
163 | $n++; |
||||||
164 | } |
||||||
165 | |||||||
166 | if (!$n) { |
||||||
167 | echo "No done results for that app"; |
||||||
168 | exit; |
||||||
0 ignored issues
–
show
|
|||||||
169 | } |
||||||
170 | |||||||
171 | ksort($hist); |
||||||
172 | show_stats($hist); |
||||||
0 ignored issues
–
show
The call to
show_stats() has too many arguments starting with $hist .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
173 | echo "<hr>\n"; |
||||||
174 | show_as_table(); |
||||||
175 | echo "<hr>\n"; |
||||||
176 | show_as_xml(); |
||||||
177 | } |
||||||
178 | |||||||
179 | function show_app_select() { |
||||||
180 | admin_page_head("Show FLOPS distribution"); |
||||||
181 | echo "Select an application: |
||||||
182 | <form action=job_times.php> |
||||||
183 | "; |
||||||
184 | $apps = BoincApp::enum("deprecated=0"); |
||||||
185 | |||||||
186 | foreach($apps as $app) { |
||||||
187 | echo "<br><input type=radio name=appid value=$app->id> |
||||||
188 | $app->user_friendly_name |
||||||
189 | "; |
||||||
190 | } |
||||||
191 | echo "<br><br><input class=\"btn btn-default\" type=submit value=OK>"; |
||||||
192 | admin_page_tail(); |
||||||
193 | } |
||||||
194 | |||||||
195 | function show_form($appid) { |
||||||
196 | admin_page_head("Show FLOPS distribution"); |
||||||
197 | echo " |
||||||
198 | <form method=get action=job_times.php> |
||||||
199 | <input type=hidden name=appid value=$appid> |
||||||
200 | "; |
||||||
201 | start_table(); |
||||||
202 | row2("App version:", version_select($appid)); |
||||||
203 | row2("Resolution:<br><p class=\"text-muted\">(if you see only one bar, use a smaller value)</p>", "<input name=quantum value=1e12>"); |
||||||
204 | row2("Sample size (# of jobs):", "<input name=nresults value=1000>"); |
||||||
205 | row2("", "<input class=\"btn btn-default\" type=submit name=submit value=OK>"); |
||||||
206 | end_table(); |
||||||
207 | echo " |
||||||
208 | </form> |
||||||
209 | "; |
||||||
210 | admin_page_tail(); |
||||||
211 | } |
||||||
212 | |||||||
213 | if (get_str('submit', true)=='OK') { |
||||||
214 | set_time_limit(0); |
||||||
215 | $appid = get_int('appid'); |
||||||
216 | $app_version_id = get_int('app_version_id'); |
||||||
217 | $quantum = (double)(get_str('quantum')); |
||||||
218 | $nresults = get_int('nresults'); |
||||||
219 | analyze($appid, $app_version_id, $nresults); |
||||||
220 | } else { |
||||||
221 | $appid = get_int('appid', true); |
||||||
222 | if ($appid) { |
||||||
223 | show_form($appid); |
||||||
224 | } else { |
||||||
225 | show_app_select(); |
||||||
226 | } |
||||||
227 | } |
||||||
228 | |||||||
229 | ?> |
||||||
230 |