- Fixed bug in copy construction of DynamicProcess

- Fixed bug in get_parameter<bool> in TextSimulation
- Written some new code for visualization of the simulation

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@799 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-07-29 00:24:48 +00:00
parent 25e5a7319b
commit d64051279f
7 changed files with 90 additions and 13 deletions

View File

@ -111,7 +111,7 @@ ConcreteHistory::append_new_environment(ConcreteEnvironment* environment)
ConcreteHistory::size_t ConcreteHistory::size_t
ConcreteHistory::get_size() ConcreteHistory::get_size() const
{ {
return _snapshots.size(); return _snapshots.size();
} }

View File

@ -50,7 +50,7 @@ namespace sgpem
virtual ~ConcreteHistory(); virtual ~ConcreteHistory();
virtual void append_new_environment(ConcreteEnvironment* environment); virtual void append_new_environment(ConcreteEnvironment* environment);
virtual size_t get_size(); virtual size_t get_size() const;
virtual const ConcreteEnvironment& get_last_environment() const; virtual const ConcreteEnvironment& get_last_environment() const;
virtual const ConcreteEnvironment& get_environment_at(position index) const throw(std::out_of_range); virtual const ConcreteEnvironment& get_environment_at(position index) const throw(std::out_of_range);

View File

@ -39,7 +39,8 @@ DynamicProcess::DynamicProcess(StaticProcess* core) :
} }
DynamicProcess::DynamicProcess(const DynamicProcess &other) : DynamicProcess::DynamicProcess(const DynamicProcess &other) :
Schedulable(), DynamicSchedulable(other), Process() Schedulable(), DynamicSchedulable(other), Process(),
_core(other._core)
{ {
typedef vector<DynamicThread*>::const_iterator ThreadIt; typedef vector<DynamicThread*>::const_iterator ThreadIt;

View File

@ -25,6 +25,7 @@
#include "request.hh" #include "request.hh"
#include "static_request.hh" #include "static_request.hh"
#include "dynamic_thread.hh"
#include "smartp.hh" #include "smartp.hh"
@ -34,7 +35,6 @@ namespace sgpem
{ {
class DynamicRequest; class DynamicRequest;
class SerializeVisitor; class SerializeVisitor;
class DynamicThread;
class SubRequest; class SubRequest;
class DynamicSubRequest; class DynamicSubRequest;

View File

@ -66,7 +66,7 @@ namespace sgpem
virtual ~History() = 0; virtual ~History() = 0;
virtual size_t get_size() = 0; virtual size_t get_size() const = 0;
virtual const Environment& get_last_environment() const = 0; virtual const Environment& get_last_environment() const = 0;
virtual const Environment& get_environment_at(position index) const throw(std::out_of_range) = 0; virtual const Environment& get_environment_at(position index) const throw(std::out_of_range) = 0;

View File

@ -29,6 +29,7 @@ namespace sgpem
class Request; class Request;
class SerializeVisitor; class SerializeVisitor;
class SubRequest; class SubRequest;
class Thread;
class SG_DLLEXPORT Request class SG_DLLEXPORT Request
{ {
@ -44,6 +45,8 @@ namespace sgpem
virtual ~Request(); virtual ~Request();
virtual Thread& get_thread() = 0;
virtual bool operator==(const Request& op2) const = 0; virtual bool operator==(const Request& op2) const = 0;
virtual std::vector<SubRequest*> get_subrequests() = 0; virtual std::vector<SubRequest*> get_subrequests() = 0;

View File

@ -291,10 +291,12 @@ namespace sgpem
void void
TextSimulation::get_parameter<bool>(CommandParameter<bool>& parameter) TextSimulation::get_parameter<bool>(CommandParameter<bool>& parameter)
{ {
bool loop = true; bool correct;
while(loop) do
{ {
correct = true;
ostringstream buf; ostringstream buf;
buf << "\n"; buf << "\n";
@ -315,22 +317,26 @@ namespace sgpem
// it's correct ;-) // it's correct ;-)
Tokens tokens = tokenize(str); Tokens tokens = tokenize(str);
if(tokens.size() == 0 && parameter.required) if(tokens.size() != 0)
p_stderr(_("\nERROR: This is a mandatory atribute; you MUST provide a valid value!"));
else
{ {
try try
{ {
parameter.value = string_to<bool>(str); parameter.value = string_to<bool>(str);
loop = false;
} }
catch(domain_error e) catch(domain_error e)
{ {
p_stderr(_("\nERROR: Please provide a valid boolean value ('true' or 'false')")); p_stderr(_("\nERROR: Please provide a valid boolean value ('true' or 'false')"));
correct = false;
} }
} }
else if(parameter.required)
{
p_stderr(_("\nERROR: This is a mandatory atribute; you MUST provide a valid value!"));
correct = false;
} }
} }
while(!correct);
}
} }
void void
@ -1149,6 +1155,9 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
CommandParameter<int> resource_key(_("resource key"), 0, INT_MAX, true, 0); CommandParameter<int> resource_key(_("resource key"), 0, INT_MAX, true, 0);
CommandParameter<int> duration(_("duration"), 0, INT_MAX, true, 0); CommandParameter<int> duration(_("duration"), 0, INT_MAX, true, 0);
get_parameter(resource_key);
get_parameter(duration);
History& h = Simulation::get_instance().get_history(); History& h = Simulation::get_instance().get_history();
h.add_subrequest(*r, resource_key.value, duration.value); h.add_subrequest(*r, resource_key.value, duration.value);
@ -1815,7 +1824,13 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
void void
TextSimulation::update(const History& changed_history) TextSimulation::update(const History& changed_history)
{ {
p_stdout(_("\nqueue: { ")); ostringstream oss;
oss << changed_history.get_size() - 1 << _(".\tready queue: { ");
p_stdout(oss.str());
oss.str(string());
const Environment& env = changed_history.get_last_environment(); const Environment& env = changed_history.get_last_environment();
const ReadyQueue& q = env.get_sorted_queue(); const ReadyQueue& q = env.get_sorted_queue();
@ -1829,6 +1844,64 @@ TextSimulation::update(const History& changed_history)
p_stdout("}\n"); p_stdout("}\n");
p_stdout(_("\tresources:\n"));
const Environment::Resources& resources = env.get_resources();
typedef Environment::Resources::const_iterator ResourceIt;
for(ResourceIt it = resources.begin(); it != resources.end(); ++it)
{
const Resource& r = *it->second;
Environment::resource_key_t key = it->first;
oss << "\t\t" << key << ". " << r.get_name() << _(", with ");
oss << r.get_places() << _(" places\n");
p_stdout(oss.str());
oss.str(string());
// FIXME this code causes a segfault because an invalid reference is
// returned from get_request_queue()
// const Environment::SubRequestQueue& req_queue =
// env.get_request_queue(it->first);
//
// p_stdout(_("\t\t\tqueue: { "));
//
// for(unsigned int i = 0; i < req_queue.size(); ++i)
// {
// oss << req_queue[i]->get_request().get_thread().get_name() << " ~ ";
// p_stdout(oss.str());
// oss.str(string());
// }
//
// p_stdout("}\n");
}
p_stdout(_("\tprocesses:\n"));
const Environment::Processes& processes = env.get_processes();
for(unsigned int pi = 0; pi < processes.size(); ++pi)
{
Process& p = *processes[pi];
oss << "\t\t" << 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;
p_stdout(oss.str());
oss.str(string());
}
p_stdout("\n");
// History& h = History::get_instance(); // History& h = History::get_instance();
// int when, arr; // int when, arr;
// ustring temp; // ustring temp;