2007-04-12 20:41:46 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
2007-04-12 20:41:46 +00:00
2009-10-02 18:32:40 +00:00
// tool for estimating FLOPS per job for a given app
2008-12-22 00:10:02 +00:00
error_reporting ( E_ALL );
ini_set ( 'display_errors' , true );
ini_set ( 'display_startup_errors' , true );
2007-04-12 20:41:46 +00:00
require_once ( " ../inc/db.inc " );
2009-09-15 18:14:37 +00:00
require_once ( " ../inc/util_ops.inc " );
2007-04-12 20:41:46 +00:00
db_init ();
$hist = array ();
$quantum = 1e10 ;
2007-05-18 22:48:00 +00:00
$mean = 0 ;
$count = 0 ;
$varsum = 0 ;
2007-04-12 20:41:46 +00:00
function handle_result ( $result ) {
global $hist ;
global $quantum ;
2007-05-18 22:48:00 +00:00
global $mean ;
global $count ;
global $varsum ;
2011-07-13 21:50:48 +00:00
$flops = $result -> elapsed_time * $result -> flops_estimate ;
2007-05-18 22:48:00 +00:00
//printf("%e<br>\n", $flops);
2007-04-12 20:41:46 +00:00
$n = ( int ) ( $flops / $quantum );
if ( ! array_key_exists ( $n , $hist )) {
$hist [ $n ] = 0 ;
}
$hist [ $n ] ++ ;
2007-05-18 22:48:00 +00:00
$count ++ ;
$delta = $flops - $mean ;
$mean += $delta / $count ;
$varsum += $delta * ( $flops - $mean );
2007-04-12 20:41:46 +00:00
}
function show_stats () {
2007-05-18 22:48:00 +00:00
global $mean ;
global $count ;
global $varsum ;
global $sum ;
$stdev = sqrt ( $varsum / ( $count - 1 ));
2011-07-13 21:50:48 +00:00
printf ( " mean: %e<br>stdev: %e<br>samples: %d " , $mean , $stdev , $count );
2007-05-18 22:48:00 +00:00
}
function show_stats_hist () { //deprecated
2007-04-12 20:41:46 +00:00
global $hist ;
global $quantum ;
$sum = 0 ;
$n = 0 ;
foreach ( $hist as $i => $v ) {
$sum += $quantum * $i * $v ;
$n += $v ;
}
$mean = $sum / $n ;
echo " mean: " ;
printf ( " %e " , $mean );
$sum = 0 ;
foreach ( $hist as $i => $v ) {
$d = ( $mean - $quantum * $i );
$sum += $d * $d * $v ;
}
$stdev = sqrt ( $sum / $n );
echo " <br>stdev: " ;
printf ( " %e " , $stdev );
}
function show_as_xml () {
global $hist ;
global $quantum ;
echo " <pre> " ;
foreach ( $hist as $i => $v ) {
echo " <bin>
& lt ; value > " ;
printf ( " %e " , $quantum * $i );
echo " </value>
& lt ; count > $v & lt ; / count >
& lt ; / bin >
" ;
}
echo " </pre> " ;
}
function show_as_table () {
global $quantum ;
global $hist ;
echo " <table width=600 border=0 cellborder=0 cellpadding=0> " ;
$keys = array_keys ( $hist );
$start = reset ( $keys );
$end = end ( $keys );
$max = $hist [ $start ];
foreach ( $hist as $v ) {
if ( $v > $max ) $max = $v ;
}
for ( $i = $start ; $i <= $end ; $i ++ ) {
if ( array_key_exists ( $i , $hist )) {
$w = 600 * $hist [ $i ] / $max ;
} else {
$w = 0 ;
}
$f = $i * $quantum ;
echo " <tr><td><font size=-2> " ;
2007-05-18 22:48:00 +00:00
printf ( " %e " , $f );
2007-04-12 20:41:46 +00:00
echo " </font></td><td><img vspace=0 src=http://boinc.berkeley.edu/colors/000000.gif height=10 width= $w ></td></tr> \n " ;
}
echo " </table> " ;
}
2011-07-13 21:50:48 +00:00
function version_select ( $appid ) {
$x = " <select name=app_version_id>
< option value = 0 > All
2007-04-12 20:41:46 +00:00
" ;
2011-07-13 21:50:48 +00:00
$avs = BoincAppVersion :: enum ( " appid= $appid " );
$avs = current_versions ( $avs );
foreach ( $avs as $av ) {
$platform = BoincPlatform :: lookup_id ( $av -> platformid );
$n = $platform -> name ;
if ( strlen ( $av -> plan_class )) {
$n .= " ( $av->plan_class ) " ;
}
$x .= " <option value= $av->id > $n\n " ;
}
$x .= " </select> \n " ;
return $x ;
2007-04-12 20:41:46 +00:00
}
2011-07-13 21:50:48 +00:00
function analyze ( $appid , $app_version_id , $nresults ) {
2007-04-12 20:41:46 +00:00
global $hist ;
2011-07-13 21:50:48 +00:00
$clause = $app_version_id ? " and app_version_id = $app_version_id " : " " ;
2007-04-12 20:41:46 +00:00
2011-07-13 21:50:48 +00:00
$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 " ;
2014-09-04 19:00:09 +00:00
$r = _mysql_query ( $query );
2007-04-12 20:41:46 +00:00
$n = 0 ;
2014-09-04 19:00:09 +00:00
while ( $result = _mysql_fetch_object ( $r )) {
2010-04-16 20:01:13 +00:00
handle_result ( $result );
$n ++ ;
2007-04-12 20:41:46 +00:00
}
2007-04-12 21:53:59 +00:00
if ( ! $n ) {
echo " No done results for that app " ;
exit ;
}
2007-04-12 20:41:46 +00:00
ksort ( $hist );
show_stats ( $hist );
echo " <hr> \n " ;
2008-12-22 00:10:02 +00:00
show_as_table ();
2007-04-12 20:41:46 +00:00
echo " <hr> \n " ;
2008-12-22 00:10:02 +00:00
show_as_xml ();
2007-04-12 20:41:46 +00:00
}
2011-07-13 21:50:48 +00:00
function show_app_select () {
admin_page_head ( " Show FLOPS distribution " );
echo " Select an application:
< form action = job_times . php >
" ;
$apps = BoincApp :: enum ( " deprecated=0 " );
foreach ( $apps as $app ) {
echo " <br><input type=radio name=appid value= $app->id >
$app -> user_friendly_name
" ;
}
echo " <br><br><input type=submit value=OK> " ;
admin_page_tail ();
}
function show_form ( $appid ) {
2010-02-26 21:34:20 +00:00
admin_page_head ( " Show FLOPS distribution " );
2007-04-12 20:41:46 +00:00
echo "
< form method = get action = job_times . php >
2011-07-13 21:50:48 +00:00
< input type = hidden name = appid value = $appid >
2010-02-26 21:34:20 +00:00
" ;
start_table ();
2011-07-13 21:50:48 +00:00
row2 ( " App version: " , version_select ( $appid ));
row2 ( " Resolution:<br><span class=note>(if you see only one bar, use a smaller value)</span> " , " <input name=quantum value=1e12> " );
2010-02-26 21:34:20 +00:00
row2 ( " Sample size (# of jobs): " , " <input name=nresults value=1000> " );
row2 ( " " , " <input type=submit name=submit value=OK> " );
end_table ();
echo "
2007-04-12 20:41:46 +00:00
</ form >
" ;
2010-02-26 21:34:20 +00:00
admin_page_tail ();
2007-04-12 20:41:46 +00:00
}
2010-02-26 21:34:20 +00:00
if ( get_str ( 'submit' , true ) == 'OK' ) {
2007-04-12 21:40:41 +00:00
set_time_limit ( 0 );
2011-07-13 21:50:48 +00:00
$appid = get_int ( 'appid' );
$app_version_id = get_int ( 'app_version_id' );
$quantum = ( double )( get_str ( 'quantum' ));
$nresults = get_int ( 'nresults' );
analyze ( $appid , $app_version_id , $nresults );
2007-04-12 20:41:46 +00:00
} else {
2011-07-13 21:50:48 +00:00
$appid = get_int ( 'appid' , true );
if ( $appid ) {
show_form ( $appid );
} else {
show_app_select ();
}
2007-04-12 20:41:46 +00:00
}
?>