-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.php
445 lines (430 loc) · 17.5 KB
/
utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<?php
//
// $Id: utils.php,v 1.6 2006/01/26 00:06:35 charlie Exp $
//
// $Log: utils.php,v $
// Revision 1.6 2006/01/26 00:06:35 charlie
// corrected estimated cpu time remaining
// general html/css cleanup
//
// Revision 1.2 2005/04/16 00:41:08 charlie
// added RCS headers
//
//
function timestr($seconds) {
$hour = (integer)($seconds / 3600);
$min = (integer)($seconds / 60) % 60; if ($min < 10) $min = "0".$min;
$sec = (integer)($seconds) % 60; if ($sec < 10) $sec = "0".$sec;
return $hour.":".$min.":".$sec;
}
function print_projects($client, $client_state, $address) {
echo "<table summary=\"List of attached projects\">\n";
// echo "<table class=\"projects\" summary=\"List of attached projects\">\n";
// echo " <colgroup>\n";
// echo " <col width=\"2*\" />\n";
// echo " <col width=\"2*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"2*\" />\n";
// echo " </colgroup>\n";
echo " <tr>\n";
echo " <th>Project</th>\n";
echo " <th>Account</th>\n";
echo " <th>Total Credit</th>\n";
echo " <th>Avg. Credit</th>\n";
echo " <th>Debt</th>\n";
echo " <th>LT Debt</th>\n";
echo " <th>Share</th>\n";
echo " <th>Percent</th>\n";
echo " <th>DCF</th>\n";
echo " <th>Retry In</th>\n";
echo " <th>Tools</th>\n";
echo " </tr>\n";
$total_share = 0;
foreach ($client_state["projects"] as $project) {
$total_share = $total_share + $project["resource_share"];
}
foreach ($client_state["projects"] as $project) {
if ($project["suspended_via_gui"] == "true")
{
echo " <tr class=\"suspend\">\n";
}
else if ($project["frozen"] == "true")
{
echo " <tr class=\"paused\">\n";
}
else
{
echo " <tr>\n";
}
echo " <td><a href=\"".$project["master_url"]."\" target=\"_blank\" title=\"".$project["project_name"]."\">".$project["project_name"]."</a></td>\n";
echo " <td>".$project["user_name"]."</td>\n";
printf (" <td class=right> %01.2f </td>\n", $project["user_total_credit"]);
printf (" <td class=right> %01.2f </td>\n", $project["user_expavg_credit"]);
printf (" <td class=right> %01.2f </td>\n", $project["debt"]);
printf (" <td class=right> %01.2f </td>\n", $project["ltdebt"]);
printf (" <td class=right> %01.2f </td>\n", $project["resource_share"]);
printf (" <td class=right> %01.2f </td>\n", $project["resource_share"] / $total_share * 100.0);
printf (" <td class=right> %01.3f </td>\n", $project["duration_correction_factor"]);
echo " <td>";
$deltatime = $project["min_rpc_time"] - time();
if ($deltatime > 0) {
$retry_in = timestr($deltatime);
echo $retry_in;
}
echo " </td>\n";
echo " <td>".
"<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=project_update&url=".urlencode($project["master_url"])."\" title=\"Update project\" class=\"normal\">update</a>".
"<span class=\"normal\"> - </span>".
"<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=project_reset&url=".urlencode($project["master_url"])."\" title=\"Reset project\" class=\"normal\">reset</a>".
"<span class=\"normal\"> - </span>".
"<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=project_detach&url=".urlencode($project["master_url"])."\" title=\"Detach from project\" class=\"normal\">detach</a>".
"<span class=\"normal\"> - </span>";
if ($project["suspended_via_gui"] == "true")
{
echo "<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=project_resume&url=".urlencode($project["master_url"])."\" title=\"Resume project\" class=\"normal\">resume</a>";
// "<span class=\"normal\">/</span>".
}
else
{
echo "<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=project_suspend&url=".urlencode($project["master_url"])."\" title=\"Suspend project\" class=\"suspend\">suspend</a>";
}
echo "<span class=\"normal\"> - </span>";
if ($project["frozen"] == "true")
{
echo "<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=project_thaw&url=".urlencode($project["master_url"])."\" title=\"Thaw project\" class=\"normal\">thaw</a>";
}
// "<span class=\"normal\">/</span>".
else
{
echo "<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=project_freeze&url=".urlencode($project["master_url"])."\" title=\"Freeze project\" class=\"paused\">freeze</a>";
}
echo "</td>\n";
echo " </tr>\n";
}
echo "</table>\n";
return;
}
function print_work($client, $client_state, $address) {
// echo "<table summary=\"Current work\">\n";
echo "<table class=\"work\" summary=\"Current work\">\n";
// echo " <colgroup>\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"2*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " <col width=\"1*\" />\n";
// echo " </colgroup>\n";
echo " <tr>\n";
echo " <th>#</th>\n";
echo " <th>Project</th>\n";
echo " <th>Name</th>\n";
echo " <th>Application</th>\n";
echo " <th>CPU Time</th>\n";
echo " <th>Progress</th>\n";
echo " <th>Finished In</th>\n";
echo " <th>Report Deadline</th>\n";
echo " <th>Status</th>\n";
echo " <th>Tools</th>\n";
echo " </tr>\n";
$line=1;
foreach ($client_state["results"] as $result) {
$active_task = $result["active_task"];
if ($result["suspended_via_gui"] == "true") {
echo " <tr class=\"suspend\">\n";
} else {
switch ($result["state"]) {
case 2:
if ($active_task) {
if ($active_task["scheduler_state"] == 1) {
echo " <tr class=\"paused\">\n";
} else {
echo " <tr class=\"running\">\n";
}
} else {
echo " <tr class=\"normal\">\n";
}
break;
case 5:
echo "<tr class=\"ready\">\n";
break;
case 1:
case 4:
echo "<tr class=\"transferring\">\n";
break;
default:
if ($result["suspended_via_gui"] == "true") {
echo " <tr class=\"suspend\">\n";
} else {
echo " <tr class=\"normal\">\n";
}
break;
}
}
echo "<td>".$line."</td>\n";
$line = $line + 1;
// project
echo " <td>".$result["project"]["project_name"]."</td>\n";
// name
echo " <td>".$result["name"]."</td>\n";
// application
//echo " <td>".$result["workunit"]["app_name"]." ".($result["workunit"]["version_num"]/100)."</td>\n";
echo " <td>".$result["workunit"]["app_name"];
printf (" %01.2f </td>\n",$result["workunit"]["version_num"]/100);
//cpu time
if ($active_task) {
echo " <td class=center>".timestr($active_task["current_cpu_time"])."</td>\n";
} else {
if ($result["ready_to_report"]||($result["state"] > 3)) {
echo " <td class=center>".timestr($result["final_cpu_time"])."</td>\n";
} else {
echo " <td class=center>---</td>\n";
}
}
// progress
if ($active_task) {
printf (" <td class=right> %01.2f%% </td>\n", $active_task["fraction_done"]*100)."%</td>\n";
} else {
if ($result["state"] > 3) {
echo " <td class=right>100.00%</td>\n";
} else {
echo " <td class=center>---</td>\n";
}
}
// to completion
if (!$active_task) {
if ($result["state"] < 4) {
$tocomp = $result["workunit"]["rsc_fpops_est"] / $client_state["host_info"]["p_fpops"];
} else {
$tocomp = 0;
}
} else {
$tocomp = ($active_task["current_cpu_time"] / $active_task["fraction_done"]) - $active_task["current_cpu_time"];
if ($tocomp < 0) {
$tocomp = $result["workunit"]["rsc_fpops_est"] / $client_state["host_info"]["p_fpops"];
}
}
//$tocomp = $tocomp * $result["project"]["duration_correction_factor"];
$tocomp = $result["estimated_cpu_time_remaining"];
//$tocomp = $result["estimated_cpu_time_remaining"] * $result["project"]["duration_correction_factor"];
if ($result["ready_to_report"]) {
echo " <td class=center>---</td>\n";
} else {
//printf (" <td class=right> %01.4f </td>\n", $result["project"]["duration_correction_factor"]);
//echo " <td class=center>".$client_state["projects"]["duration_correction_factor"]."</td>\n";
echo " <td class=center>".timestr($tocomp)."</td>\n";
}
// deadline
echo " <td>".date("j M Y G:i:s", $result["report_deadline"])."</td>\n";
// state
switch ($result["state"]) {
case 0:
echo " <td>Ready to download</td>\n";
break;
case 1:
echo " <td>Downloading</td>\n";
break;
case 2:
if ($active_task) {
if ($active_task["scheduler_state"] == 1) {
echo " <td>Paused</td>\n";
} else {
echo " <td>Running</td>\n";
}
} elseif ($result["aborted_via_gui"]){
echo " <td>Aborted</td>\n";
} else {
echo " <td>Rdy to run</td>\n";
}
break;
case 3:
echo " <td>Computation Error</td>\n";
break;
case 4:
echo " <td>Uploading</td>\n";
break;
case 5:
if ($result["ready_to_report"]) {
if ($result["project"]) {
echo " <td><a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=project_update&url=".urlencode($result["project"]["master_url"])."\" title=\"Update ".$result["project"]["project_name"]."\">Rdy to rpt</td>\n";
} else {
echo " <td>Ready to report</td>\n";
}
} else {
echo " <td>Result uploaded</td>\n";
}
break;
case 6:
echo " <td>Aborted</td>\n";
break;
default:
echo " <td>".$result["state"]."</td>\n";
}
//Tools
echo " <td>";
if ($result["suspended_via_gui"] == "true")
{
echo "<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=result_resume&result=".$result["name"]."&url=".urlencode($result["project"]["master_url"])."\" title=\"Resume result\" class=\"normal\">resume</a>";
// "<span class=\"normal\">/</span>".
}
else
{
echo "<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=result_suspend&result=".$result["name"]."&url=".urlencode($result["project"]["master_url"])."\" title=\"Suspend result\" class=\"suspend\">suspend</a>";
}
echo "<span class=\"normal\"> - </span>".
"<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=result_abort&result=".$result["name"]."&url=".urlencode($result["project"]["master_url"])."\" title=\"Abort result\" class=\"normal\">abort</a>".
"</td>";
echo " </tr>\n";
}
echo "</table>\n";
return;
}
function print_transfers($client, $transfers, $address) {
echo "<table class=\"transfers\" summary=\"Ongoing file transfers\">\n";
echo " <colgroup>\n";
echo " <col width=\"2*\" />\n";
echo " <col width=\"3*\" />\n";
echo " <col width=\"1*\" />\n";
echo " <col width=\"1*\" />\n";
echo " <col width=\"1*\" />\n";
echo " <col width=\"1*\" />\n";
echo " <col width=\"1*\" />\n";
echo " <col width=\"1*\" />\n";
echo " <col width=\"1*\" />\n";
echo " <col width=\"1*\" />\n";
echo " <col width=\"1*\" />\n";
echo " </colgroup>\n";
echo " <tr>\n";
echo " <th>Project</th>\n";
echo " <th>File</th>\n";
echo " <th>Progress</th>\n";
echo " <th>Size</th>\n";
echo " <th>So Far</th>\n";
echo " <th>To Go</th>\n";
echo " <th>Time</th>\n";
echo " <th>Speed</th>\n";
echo " <th>Status</th>\n";
echo " <th>Retry In</th>\n";
echo " <th>Tools</th>\n";
echo " </tr>\n";
foreach ($transfers as $file_xfer) {
echo " <tr>\n";
// project
echo " <td>".$file_xfer["project_url"]."</td>\n";
// file
echo " <td>".$file_xfer["name"]."</td>\n";
// progress
echo sprintf(" <td>%0.2f%%</td>\n", ($file_xfer["bytes_xferred"] / $file_xfer["nbytes"])*100);
// size
echo sprintf(" <td>%0.0f B</td>\n", $file_xfer["nbytes"]);
// So Far
echo sprintf(" <td>%0.0f B</td>\n", $file_xfer["bytes_xferred"]);
// To Go
echo sprintf(" <td>%0.0f B</td>\n", $file_xfer["nbytes"] - $file_xfer["bytes_xferred"]);
// time
echo " <td>".timestr($file_xfer["time_so_far"])."</td>\n";
// speed
echo sprintf(" <td>%0.2f Bps</td>\n", $file_xfer["xfer_speed"]);
// status
if ($file_xfer["generated_locally"] && $file_xfer["active"]) {
echo " <td>Uploading</td>\n";
} elseif($file_xfer["generated_locally"] && !$file_xfer["active"]) {
echo " <td>Upload pending</td>\n";
} elseif(!$file_xfer["generated_locally"] && !$file_xfer["active"]) {
echo " <td>Download pending</td>\n";
} else {
echo " <td>Downloading</td>\n";
}
$deltatime = $file_xfer["next_request_time"] - time();
if ($deltatime > 0) {
$retry_in = timestr($deltatime);
echo " <td>$retry_in</td>\n";
} else {
echo " <td></td>\n";
}
//Tools
echo " <td>".
"<a href=\"".$_SERVER["PHP_SELF"]."?index=tools&address=".$address."&cmd=retry_transfer&file=".$file_xfer["name"]."&url=".urlencode($file_xfer["project_url"])."\" title=\"Retry File Transfer\" class=\"normal\">Retry</a>".
"</td>\n";
echo " </tr>\n";
}
echo "</table>\n";
return;
}
function print_help()
{
?>
<ul>
<li><strong>Project Tab</strong>
<dl>
<dt>Project</dt>
<dd>The name of the project</dd>
<dt>Account</dt>
<dd>The name of the account</dd>
<dt>Total Credit</dt>
<dd>Number of cobblestones for this project as
of the most recent update of the project.</dd>
<dt>Avg Credit</dt>
<dd>The recent average credit for this project as of the most recent
update of the project.</dd>
<dt>Debt</dt>
<dd>The resource debt for this project. When it is time to switch
to a different project, the project with the highest resource debt
will be run. Updating a project will recalculate the debt and
switch projects is a different project than the one currently running
has a higher debt.</dd>
<dt>Share</dt>
<dd>The resource share for the project</dd>
<dt>Percent</dd>
<dd>The percent of the total resoruce shares for all projects. The
resource shares for all projects are totaled and the percent for the
current project is displayed.</dd>
<dt>Retry In</dt>
<dd>The time in HH:MM:SS format until the next time the core client will
contact the project's scheduler.</dd>
<dt>Tools</dt>
<dd><li>Update - Force an update to the project. The core client will
contact the project's scheduler.
<dd><li>Reset - Reset a project. All workunits will be discarded.
New workunits will be downloaded.
<dd><li>Detach - Detach the core client from the project. All workunits
will be discarded. The project will be removed from the list of
projects.
<dd><li>Suspend/Resume - Only the appropriate action will be displayed.
Suspending a project will cause any running workunit for the project
to stop. No workunits for the project will run as long as the
project is suspended. A suspended project will be displayed with
a red colored background. No work already done is lost. A
suspended project can be resumed by clicking RESUME (when a project
is suspended, SUSPEND changes to RESUME). A workunit will be resumed
when the resource debt for the project is higher than any other
project.
<dd><li>Freeze/Thaw - Only the appropriate action will be displayed.
Freezing a project allows all currently downloaded workunits to
be processed as normal. Results will be uploaded. However,
results will not be reported to the project's scheduler, nor will
any more workunits be downloaded from the project's scheduler. This
allows the user to drain the project's queue without the need to
discard any workunits. A frozen project is displayed with a
yellow background. Thaw will undo the action of Freeze. Uploaded
workunits can be reported by using the UPDATE function for the
project.
</dl>
</li>
<li><strong>Work Tab</strong>
<ul>
<li>Project - The name of the project</li>
<li>Name - The result name</li>
</ul>
</li>
</ul>
<?php
}
?>