.
// web interface to client simulator
//
// to use this, symlink to it from the html/user dir of a BOINC project,
// create an apache-writable dir called "scenarios" there,
// and symlink from html/inc to sim_util.inc
require_once("../inc/util.inc");
require_once("../inc/sim_util.inc");
function nsims($scen) {
$d = opendir("scenarios/$scen/simulations");
$n = 0;
while (false !== ($f = readdir($d))) {
if ($f == ".") continue;
if ($f == "..") continue;
$n++;
}
return $n;
}
function show_scenario_summary($f) {
$desc = file_get_contents("scenarios/$f/description");
$userid = (int)file_get_contents("scenarios/$f/userid");
$user = BoincUser::lookup_id($userid);
$date = date_str(filemtime("scenarios/$f"));
$nsims = nsims($f);
echo "
";
}
// show existing scenarios, "create scenario" button
//
function show_scenarios() {
page_head("The BOINC Client Emulator");
echo "
Welcome to the BOINC Client Emulator (BCE).
BCE emulates a BOINC client attached to one or more projects.
It predicts, in a few seconds, what the BOINC client will do
over a period of day or months.
This allows BOINC developers to fix bugs and improve performance.
The inputs to BCE, called scenarios,
describe a particular computer and the project to which it's attached.
A scenario consists of 4 files:
client_state.xml: describes the host and projects.
global_prefs.xml and global_prefs_override.xml:
computing preferences (optional).
cc_config.xml: client configuration (optional).
You can use the files from a running BOINC client
to emulate that client.
You can modify these files, or create new ones, to study hypothetical hosts
(e.g. ones with a large number of CPUs,
attached to a large number of projects, and so on).
See The
BCE documentation for details.
You create a scenario by uploading these files to the BOINC server.
Then you can run any number of simulations based on the scenario.
The parameters of a simulation include
The duration and time resolution of the simulation.
Choices for various client policy alternatives.
The client version.
The outputs of a simulation include
A graphical 'time line' showing CPU and GPU usage.
The client's message log
graphs of scheduling-related data (debt, REC).
A summary of several 'figures of merit',
including idle and wasted processing fraction,
resource share violation, and monotony.
";
show_button(
"sim_web.php?action=create_scenario_form",
"Create a scenario", "Create a new scenario"
);
echo "
Existing scenarios
Creator
When
# simulations
Description
";
$d = opendir("scenarios");
while (false !== ($f = readdir($d))) {
if ($f === ".") continue;
if ($f === "..") continue;
show_scenario_summary($f);
}
echo "
\n";
page_tail();
}
// show form for creating a scenario
//
function create_scenario_form() {
get_logged_in_user();
page_head("Create a scenario");
echo "
To create a scenario:
choose the input files,
enter a short description, and click OK
(items with * are required).
";
page_tail();
}
// create a subdir $dir/N for the first available N
//
function create_dir_seqno($dir) {
$i = -1;
$d = opendir($dir);
while (false !== ($f = readdir($d))) {
$j = -1;
$n = sscanf($f, "%d", $j);
if ($n == 1 && $j >= 0) {
if ($j > $i) {
$i = $j;
}
}
}
$i++;
$p = "$dir/$i";
mkdir($p);
return "$i";
}
// choose scenario name
// create dir, put files there
// create meta-data file
// redirect to show scenario
//
function create_scenario() {
$user = get_logged_in_user();
$csname = $_FILES['client_state']['tmp_name'];
if (!is_uploaded_file($csname)) {
error_page("You must specify a client_state.xml file.");
}
$desc = post_str("description", true);
if (!strlen($desc)) {
error_page("You must supply a description.");
}
$desc = strip_tags($desc);
$sname = create_dir_seqno("scenarios");
$d = "scenarios/$sname";
move_uploaded_file($csname, "$d/client_state.xml");
$gp = $_FILES['global_prefs']['tmp_name'];
if (is_uploaded_file($gp)) {
move_uploaded_file($gp, "$d/global_prefs.xml");
}
$gpo = $_FILES['global_prefs_override']['tmp_name'];
if (is_uploaded_file($gpo)) {
move_uploaded_file($gpo, "$d/global_prefs_override.xml");
}
$cc = $_FILES['cc_config']['tmp_name'];
if (is_uploaded_file($cc)) {
move_uploaded_file($cc, "$d/cc_config.xml");
}
file_put_contents("$d/userid", "$user->id");
file_put_contents("$d/description", $desc);
mkdir("$d/simulations");
header("Location: sim_web.php?action=show_scenario&name=$sname");
}
function show_simulation_summary($scen, $sim) {
$dir = "scenarios/$scen/simulations/$sim";
$userid = (int)file_get_contents("$dir/userid");
$user = BoincUser::lookup_id($userid);
$date = date_str(filemtime($dir));
echo "