Changeset 303


Ignore:
Timestamp:
04/16/07 16:28:06 (17 years ago)
Author:
bastiaans
Message:

web/addons/job_monarch/image.php:

web/addons/job_monarch/overview.php:

  • removed function makeTime -> moved to libtoga.php

web/addons/job_monarch/libtoga.php:

Location:
trunk/web/addons/job_monarch
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/job_monarch/image.php

    r300 r303  
    3838if( isset($user) && ($user!='')) $filter[user]=$user;
    3939if( isset($queue) && ($queue!='')) $filter[queue]=$queue;
     40
     41function drawHostImage() {
     42
     43        global $clustername, $hostname;
     44
     45        $data_gatherer = new DataGatherer( $clustername );
     46        $data_gatherer->parseXML();
     47
     48        if( $data_gatherer->isJobmonRunning() )
     49                $ic = new HostImage( $data_gatherer, $clustername, $hostname );
     50        else
     51                $ic = new EmptyImage();
     52
     53        $ic->draw();
     54}
    4055
    4156function drawSmallClusterImage() {
     
    99114                break;
    100115
     116        case "hostimage":
     117
     118                drawHostImage();
     119       
     120                break;
     121
    101122        default:
    102123
  • trunk/web/addons/job_monarch/libtoga.php

    r301 r303  
    488488        }
    489489
     490        function getNode( $node ) {
     491                $handler = $this->xmlhandler;
     492                return $handler->getNode( $node );
     493        }
     494
    490495        function getCpus() {
    491496                $handler = $this->xmlhandler;
     
    496501                $handler = $this->xmlhandler;
    497502                return $handler->getJobs();
     503        }
     504
     505        function getJob( $job ) {
     506                $handler = $this->xmlhandler;
     507                return $handler->getJob( $job );
    498508        }
    499509
     
    726736        }
    727737
     738        function getNode( $node ) {
     739
     740                $nodes = &$this->nodes;
     741                if( isset( $nodes[$node] ) )
     742                        return $nodes[$node];
     743                else
     744                        return NULL;
     745        }
     746
    728747        function getJobs() {
    729748                return $this->jobs;
     749        }
     750
     751        function getJob( $job ) {
     752
     753                $jobs = &$this->jobs;
     754                if( isset( $jobs[$job] ) )
     755                        return $jobs[$job];
     756                else
     757                        return NULL;
    730758        }
    731759
     
    10521080}
    10531081
    1054 //$my_data = new DataGatherer();
    1055 //$my_data->parseXML();
    1056 //$my_data->printInfo();
    1057 
    1058 //$ic = new ClusterImage( "LISA Cluster" );
    1059 //$ic->draw();
     1082class HostImage {
     1083
     1084        var $data_gather, $cluster, $host, $node, $image;
     1085        var $headerstrlen;
     1086
     1087        function HostImage( $data_gather, $cluster, $host ) {
     1088
     1089                $this->data_gather      = $data_gather;
     1090                $this->cluster          = $cluster;
     1091                $this->host             = $host;
     1092                $this->y_offset         = 0;
     1093                $this->font             = 2;
     1094                $this->fontspaceing     = 2;
     1095                $this->headerstrlen     = array();
     1096
     1097                $this->fontheight       = ImageFontHeight( $this->font );
     1098                $this->fontwidth        = ImageFontWidth( $this->font );
     1099
     1100                $dg                     = &$this->data_gather;
     1101                $this->node             = &$dg->getNode( $this->host );
     1102                $n                      = &$this->node;
     1103                $this->njobs            = $n->getJobs();
     1104        }
     1105
     1106        function drawJobs() {
     1107
     1108                $dg                     = &$this->data_gather;
     1109                $colorblack             = imageColorAllocate( $this->image, 0, 0, 0 );
     1110
     1111                for( $n = 0; $n < count( $this->njobs ); $n++ ) {
     1112
     1113                        $jobid                  = $this->njobs[$n];
     1114                        $jobinfo                = $dg->getJob( $jobid );
     1115
     1116                        $xoffset                = 5;
     1117                        imageString( $this->image, $this->font, $xoffset, $this->y_offset, strval( $jobid ), $colorblack );
     1118
     1119                        foreach( $this->headerstrlen as $headername => $headerlen ) {
     1120
     1121                                if( $headername == 'nodes' ) {
     1122                                        $attrval        = strval( count( $jobinfo[nodes] ) );
     1123                                } else if( $headername == 'cpus' ) {
     1124
     1125                                        if( !isset( $jobinfo[ppn] ) )
     1126                                                $jobinfo[ppn] = 1;
     1127
     1128                                        $attrval        = strval( count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ) );
     1129
     1130                                } else if( $headername == 'runningtime' ) {
     1131                                        $attrval        = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) );
     1132                                } else {
     1133                                        $attrval        = strval( $jobinfo[$headername] );
     1134                                }
     1135
     1136                                imageString( $this->image, $this->font, $xoffset, $this->y_offset, $attrval, $colorblack );
     1137               
     1138                                $xoffset        = $xoffset + ($this->fontwidth * ( $headerlen + 1 ) );
     1139
     1140                        }
     1141                       
     1142                        $this->newLineOffset();
     1143                }
     1144        }
     1145
     1146        function drawHeader() {
     1147
     1148                $dg                     = &$this->data_gather;
     1149
     1150                for( $n = 0; $n < count( $this->njobs ); $n++ ) {
     1151
     1152                        $jobid                  = $this->njobs[$n];
     1153                        $jobinfo                = $dg->getJob( $jobid );
     1154
     1155                        if( !isset( $this->headerstrlen[id] ) )
     1156                                $this->headerstrlen[id] = strlen( strval( $jobid ) );
     1157                        else
     1158                                if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] )
     1159                                        $this->headerstrlen[id] = strlen( strval( $jobid ) );
     1160
     1161                        if( !isset( $this->headerstrlen[owner] ) )
     1162                                $this->headerstrlen[owner]      = strlen( strval( $jobinfo[owner] ) );
     1163                        else
     1164                                if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] )
     1165                                        $this->headerstrlen[owner]      = strlen( strval( $jobinfo[owner] ) );
     1166
     1167                        if( !isset( $this->headerstrlen[queue] ) )
     1168                                $this->headerstrlen[queue]      = strlen( strval( $jobinfo[queue] ) );
     1169                        else
     1170                                if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] )
     1171                                        $this->headerstrlen[queue]      = strlen( strval( $jobinfo[queue] ) );
     1172
     1173                        if( !isset( $jobinfo[ppn] ) )
     1174                                $jobinfo[ppn] = 1;
     1175
     1176                        $cpus                   = count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] );
     1177
     1178                        if( !isset( $this->headerstrlen[cpus] ) )
     1179                                $this->headerstrlen[cpus]       = strlen( strval( $cpus ) );
     1180                        else
     1181                                if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] )
     1182                                        $this->headerstrlen[cpus]       = strlen( strval( $cpus ) );
     1183
     1184                        $nodes                  = count( $jobinfo[nodes] );
     1185
     1186                        if( !isset( $this->headerstrlen[nodes] ) )
     1187                                $this->headerstrlen[nodes]      = strlen( strval( $nodes ) );
     1188                        else
     1189                                if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] )
     1190                                        $this->headerstrlen[nodes]      = strlen( strval( $nodes ) );
     1191
     1192                        $runningtime            = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) );
     1193
     1194                        if( !isset( $this->headerstrlen[runningtime] ) )
     1195                                $this->headerstrlen[runningtime]        = strlen( strval( $runningtime) );
     1196                        else
     1197                                if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] )
     1198                                        $this->headerstrlen[runningtime]        = strlen( strval( $runningtime) );
     1199
     1200                        if( !isset( $this->headerstrlen[name] ) )
     1201                                $this->headerstrlen[name]       = strlen( strval( $jobinfo[name] ) );
     1202                        else
     1203                                if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] )
     1204                                        $this->headerstrlen[name]       = strlen( strval( $jobinfo[name] ) );
     1205
     1206                }
     1207
     1208                $xoffset        = 5;
     1209
     1210                foreach( $this->headerstrlen as $headername => &$headerlen ) {
     1211
     1212                        $colorgreen     = imageColorAllocate( $this->image, 0, 200, 0 );
     1213
     1214                        imageString( $this->image, $this->font, $xoffset, $this->y_offset, ucfirst( $headername ), $colorgreen );
     1215               
     1216                        if( $headerlen < strlen( $headername ) )
     1217                                $headerlen      = strlen( $headername );
     1218
     1219                        $xoffset        = $xoffset + ($this->fontwidth * ( $headerlen + 1 ) );
     1220
     1221                }
     1222                $this->newLineOffset();
     1223        }
     1224
     1225        function newLineOffset() {
     1226
     1227                $this->y_offset         = $this->y_offset + $this->fontheight + $this->fontspaceing;
     1228        }
     1229
     1230        function draw() {
     1231
     1232                $xlen           = 450;
     1233                $ylen           = ( count( $this->njobs ) * ( $this->fontheight + $this->fontspaceing ) ) + (3 * $this->fontheight);
     1234
     1235                $this->image    = imageCreateTrueColor( $xlen, $ylen );
     1236                $colorwhite     = imageColorAllocate( $this->image, 255, 255, 255 );
     1237                imageFill( $this->image, 0, 0, $colorwhite );                         
     1238
     1239                $colorblue      = imageColorAllocate( $this->image, 0, 0, 255 );
     1240
     1241                imageString( $this->image, $this->font, 1, $this->y_offset, "Monarch Joblist - host: ".$this->host, $colorblue );
     1242                $this->newLineOffset();
     1243
     1244                $this->drawHeader();
     1245                $this->drawJobs();
     1246
     1247                header( 'Content-type: image/png' );
     1248                imagePNG( $this->image );
     1249                imageDestroy( $this->image );
     1250        }
     1251}
     1252
     1253function makeTime( $time ) {
     1254
     1255        $days = intval( $time / 86400 );
     1256        $time = ($days>0) ? $time % ($days * 86400) : $time;
     1257
     1258        //printf( "time = %s, days = %s\n", $time, $days );
     1259
     1260        $date_str = '';
     1261        $day_str = '';
     1262
     1263        if( $days > 0 ) {
     1264                if( $days > 1 )
     1265                        $day_str .= $days . ' days';
     1266                else
     1267                        $day_str .= $days . ' day';
     1268        }
     1269
     1270        $hours = intval( $time / 3600 );
     1271        $time = $hours ? $time % ($hours * 3600) : $time;
     1272
     1273        //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours );
     1274        if( $hours > 0 ) {
     1275                $date_str .= $hours . ':';
     1276                $date_unit = 'hours';
     1277        }
     1278
     1279        $minutes = intval( $time / 60 );
     1280        $seconds = $minutes ? $time % ($minutes * 60) : $time;
     1281
     1282        if( $minutes > 0 ) {
     1283
     1284                if( $minutes >= 10 )
     1285                        $date_str .= $minutes . ':';
     1286                else
     1287                        $date_str .= '0' . $minutes . ':';
     1288
     1289                $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
     1290        } else {
     1291                if($hours > 0 ) {
     1292                        $date_str .= '00:';
     1293                        $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
     1294                }
     1295        }
     1296
     1297
     1298        $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
     1299
     1300        if( $seconds > 0 ) {
     1301
     1302                if( $seconds >= 10 )
     1303                        $date_str .= $seconds . ' ' . $date_unit;
     1304                else
     1305                        $date_str .= '0' . $seconds . ' ' . $date_unit;
     1306
     1307        } else if ( $hours > 0 or $minutes > 0 )
     1308
     1309                $date_str .= '00 ' . $date_unit;
     1310
     1311        if( $days > 0) {
     1312
     1313                if( $hours > 0 or $minutes > 0 or $seconds > 0 )
     1314                        $date_str = $day_str . ' - ' . $date_str;
     1315                else
     1316                        $date_str = $day_str;
     1317        }
     1318
     1319        return $date_str;
     1320}
    10601321?>
  • trunk/web/addons/job_monarch/overview.php

    r302 r303  
    9494}
    9595
    96 function makeTime( $time ) {
    97 
    98         $days = intval( $time / 86400 );
    99         $time = ($days>0) ? $time % ($days * 86400) : $time;
    100 
    101         //printf( "time = %s, days = %s\n", $time, $days );
    102 
    103         $date_str = '';
    104         $day_str = '';
    105 
    106         if( $days > 0 ) {
    107                 if( $days > 1 )
    108                         $day_str .= $days . ' days';
    109                 else
    110                         $day_str .= $days . ' day';
    111         }
    112 
    113         $hours = intval( $time / 3600 );
    114         $time = $hours ? $time % ($hours * 3600) : $time;
    115 
    116         //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours );
    117 
    118         if( $hours > 0 ) {
    119                 $date_str .= $hours . ':';
    120                 $date_unit = 'hours';
    121         }
    122                
    123         $minutes = intval( $time / 60 );
    124         $seconds = $minutes ? $time % ($minutes * 60) : $time;
    125 
    126         if( $minutes > 0 ) {
    127 
    128                 if( $minutes >= 10 )
    129                         $date_str .= $minutes . ':';
    130                 else
    131                         $date_str .= '0' . $minutes . ':';
    132 
    133                 $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
    134         } else {
    135                 if($hours > 0 ) {
    136                         $date_str .= '00:';
    137                         $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
    138                 }
    139         }
    140 
    141 
    142         $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
    143 
    144         if( $seconds > 0 ) {
    145 
    146                 if( $seconds >= 10 )
    147                         $date_str .= $seconds . ' ' . $date_unit;
    148                 else
    149                         $date_str .= '0' . $seconds . ' ' . $date_unit;
    150                        
    151         } else if ( $hours > 0 or $minutes > 0 )
    152 
    153                 $date_str .= '00 ' . $date_unit;
    154 
    155         if( $days > 0) {
    156 
    157                 if( $hours > 0 or $minutes > 0 or $seconds > 0 )
    158                         $date_str = $day_str . ' - ' . $date_str;
    159                 else
    160                         $date_str = $day_str;
    161         }
    162 
    163         return $date_str;
    164 }
    165 
    16696//function makeDate( $time ) {
    16797//      return strftime( "%a %d %b %Y %H:%M:%S", $time );
Note: See TracChangeset for help on using the changeset viewer.