- Prettify textual simulation output, simplyfing the code, too.
- Fix return code on exit git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@844 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
97d6f574af
commit
51fdeea4d1
|
@ -132,6 +132,11 @@ parse_options(int argc, char** argv)
|
|||
TextSimulation sim;
|
||||
std::string str;
|
||||
|
||||
std::cout << std::endl
|
||||
<< _(" [II] To see a list of commands available,\n"
|
||||
" [II] please type \"help\" and hit the ENTER key.")
|
||||
<< std::endl;
|
||||
|
||||
std::cout << std::endl << "% ";
|
||||
while (getline(std::cin, str))
|
||||
{
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
|
||||
#include "text_simulation.hh"
|
||||
|
||||
#include <cassert>
|
||||
#include <ios>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
@ -574,10 +577,10 @@ TextSimulation::on_quit(const Tokens& arguments)
|
|||
if (!unsaved_ask_confirm())
|
||||
return;
|
||||
|
||||
p_stdout(_("\n\n*** Thank you for using SGPEM by Sirius Cybernetics Corporation ***\n\n"));
|
||||
p_stdout(_("\nBye.\n\n"));
|
||||
|
||||
// Is this ok? Really? Oh, sure, if it we always did it in this way, it is surely a Good Thing!
|
||||
exit(1);
|
||||
// Exit the program with a correct return code.
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1476,19 +1479,19 @@ operator<<(ostream& os, Schedulable::state state)
|
|||
switch (state)
|
||||
{
|
||||
case Schedulable::state_running:
|
||||
os << " RUNNING @";
|
||||
os << _("RUNNING @");
|
||||
break;
|
||||
case Schedulable::state_ready:
|
||||
os << " READY ";
|
||||
os << _("READY");
|
||||
break;
|
||||
case Schedulable::state_blocked:
|
||||
os << " BLOCKED ";
|
||||
os << _("BLOCKED");
|
||||
break;
|
||||
case Schedulable::state_future:
|
||||
os << " FUTURE ";
|
||||
os << _("FUTURE");
|
||||
break;
|
||||
case Schedulable::state_terminated:
|
||||
os << " TERMINATED ";
|
||||
os << _("TERMINATED");
|
||||
break;
|
||||
default:
|
||||
os.setstate(ios_base::failbit);
|
||||
|
@ -1503,19 +1506,19 @@ operator<<(ostream& os, Request::state state)
|
|||
switch (state)
|
||||
{
|
||||
case Request::state_unallocable:
|
||||
os << "UNALLOCABLE";
|
||||
os << _("UNALLOCABLE");
|
||||
break;
|
||||
case Request::state_allocated:
|
||||
os << " ALLOCATED";
|
||||
os << _("ALLOCATED");
|
||||
break;
|
||||
case Request::state_future:
|
||||
os << " FUTURE";
|
||||
os << _("FUTURE");
|
||||
break;
|
||||
case Request::state_exhausted:
|
||||
os << " EXHAUSTED";
|
||||
os << _("EXHAUSTED");
|
||||
break;
|
||||
case Request::state_allocable:
|
||||
os << " ALLOCABLE";
|
||||
os << _("ALLOCABLE");
|
||||
break;
|
||||
default:
|
||||
os.setstate(ios_base::failbit);
|
||||
|
@ -1528,19 +1531,21 @@ void
|
|||
TextSimulation::update(const History& changed_history)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int printed_instant;
|
||||
static const std::string tab = " ";
|
||||
|
||||
|
||||
// Print header for each instant:
|
||||
if (changed_history.get_size() > 1)
|
||||
printed_instant = static_cast<int>(changed_history.get_size()) - 2;
|
||||
else
|
||||
printed_instant = -1;
|
||||
|
||||
oss << ">>>> " << printed_instant << _("\nREADY QUEUE: { ");
|
||||
oss << endl << ">>>> " << printed_instant;
|
||||
|
||||
p_stdout(oss.str());
|
||||
|
||||
oss.str(string());
|
||||
// Print ready queue
|
||||
oss << endl << _("READY QUEUE: { ");
|
||||
|
||||
const Environment& env = changed_history.get_last_environment();
|
||||
const ReadyQueue& q = env.get_sorted_queue();
|
||||
|
@ -1548,62 +1553,36 @@ TextSimulation::update(const History& changed_history)
|
|||
for (unsigned int i = 0; i < q.size(); ++i)
|
||||
{
|
||||
const Thread& t = q.get_item_at(i);
|
||||
|
||||
p_stdout(t.get_name() + " ~ ");
|
||||
oss << t.get_name() + _(" ~ ");
|
||||
}
|
||||
|
||||
p_stdout("}\n");
|
||||
oss << _("}") << endl;
|
||||
|
||||
|
||||
// Flush buffer to screen
|
||||
p_stdout(oss.str());
|
||||
oss.str(string());
|
||||
|
||||
|
||||
const Environment::Resources& resources = env.get_resources();
|
||||
const Environment::Processes& processes = env.get_processes();
|
||||
typedef Environment::Resources::const_iterator ResourceIt;
|
||||
|
||||
|
||||
std::string tab = " ";
|
||||
std::string::size_type max = tab.size();
|
||||
for (unsigned int pi = 0; pi < processes.size(); ++pi)
|
||||
{
|
||||
Process& p = *processes[pi];
|
||||
if (p.get_name().size() > max + tab.size() + tab.size())
|
||||
max = p.get_name().size() - tab.size() - tab.size();
|
||||
vector<Thread*> threads = p.get_threads();
|
||||
for (unsigned int ti = 0; ti < threads.size(); ++ti)
|
||||
{
|
||||
Thread& t = *threads[ti];
|
||||
if (t.get_name().size() > max + tab.size())
|
||||
max = t.get_name().size() - tab.size();;
|
||||
}
|
||||
|
||||
for (ResourceIt it = resources.begin(); it != resources.end(); ++it)
|
||||
{
|
||||
const Resource& r = *it->second;
|
||||
if (r.get_name().size() > max)
|
||||
max = r.get_name().size();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
p_stdout(_("RESOURCES:\n"));
|
||||
// Write the queue of requests for each resource
|
||||
oss << _("RESOURCES:") << endl;
|
||||
for (ResourceIt it = resources.begin(); it != resources.end(); ++it)
|
||||
{
|
||||
const Resource& r = *it->second;
|
||||
Environment::resource_key_t key = it->first;
|
||||
|
||||
oss << " " << (key < 10 ? " " : "") << key << ". " << r.get_name() << _(", with ");
|
||||
|
||||
oss << r.get_places() << _(" places\n");
|
||||
|
||||
p_stdout(oss.str());
|
||||
oss.str(string());
|
||||
|
||||
oss << right << setw(3) << key << left << ". " << r.get_name() << _(", with ");
|
||||
oss << r.get_places() << _(" places") << endl;
|
||||
|
||||
const Environment::SubRequestQueue& req_queue =
|
||||
env.get_request_queue(it->first);
|
||||
|
||||
p_stdout(_("\t\t\tqueue: { "));
|
||||
oss << setw(tab.size()*3) << ' ' << _("queue: { ");
|
||||
|
||||
for (unsigned int i = 0; i < req_queue.size(); ++i)
|
||||
{
|
||||
|
@ -1617,33 +1596,48 @@ TextSimulation::update(const History& changed_history)
|
|||
oss << "[" << req_queue[i]->get_request().get_thread().get_name() << "]";
|
||||
else
|
||||
oss << req_queue[i]->get_request().get_thread().get_name();
|
||||
p_stdout(oss.str());
|
||||
oss.str(string());
|
||||
}
|
||||
|
||||
p_stdout(" }\n");
|
||||
oss << _(" }") << endl;
|
||||
}
|
||||
|
||||
// Flush buffer to screen
|
||||
p_stdout(oss.str());
|
||||
oss.str(string());
|
||||
|
||||
|
||||
// Set new format state flags, and save the old one
|
||||
static const unsigned int fill0 = 25;
|
||||
static const unsigned int fill1 = 15;
|
||||
|
||||
// Minimum fill0 for the usage we make of it below:
|
||||
assert(fill0 > tab.size()*2 + 6);
|
||||
|
||||
p_stdout(_("\nPROCESSES:"));
|
||||
Glib::ustring space_bar_1 = " ";
|
||||
space_bar_1.resize(max, ' ');
|
||||
p_stdout(space_bar_1);
|
||||
p_stdout(_(" state arrival requiring elapsed priority resource_id\n"));
|
||||
oss << endl;
|
||||
|
||||
oss << left;
|
||||
oss << setw(fill0) << _("PROCESSES:");
|
||||
oss << right;
|
||||
oss << setw(fill1) << _("state")
|
||||
<< setw(fill1) << _("arrival")
|
||||
<< setw(fill1) << _("requiring")
|
||||
<< setw(fill1) << _("elapsed")
|
||||
<< setw(fill1) << _("priority")
|
||||
<< setw(fill1) << _("resource_id")
|
||||
<< endl;
|
||||
|
||||
for (unsigned int pi = 0; pi < processes.size(); ++pi)
|
||||
{
|
||||
Process& p = *processes[pi];
|
||||
Glib::ustring upname(p.get_name());
|
||||
upname.resize(max + tab.size() + tab.size(), ' ');
|
||||
oss << " " << (pi < 9 ? " " : "") << pi + 1 << ". " << upname;
|
||||
oss << " " << p.get_state();
|
||||
oss << _(" ") << (p.get_arrival_time() < 10 ? " " : "") << p.get_arrival_time();
|
||||
oss << _(" ") << (p.get_total_cpu_time() < 10 ? " " : "") << p.get_total_cpu_time();
|
||||
oss << _(" ") << (p.get_elapsed_time() < 10 ? " " : "") << p.get_elapsed_time();
|
||||
oss << _(" ") << (p.get_current_priority() < 10 ? " " : "") << p.get_current_priority() << endl;
|
||||
oss << setw(2) << right << (pi + 1) << left << ". "
|
||||
<< setw(fill0 - 4) << p.get_name().substr(0, fill0 - 5);
|
||||
oss << right;
|
||||
oss << setw(fill1) << p.get_state();
|
||||
oss << setw(fill1) << p.get_arrival_time();
|
||||
oss << setw(fill1) << p.get_total_cpu_time();
|
||||
oss << setw(fill1) << p.get_elapsed_time();
|
||||
oss << setw(fill1) << p.get_current_priority();
|
||||
oss << endl;
|
||||
|
||||
p_stdout(oss.str());
|
||||
oss.str(string());
|
||||
|
@ -1654,14 +1648,15 @@ TextSimulation::update(const History& changed_history)
|
|||
{
|
||||
Thread& t = *threads[ti];
|
||||
|
||||
Glib::ustring upname(t.get_name());
|
||||
upname.resize(max + tab.size(), ' ');
|
||||
oss << " " << tab << (ti < 9 ? " " : "") << ti + 1 << ". " << upname;
|
||||
oss << " " << t.get_state();
|
||||
oss << _(" ") << (t.get_arrival_time() < 10 ? " " : "") << t.get_arrival_time();
|
||||
oss << _(" ") << (t.get_total_cpu_time() < 10 ? " " : "") << t.get_total_cpu_time();
|
||||
oss << _(" ") << (t.get_elapsed_time() < 10 ? " " : "") << t.get_elapsed_time();
|
||||
oss << _(" ") << (t.get_current_priority() < 10 ? " " : "") << t.get_current_priority() << endl;
|
||||
oss << right << setw(tab.size() + 2) << ti + 1 << left << ". "
|
||||
<< setw(fill0 - 4 - tab.size()) << t.get_name().substr(0, fill0 - 5 - tab.size());
|
||||
oss << right;
|
||||
oss << setw(fill1) << t.get_state();
|
||||
oss << setw(fill1) << t.get_arrival_time();
|
||||
oss << setw(fill1) << t.get_total_cpu_time();
|
||||
oss << setw(fill1) << t.get_elapsed_time();
|
||||
oss << setw(fill1) << t.get_current_priority();
|
||||
oss << endl;
|
||||
|
||||
p_stdout(oss.str());
|
||||
oss.str(string());
|
||||
|
@ -1679,18 +1674,15 @@ TextSimulation::update(const History& changed_history)
|
|||
SubRequest& sr = *subrequests[sri];
|
||||
ResourceIt point = resources.find(sr.get_resource_key());
|
||||
|
||||
oss << " " << tab << " ";
|
||||
oss << (ri < 9 ? " " : "") << ri + 1 << "." << sri + 1 << (sri < 9 ? " " : "");
|
||||
|
||||
Glib::ustring upname((point->second)->get_name());
|
||||
upname.resize(max, ' ');
|
||||
oss << _(" ") << upname;
|
||||
oss << " " << sr.get_state();
|
||||
oss << _(" ") << (r.get_instant() < 10 ? " " : "") << r.get_instant();
|
||||
oss << _(" ") << (sr.get_length() < 10 ? " " : "") << sr.get_length();
|
||||
oss << _(" ") << (sr.get_length() - sr.get_remaining_time() < 10 ? " " : "") << sr.get_length() - sr.get_remaining_time();
|
||||
|
||||
oss << _(" ") << sr.get_resource_key() << " \n";
|
||||
oss << setw(2 + tab.size()*2) << ri + 1 << left << "." << setw(2) << sri + 1
|
||||
<< setw(fill0 - 5 - tab.size()*2) << (point->second)->get_name().substr(0, fill0 - 6 - tab.size()*2);
|
||||
oss << right;
|
||||
oss << setw(fill1) << sr.get_state();
|
||||
oss << setw(fill1) << r.get_instant();
|
||||
oss << setw(fill1) << sr.get_length();
|
||||
oss << setw(fill1) << sr.get_length() - sr.get_remaining_time();
|
||||
oss << setw(fill1) << sr.get_resource_key();
|
||||
oss << endl;
|
||||
|
||||
p_stdout(oss.str());
|
||||
oss.str(string());
|
||||
|
@ -1699,7 +1691,5 @@ TextSimulation::update(const History& changed_history)
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
p_stdout("\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue