- Add a widget to show the ReadyQueue

- Change slightly the gradients of the SimulationWidget to make
them more aggressive. Bite, Fido! :-)


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1025 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-09-06 14:51:53 +00:00
parent dbfc7393ed
commit cb1d85a4cc
7 changed files with 584 additions and 869 deletions

View File

@ -306,6 +306,7 @@ sgpemv2_SOURCES = \
src/holt_widget.cc \
src/main.cc \
src/parse_opts.cc \
src/ready_queue_widget.cc \
src/resources_widget.cc \
src/schedulable_state_widget.cc \
src/schedulables_tree_widget.cc \
@ -323,6 +324,7 @@ noinst_HEADERS += \
src/holt_widget.hh \
src/main.hh \
src/parse_opts.hh \
src/ready_queue_widget.hh \
src/resources_widget.hh \
src/schedulable_state_widget.hh \
src/schedulables_tree_widget.hh \

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,7 @@
#include "graphical_preferences_editor.hh"
#include "holt_container_window.hh"
#include "holt_widget.hh"
#include "ready_queue_widget.hh"
#include "schedulables_tree_widget.hh"
#include "simulation_widget.hh"
#include "resources_widget.hh"
@ -576,15 +577,18 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
_simulation_widget->set_show_threads(_show_threads);
_simulation_widget->show();
// Why this works, and SimulationWidget doesn't ??
// HoltWidget& holt = *manage(new HoltWidget(Simulation::get_instance()));
// simulation_window->add(holt);
// holt.show();
// temporary test on holt widget...
// ReadyQueue custom label widget
ReadyQueueWidget& rq_widget = *manage(new ReadyQueueWidget(Simulation::get_instance().get_history()));
HBox* rqb;
_refXml->get_widget("ReadyQueueBox", rqb);
rqb->pack_start(rq_widget);
rq_widget.show();
// HoltGraph container window
_holt_container.set_keep_above();
_holt_container.get_holt_widget().set_show_threads(_show_threads);
// _holt_container.set_deletable(false);
_holt_container.show();
}

73
src/ready_queue_widget.cc Normal file
View File

@ -0,0 +1,73 @@
// src/ready_queue_widget.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "gettext.h"
#include "ready_queue_widget.hh"
#include "backend/history.hh"
#include "backend/environment.hh"
#include "backend/ready_queue.hh"
#include "backend/thread.hh"
#include <glibmm/markup.h>
#include <glibmm/ustring.h>
#include <sstream>
using namespace sgpem;
static const Glib::ustring string_start = _("<b>Ready queue: { </b>");
static const Glib::ustring string_end = "<b> }</b>";
static const Glib::ustring separator = " ~ ";
ReadyQueueWidget::ReadyQueueWidget(History& history)
: Gtk::Label(string_start + string_end), _h(history)
{
_h.attach(*this);
set_use_markup(true);
set_justify(Gtk::JUSTIFY_LEFT);
set_padding(5, 3);
}
ReadyQueueWidget::~ReadyQueueWidget()
{
_h.detach(*this);
}
void
ReadyQueueWidget::update(const History& changed_history)
{
Glib::ustring text(string_start);
const ReadyQueue& rq = changed_history.get_last_environment().get_sorted_queue();
size_t size = rq.size();
for(size_t i = 0; i < size; ++i)
text += Glib::Markup::escape_text(rq.get_item_at(i).get_name()) + separator;
text += string_end;
set_markup(text);
}

46
src/ready_queue_widget.hh Normal file
View File

@ -0,0 +1,46 @@
// src/ready_queue_widget.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef READY_QUEUE_WIDGET_HH
#define READY_QUEUE_WIDGET_HH 1
#include "config.h"
#include <gtkmm/label.h>
#include "backend/history_observer.hh"
namespace sgpem
{
class ReadyQueueWidget : public HistoryObserver, public Gtk::Label
{
public:
ReadyQueueWidget(History& history);
virtual ~ReadyQueueWidget();
virtual void update(const History& changed_history);
private:
History& _h;
};
} //~ namespace sgpem
#endif //~ READY_QUEUE_WIDGET_HH

View File

@ -38,7 +38,10 @@
#include <gtkmm/menuitem.h>
#include <cassert>
#ifndef NDEBUG
#include <iostream>
#endif
using namespace sgpem;
using Gnome::Glade::Xml;

View File

@ -164,7 +164,6 @@ SimulationWidget::draw_widget(cairo_t* ctx)
void
SimulationWidget::draw_names(cairo_t* ctx)
{
// std::cout << " SimulationWidget::draw_names " << std::endl;
// show processes (and thread) names...
// useful constants
@ -331,7 +330,10 @@ SimulationWidget::draw_bars(cairo_t* ctx)
from_time = 1;
}
#ifndef NDEBUG
std::cout << " SimulationWidget::draw_bars from:" << from_time << " to:" << hist_front << std::endl;
#endif
for(unsigned int t=from_time; t<=hist_front; t++)
{
// draw schedulables bars
@ -373,12 +375,6 @@ void
SimulationWidget::draw_instant_rect(cairo_t* ctx, double x, double y,
double w, double h, Schedulable::state state)
{
// _ready_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// _running_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// _blocked_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
cairo_matrix_t matrix;
switch(state)
@ -429,212 +425,10 @@ SimulationWidget::draw_instant_rect(cairo_t* ctx, double x, double y,
} // ~ switch(state)
}
// OLD - START ***************
/*
void
SimulationWidget::draw_widget(cairo_t* ctx)
{
const History& hist = _simulation->get_history();
const Environment::Processes& processes = hist.get_last_environment().get_processes();
if(_n_proc<1) // nothing to draw
return;
double text_maxw = 0;
bool* terminated = 0;
double top_margin = _y_unit;
double left_margin = _x_unit;
double top_graph_margin = 1.0 * _y_unit; //3.0 * _y_unit;
double left_graph_margin = 11.0 * _x_unit;
double process_label_delta = 1.0 * _y_unit;
double process_bar_delta = 1.0 * _y_unit;
double process_bar_height = 1.0 * _y_unit;
double process_height = process_bar_height + 2*process_bar_delta;
double thread_bar_height = 1.0 * _y_unit;
Simulation::state sim_state = _simulation->get_state();
cairo_text_extents_t extents;
int item_index;
if(_n_proc+_n_thr>0)
terminated = new bool[_n_proc+_n_thr];
// show processes names...
// set clip region to cut long names
cairo_rectangle(ctx, 0, top_graph_margin,
left_graph_margin - _x_unit, _n_proc*process_height + _n_thr*thread_bar_height);
cairo_clip(ctx); // set the rectangular clip region
{ // draw schedulables names block
item_index = 0;
double ypos = top_graph_margin; // height of process bar
const Environment::Processes& processes = hist.get_last_environment().get_processes();
Environment::Processes::const_iterator proc_iter = processes.begin();
while(proc_iter!=processes.end())
{
Process* p = (*proc_iter);
proc_iter++;
ypos += process_bar_delta; // white row before
cairo_move_to(ctx, left_margin, ypos);
cairo_show_text(ctx,p->get_name().c_str());
ypos += process_bar_delta; // height of process bar
terminated[item_index] = false;
item_index++;
if(_show_threads)
{
const std::vector<Thread*>& tvect = p->get_threads();
std::vector<Thread*>::const_iterator thr_iter = tvect.begin();
while(thr_iter!=tvect.end())
{
Thread* t = (*thr_iter);
thr_iter++;
cairo_move_to(ctx, left_margin+_x_unit, ypos);
cairo_show_text(ctx,t->get_name().c_str());
ypos += thread_bar_height; // height of process bar
terminated[item_index] = false;
item_index++;
}
}
ypos += process_bar_delta; // white row after
} // ~ while(proc_iter!=processes.end())
} // ~ draw schedulables names block
cairo_reset_clip(ctx); // remove clip region
// std::cout << " draw_widget not_stop " << std::endl;
unsigned int pos = _simulation->get_history().get_front();
// show grid
cairo_save(ctx);
cairo_set_line_width(ctx, 0.5*cairo_get_line_width(ctx));
// _n_proc+1 horizontal lines
for(int i=0; i<=_n_proc; i++)
{
cairo_move_to(ctx, left_graph_margin, top_graph_margin + process_height*i);
cairo_line_to(ctx, left_graph_margin + (pos+2)*_x_unit, top_graph_margin + process_height*i);
}
// opening vertical line
cairo_move_to(ctx, left_graph_margin, top_graph_margin);
cairo_line_to(ctx, left_graph_margin, top_graph_margin + process_height*_n_proc);
cairo_stroke(ctx);
// closing vertical line
if(sim_state!=Simulation::state_stopped)
{
double dashes = 1.5;
cairo_set_dash(ctx, &dashes, 1, 0.0);
}
cairo_move_to(ctx, left_graph_margin + (pos+2)*_x_unit, top_graph_margin);
cairo_line_to(ctx, left_graph_margin + (pos+2)*_x_unit, top_graph_margin + process_height*_n_proc);
cairo_stroke(ctx);
cairo_restore(ctx);
item_index = 0;
for(int t=1; t<=pos; t++)
{
double ypos = top_graph_margin;
const Environment::Processes& processes = hist.get_environment_at(t).get_processes();
double xpos = left_graph_margin + t*_x_unit;
Environment::Processes::const_iterator proc_iter = processes.begin();
while(proc_iter!=processes.end())
{
Process* p = (*proc_iter);
proc_iter++;
ypos += process_bar_delta; // space y before process bar
Schedulable::state st = p->get_state();
// Schedulable::state st = processes[i]->get_state();
switch(st)
{
case Schedulable::state_running:
cairo_set_source_rgb(ctx, 0, 1, 0);
cairo_rectangle(ctx, xpos, ypos, _x_unit, _y_unit);
cairo_fill(ctx);
break;
case Schedulable::state_ready:
cairo_set_source_rgb(ctx, 1, 1, 0);
cairo_rectangle(ctx, xpos, ypos, _x_unit, _y_unit);
cairo_fill(ctx);
break;
case Schedulable::state_blocked:
cairo_set_source_rgb(ctx, 1, 0, 0);
cairo_rectangle(ctx, xpos, ypos, _x_unit, _y_unit);
cairo_fill(ctx);
break;
case Schedulable::state_future:
break;
case Schedulable::state_terminated:
if(!terminated[item_index])
{
cairo_set_source_rgb(ctx, 0, 0, 0);
cairo_rectangle(ctx, xpos, ypos, _x_unit, _y_unit);
cairo_fill(ctx);
}
terminated[item_index] = true;
break;
}
ypos += process_bar_delta; // height of process bar
item_index++;
if(_show_threads)
{
const std::vector<Thread*>& tvect = p->get_threads();
std::vector<Thread*>::const_iterator thr_iter = tvect.begin();
while(thr_iter!=tvect.end())
{
Thread* t = (*thr_iter);
thr_iter++;
Schedulable::state thr_state = t->get_state();
switch(thr_state)
{
case Schedulable::state_running:
cairo_set_source_rgb(ctx, 0, 1, 0);
cairo_rectangle(ctx, xpos, ypos+_y_unit/3.0, _x_unit, _y_unit/3.0);
cairo_fill(ctx);
break;
case Schedulable::state_ready:
cairo_set_source_rgb(ctx, 1, 1, 0);
cairo_rectangle(ctx, xpos, ypos+_y_unit/3.0, _x_unit, _y_unit/3.0);
cairo_fill(ctx);
break;
case Schedulable::state_blocked:
cairo_set_source_rgb(ctx, 1, 0, 0);
cairo_rectangle(ctx, xpos, ypos+_y_unit/3.0, _x_unit, _y_unit/3.0);
cairo_fill(ctx);
break;
case Schedulable::state_future:
break;
case Schedulable::state_terminated:
if(!terminated[item_index])
{
cairo_set_source_rgb(ctx, 0, 0, 0);
cairo_rectangle(ctx, xpos, ypos+_y_unit/3.0, _x_unit, _y_unit/3.0);
cairo_fill(ctx);
}
terminated[item_index] = true;
break;
} // ~ switch(thr_state) - thread
item_index++;
ypos += thread_bar_height; // height of process bar
} // ~ while(thr_iter!=tvect.end())
}
}
} // ~ for(int t=1; t<=pos; t++)
delete[] terminated;
} // ~ draw_widget
// OLD - END ******************
*/
void
SimulationWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
{
// std::cout << "Simulation widget BEFORE calc_drawing_size width=" << width << " height=" << height << std::endl;
if(!_simulation)
return;
const History& hist = _simulation->get_history();
@ -642,7 +436,6 @@ SimulationWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
int pos = _simulation->get_history().get_front();
cairo_text_extents_t extents;
// std::cout << " x_unit: " << std::endl;
Glib::ustring val("999");
cairo_text_extents(ctx, val.c_str(), &extents);
if(_x_unit<extents.width)
@ -656,8 +449,6 @@ SimulationWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
height = (size_t)((_yu_top_margin + (_yu_process_bar_spacing*2.0+_yu_process_bar_height) * _n_proc + 3.0) * _y_unit);
if(_show_threads)
height += (size_t) (_n_thr * (_yu_thread_bar_spacing*2.0+_yu_thread_bar_height) * _y_unit);
// std::cout << "Simulation widget AFTER calc_drawing_size width=" << width << " height=" << height << std::endl;
}
@ -666,7 +457,6 @@ SimulationWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
void
SimulationWidget::count_elements()
{
std::cout << "SimulationWidget::count_elements" << std::endl;
_n_proc = _n_thr = 0;
const History& hist = _simulation->get_history();
@ -684,8 +474,6 @@ SimulationWidget::count_elements()
_n_thr += p->get_threads().size();
}
std::cout << " _n_proc=" << _n_proc << " _n_thr=" << _n_thr << std::endl;
// count_elements();
}
void
@ -694,17 +482,20 @@ SimulationWidget::make_gradients()
_ready_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// yellow
cairo_pattern_add_color_stop_rgba(_ready_process_gradient, 0.00, 1.0, 1.0, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(_ready_process_gradient, 1.00, 1.0, 1.0, 0.0, 1.0);
cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 0.0, 1.00, 1.00, 0.0);
cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 0.3, 0.85, 0.85, 0.0);
cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 1.0, 1.00, 1.00, 0.0);
_running_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// green
cairo_pattern_add_color_stop_rgba(_running_process_gradient, 0.00, 0.5, 1.0, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(_running_process_gradient, 1.00, 0.0, 1.0, 0.0, 1.0);
cairo_pattern_add_color_stop_rgb(_running_process_gradient, 0.0, 0.0, 0.7, 0.0);
cairo_pattern_add_color_stop_rgb(_running_process_gradient, 0.3, 0.0, 1.0, 0.0);
cairo_pattern_add_color_stop_rgb(_running_process_gradient, 1.0, 0.0, 0.7, 0.0);
_blocked_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// red
cairo_pattern_add_color_stop_rgba(_blocked_process_gradient, 0.00, 1.0, 0.5, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(_blocked_process_gradient, 1.00, 1.0, 0.0, 0.0, 1.0);
cairo_pattern_add_color_stop_rgb(_blocked_process_gradient, 0.0, 0.7, 0.0, 0.0);
cairo_pattern_add_color_stop_rgb(_blocked_process_gradient, 0.3, 1.0, 0.0, 0.0);
cairo_pattern_add_color_stop_rgb(_blocked_process_gradient, 1.0, 0.7, 0.0, 0.0);
}