From 997ead080b5850d01eba6440985c998e8b7355ad Mon Sep 17 00:00:00 2001 From: paolo Date: Sat, 16 Sep 2006 01:38:03 +0000 Subject: [PATCH] - holt_widget: added places used/total to resources git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1184 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/holt_widget.cc | 67 +++++++++++++++++++++++++++++++++++++++------- src/holt_widget.hh | 27 ++++++++++++++++++- 2 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/holt_widget.cc b/src/holt_widget.cc index 980acfb..c72fbec 100644 --- a/src/holt_widget.cc +++ b/src/holt_widget.cc @@ -93,10 +93,11 @@ double HoltNode::get_radius() HoltResource::HoltResource(const Resource& resource, resource_key_t resource_key, Vec2 pt) -: HoltNode(pt) +: HoltNode(pt), + _resource(&resource), + _resource_key(resource_key), + _used_places(0) { - _resource = &resource; - _resource_key = resource_key; } HoltResource::~HoltResource() @@ -121,22 +122,51 @@ void HoltResource::draw(cairo_t *cr) cairo_save(cr); // clip text outside region - cairo_rectangle(cr, _pos.real() - _radius, _pos.imag() - _radius, - 2 * _radius * x_percent, 2 * _radius * y_percent); + /* + cairo_rectangle(cr, + _pos.real() - _radius, + _pos.imag() - _radius, // _pos.imag() + _radius (1 - 2.0 * y_percent) + 2 * _radius * x_percent, + 2 * _radius * y_percent); + */ + + cairo_rectangle(cr, + _pos.real() - _radius, + _pos.imag() + _radius * (1 - 2.0 * y_percent), + 2 * _radius * x_percent, + 2 * _radius * y_percent); cairo_clip(cr); // draw text cairo_text_extents_t extents; cairo_text_extents(cr, _resource->get_name().c_str(), &extents); - double xpos = _pos.real() - extents.width * (1 - x_percent + x_percent / 2); + double xpos = _pos.real() + _radius * (x_percent-1) - extents.width/2.0; + double ypos = _pos.imag() + _radius * (1 - y_percent); // + extents.height/2; + // _pos.imag() + extents.height * ((1 - y_percent) / 2 + 0.5) + // left aligned if too large if(xpos<_pos.real() - _radius) xpos = _pos.real() - _radius; cairo_move_to(cr, xpos, - _pos.imag() + extents.height * ((1 - y_percent) / 2 + 0.5) ); + ypos ); cairo_show_text(cr, _resource->get_name().c_str()); + // show used/total places + Glib::ustring used; + to_string((int)_used_places, used); + Glib::ustring total; + to_string((int)_resource->get_places(), total); + + Glib::ustring msg = used + "/" + total; + cairo_text_extents(cr, msg.c_str(), &extents); + xpos = _pos.real() + _radius * (x_percent-1) - extents.width/2.0; + ypos = _pos.imag() + _radius * (1 - y_percent) + extents.height*2; + cairo_move_to(cr, + xpos, + ypos ); + cairo_show_text(cr, msg.c_str()); + // stroke all cairo_stroke (cr); @@ -169,6 +199,19 @@ Vec2 HoltResource::get_intersection_to(Vec2 pt) +void +HoltResource::allocate(unsigned int places) +{ + _used_places += places; +} + +unsigned int +HoltResource::get_allocated() +{ + return _used_places; +} + + HoltSchedulable::HoltSchedulable(const Schedulable& schedulable, Vec2 pt) @@ -255,11 +298,12 @@ Vec2 HoltSchedulable::get_intersection_to(Vec2 pt) -HoltRequest::HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state) +HoltRequest::HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state, unsigned int places) : _hp(&hp), _hr(&hr), _state(state) { + hr.allocate(places); } HoltRequest::~HoltRequest() @@ -506,8 +550,8 @@ HoltWidget::arrange() else mul = Vec2(0,0); - // cen = Vec2(2*_radius+inc.real(), 2*_radius+inc.real()); cen = Vec2(2*_radius+std::abs(inc), 2*_radius+std::abs(inc)); + // cen = Vec2(sx/2.0, sy/2.0); pos = inc + cen; } @@ -726,7 +770,10 @@ HoltWidget::acquire() if (pos != env.get_resources().end() && hpos!=_holt_resources.end()) { // associates process (or thread) with resource) - HoltRequest *hreq = new HoltRequest(*hp, *(hpos->second), sr->get_state()); + unsigned int nplaces = 0; + if(sr->get_state()==Request::state_allocated) + nplaces++; + HoltRequest *hreq = new HoltRequest(*hp, *(hpos->second), sr->get_state(), nplaces); _holt_requests.push_back(hreq); } } // ~ if(subr_state==Request::state_unallocable ... etc diff --git a/src/holt_widget.hh b/src/holt_widget.hh index 95ec725..863dba8 100644 --- a/src/holt_widget.hh +++ b/src/holt_widget.hh @@ -209,6 +209,20 @@ namespace sgpem */ virtual Vec2 get_intersection_to(Vec2 pt); + /** + * \brief Allocates resource places. + * + * \param places Number to allocate. + */ + void allocate(unsigned int places); + + /** + * \brief Gets allocates resource places. + * + * \return Number of places allocated. + */ + unsigned int get_allocated(); + private: /** * \brief Pointer to the related resource. @@ -219,9 +233,18 @@ namespace sgpem * \brief Numeric key associated with this resource. */ resource_key_t _resource_key; + + /** + * \brief Numeric key associated with this resource. + */ + unsigned int _used_places; + + }; + + /** * \brief An holt node representing schedulables (processes and threads). * @@ -276,6 +299,8 @@ namespace sgpem const Schedulable* _schedulable; }; + + /** * \brief Base class to draw holt graph arrows (requests/allocation). * @@ -299,7 +324,7 @@ namespace sgpem * \param hr Reference to HoltResource. * \param state Type of request. */ - HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state); + HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state, unsigned int places); /** * \brief Object's virtual destructor.