- Corrected get_front() issues.
- Widget tests are now working properly. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@990 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
4b3cce6bea
commit
47d4fe65b4
|
@ -122,7 +122,7 @@ ConcreteHistory::get_last_environment() const
|
|||
{
|
||||
// Should always be true:
|
||||
assert(_snapshots.size() > 0);
|
||||
return *_snapshots.back();
|
||||
return get_environment_at(get_front());
|
||||
}
|
||||
|
||||
|
||||
|
@ -487,6 +487,16 @@ ConcreteHistory::edit_subrequest(SubRequest& subrequest,
|
|||
reset(true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConcreteHistory::step_front(position p)
|
||||
{
|
||||
_front = p;
|
||||
if (p > _snapshots.size())
|
||||
_front = _snapshots.size();
|
||||
notify_change();
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteHistory::reset(bool notify)
|
||||
{
|
||||
|
@ -496,6 +506,7 @@ ConcreteHistory::reset(bool notify)
|
|||
|
||||
for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>());
|
||||
_snapshots.resize(1); // Truncate to keep only our "model"
|
||||
_front = 0;
|
||||
|
||||
if (notify)
|
||||
notify_change();
|
||||
|
|
|
@ -110,6 +110,7 @@ namespace sgpem
|
|||
time_t duration);
|
||||
|
||||
|
||||
virtual void step_front(position p);
|
||||
|
||||
virtual void reset(bool notify = true);
|
||||
|
||||
|
|
|
@ -65,7 +65,6 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
|
|||
break;
|
||||
case state_stopped:
|
||||
_history.reset(true);
|
||||
_front = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -81,12 +80,15 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
|
|||
_history.set_notify_enabled(false);
|
||||
|
||||
bool yet_to_finish = true;
|
||||
while (yet_to_finish && p > _front)
|
||||
History::position increment = 0;
|
||||
while (yet_to_finish && p > _history.get_front() + increment)
|
||||
{
|
||||
yet_to_finish = step();
|
||||
|
||||
increment++;
|
||||
}
|
||||
get_history().step_front(p);
|
||||
if (!yet_to_finish)
|
||||
stop();
|
||||
_front = std::min(p, _front);
|
||||
|
||||
// Reenables updates to registered observers.
|
||||
// Calls _history.notify_change() on reactivation.
|
||||
|
@ -125,7 +127,6 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
|
|||
{
|
||||
case state_stopped:
|
||||
_history.reset(true);
|
||||
_front = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -135,6 +136,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
|
|||
|
||||
//step forward
|
||||
bool yet_to_finish = step();
|
||||
get_history().step_front(get_history().get_front() + 1);
|
||||
if (yet_to_finish)
|
||||
{
|
||||
if(_mode == mode_step_by_step)
|
||||
|
@ -173,9 +175,8 @@ ConcreteSimulation::step()
|
|||
{
|
||||
//step forward
|
||||
bool yet_to_finish = true;
|
||||
if (_front == get_history().get_size() - 1)
|
||||
if (get_history().get_front() == get_history().get_size() - 1)
|
||||
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy(), *get_resource_policy());
|
||||
_front++;
|
||||
return yet_to_finish;
|
||||
}
|
||||
catch (const CPUPolicyException& e)
|
||||
|
|
|
@ -30,7 +30,7 @@ using namespace std;
|
|||
|
||||
|
||||
History::History()
|
||||
: _notify(true)
|
||||
: _front(0), _notify(true)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -65,6 +65,11 @@ History::notify_change()
|
|||
}
|
||||
|
||||
|
||||
unsigned int History::get_front() const
|
||||
{
|
||||
return _front;
|
||||
}
|
||||
|
||||
bool
|
||||
History::set_notify_enabled(bool enabled)
|
||||
{
|
||||
|
|
|
@ -128,6 +128,7 @@ namespace sgpem
|
|||
resource_key_t resource_key,
|
||||
time_t duration) = 0;
|
||||
|
||||
virtual position get_front() const;
|
||||
|
||||
virtual void attach(HistoryObserver& observer);
|
||||
virtual void detach(const HistoryObserver& observer);
|
||||
|
@ -148,7 +149,11 @@ namespace sgpem
|
|||
|
||||
virtual void notify_change();
|
||||
|
||||
position _front;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
bool _notify;
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ using namespace sgpem;
|
|||
template class SG_DLLEXPORT Singleton<ConcreteSimulation>;
|
||||
|
||||
Simulation::Simulation()
|
||||
: _notify(true), _front(0)
|
||||
: _notify(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,6 @@ Simulation::detach(const SimulationObserver& observer)
|
|||
&observer));
|
||||
}
|
||||
|
||||
unsigned int Simulation::get_front() const
|
||||
{
|
||||
return _front;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::notify_change()
|
||||
{
|
||||
|
|
|
@ -159,8 +159,6 @@ namespace sgpem
|
|||
|
||||
virtual const History& get_history() const = 0;
|
||||
|
||||
virtual unsigned int get_front() const;
|
||||
|
||||
/**
|
||||
* Small kludge to avoid the need for declaration of ConcreteSimulation
|
||||
* by the calling code of Simulation::get_instance()
|
||||
|
@ -186,9 +184,6 @@ namespace sgpem
|
|||
typedef std::vector<SimulationObserver*> RegisteredObservers;
|
||||
RegisteredObservers _observers;
|
||||
|
||||
// since no constructor is available, these fields must be defined in concrete subclasses.
|
||||
History::position _front;
|
||||
|
||||
Simulation(); // Constructor
|
||||
|
||||
virtual void notify_change();
|
||||
|
|
|
@ -230,7 +230,7 @@ SimulationWidget::draw_grid(cairo_t* ctx)
|
|||
// useful constants
|
||||
const History& hist = _simulation->get_history();
|
||||
//const int hist_size = hist.get_size();
|
||||
const unsigned int simu_front = _simulation->get_front();
|
||||
const unsigned int hist_front = hist.get_front();
|
||||
const double top_margin = _yu_top_margin * _y_unit;
|
||||
const double left_margin = _x_unit;
|
||||
const double left_graph_margin = _xu_left_graph_margin * _x_unit;
|
||||
|
@ -238,7 +238,7 @@ SimulationWidget::draw_grid(cairo_t* ctx)
|
|||
const double process_bar_height = _yu_process_bar_height * _y_unit;
|
||||
const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit;
|
||||
const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit;
|
||||
const double graph_width = (2.0 + simu_front) * _x_unit;
|
||||
const double graph_width = (2.0 + hist_front) * _x_unit;
|
||||
const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height;
|
||||
|
||||
// draw graph grid
|
||||
|
@ -282,7 +282,7 @@ SimulationWidget::draw_grid(cairo_t* ctx)
|
|||
top_margin + graph_height + 2.0 * _y_unit);
|
||||
cairo_show_text(ctx,"T");
|
||||
|
||||
for(int t=0; t<=simu_front; t++)
|
||||
for(int t=0; t<=hist_front; t++)
|
||||
{
|
||||
cairo_move_to(ctx, left_graph_margin + (t+1)*_x_unit,
|
||||
top_margin + graph_height);
|
||||
|
@ -305,7 +305,7 @@ SimulationWidget::draw_bars(cairo_t* ctx)
|
|||
|
||||
// useful constants
|
||||
const History& hist = _simulation->get_history();
|
||||
const unsigned int simu_front = _simulation->get_front();
|
||||
const unsigned int hist_front = hist.get_front();
|
||||
const double top_margin = _yu_top_margin * _y_unit;
|
||||
const double left_margin = _x_unit;
|
||||
const double left_graph_margin = _xu_left_graph_margin * _x_unit;
|
||||
|
@ -315,11 +315,11 @@ SimulationWidget::draw_bars(cairo_t* ctx)
|
|||
const double thread_bar_height = _yu_thread_bar_height * _y_unit;
|
||||
const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit;
|
||||
const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit;
|
||||
const double graph_width = (2.0 + simu_front) * _x_unit;
|
||||
const double graph_width = (2.0 + hist_front) * _x_unit;
|
||||
const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height;
|
||||
|
||||
|
||||
for(int t=1; t<=simu_front; t++)
|
||||
for(int t=1; t<=hist_front; t++)
|
||||
{
|
||||
// draw schedulables bars
|
||||
double xpos = left_graph_margin + t * _x_unit; // left start of first process
|
||||
|
@ -456,7 +456,7 @@ SimulationWidget::draw_widget(cairo_t* ctx)
|
|||
cairo_reset_clip(ctx); // remove clip region
|
||||
|
||||
// std::cout << " draw_widget not_stop " << std::endl;
|
||||
unsigned int pos = _simulation->get_front();
|
||||
unsigned int pos = _simulation->get_history().get_front();
|
||||
|
||||
// show grid
|
||||
cairo_save(ctx);
|
||||
|
@ -589,7 +589,7 @@ SimulationWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
|
|||
return;
|
||||
const History& hist = _simulation->get_history();
|
||||
const Environment::Processes& processes = hist.get_last_environment().get_processes();
|
||||
int pos = _simulation->get_front();
|
||||
int pos = _simulation->get_history().get_front();
|
||||
cairo_text_extents_t extents;
|
||||
|
||||
// std::cout << " x_unit: " << std::endl;
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
#include "backend/cpu_policies_gatekeeper.hh"
|
||||
#include "backend/cpu_policy.hh"
|
||||
#include "backend/cpu_policy_manager.hh"
|
||||
#include "backend/resource_policies_gatekeeper.hh"
|
||||
#include "backend/resource_policy.hh"
|
||||
#include "backend/resource_policy_manager.hh"
|
||||
#include "backend/history_observer.hh"
|
||||
#include "backend/scheduler.hh"
|
||||
#include "backend/simulation.hh"
|
||||
|
@ -419,6 +422,9 @@ main(int argc, char** argv)
|
|||
History& hist = Simulation::get_instance().get_history();
|
||||
info << "gets history \n";
|
||||
|
||||
ResourcePolicyManager & rpm = *ResourcePoliciesGatekeeper::get_instance().get_registered().at(0);
|
||||
Simulation::get_instance().set_resource_policy(rpm.get_avail_policies().at(0));
|
||||
|
||||
DummyPolicyManager dummy_manager;
|
||||
|
||||
const std::vector<CPUPolicy*>& policies = dummy_manager.get_avail_policies();
|
||||
|
|
|
@ -1664,7 +1664,7 @@ TextSimulation::update(const Simulation& changed_simulation)
|
|||
|
||||
|
||||
// Print header for each instant:
|
||||
printed_instant = static_cast<int>(changed_simulation.get_front()) - 1;
|
||||
printed_instant = static_cast<int>(changed_simulation.get_history().get_front()) - 1;
|
||||
|
||||
oss << endl << ">>>> " << printed_instant;
|
||||
|
||||
|
@ -1672,7 +1672,7 @@ TextSimulation::update(const Simulation& changed_simulation)
|
|||
// Print ready queue
|
||||
oss << endl << _("READY QUEUE: { ");
|
||||
|
||||
const Environment& env = changed_simulation.get_history().get_environment_at(changed_simulation.get_front());
|
||||
const Environment& env = changed_simulation.get_history().get_last_environment();
|
||||
const ReadyQueue& q = env.get_sorted_queue();
|
||||
|
||||
for (unsigned int i = 0; i < q.size(); ++i)
|
||||
|
|
Loading…
Reference in New Issue