- Scheduler completed.

- Added a wizard just for show, but there is no
  interesting cpu-scheduling policy to test it with
- Better textual output.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@842 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-08-11 23:01:25 +00:00
parent 436e401ae8
commit 69c8341384
4 changed files with 364 additions and 103 deletions

View file

@ -1476,19 +1476,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);
@ -1506,16 +1506,16 @@ operator<<(ostream& os, Request::state state)
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);
@ -1529,13 +1529,6 @@ TextSimulation::update(const History& changed_history)
{
ostringstream oss;
/// since the history stores snapshots starting from
/// and including instant -1, the first snapshot on
/// the queue, i.e. changed_history[0] is actually
/// the snapshot corresponding to instant -1.
/// therefore, the last snapshot on the history refers
/// to instant (history.get_size() - 2).
// this is a damn uint, so we must hack and hack
int printed_instant;
if (changed_history.get_size() > 1)
@ -1561,17 +1554,45 @@ TextSimulation::update(const History& changed_history)
p_stdout("}\n");
p_stdout(_("RESOURCES:\n"));
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"));
for (ResourceIt it = resources.begin(); it != resources.end(); ++it)
{
const Resource& r = *it->second;
Environment::resource_key_t key = it->first;
oss << " " << key << ") " << r.get_name() << _(", with ");
oss << " " << (key < 10 ? " " : "") << key << ". " << r.get_name() << _(", with ");
oss << r.get_places() << _(" places\n");
@ -1603,20 +1624,26 @@ TextSimulation::update(const History& changed_history)
p_stdout(" }\n");
}
p_stdout(_("PROCESSES:\n"));
const Environment::Processes& processes = env.get_processes();
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"));
for (unsigned int pi = 0; pi < processes.size(); ++pi)
{
Process& p = *processes[pi];
oss << " " << pi + 1 << ") " << p.get_name() << " ";
oss << "[" << p.get_state() << "] ";
oss << _("arriving at ") << p.get_arrival_time() << ", ";
oss << _("requiring ") << p.get_total_cpu_time() << ", ";
oss << _("elapsed ") << p.get_elapsed_time() << ", ";
oss << _("priority ") << p.get_current_priority() << endl;
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;
p_stdout(oss.str());
oss.str(string());
@ -1627,12 +1654,14 @@ TextSimulation::update(const History& changed_history)
{
Thread& t = *threads[ti];
oss << " " << ti + 1 << ") " << t.get_name() << " ";
oss << "[" << t.get_state() << "] ";
oss << _("arriving at ") << t.get_arrival_time() << ", ";
oss << _("requiring ") << t.get_total_cpu_time() << ", ";
oss << _("elapsed ") << t.get_elapsed_time() << ", ";
oss << _("priority ") << t.get_current_priority() << endl;
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;
p_stdout(oss.str());
oss.str(string());
@ -1648,14 +1677,20 @@ TextSimulation::update(const History& changed_history)
for (unsigned int sri = 0; sri < subrequests.size(); ++sri)
{
SubRequest& sr = *subrequests[sri];
oss << _(" --> request ") << ri + 1 << "." << sri + 1 << ") ";
oss << _("at ") << r.get_instant() << " ";
ResourceIt point = resources.find(sr.get_resource_key());
oss << _("for resource ") << (point->second)->get_name() << " ";
oss << _("with id ") << sr.get_resource_key() << " ";
oss << "[" << sr.get_state() << "] ";
oss << _("requiring ") << sr.get_length() << ", ";
oss << _("remaining ") << sr.get_remaining_time() << endl;
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";
p_stdout(oss.str());
oss.str(string());