Project

General

Profile

Revision 798

Utilization-based LWF generation (still needs some work, but mostly done)

View differences:

analysis.py
14 14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15 15
# See the License for the specific language governing permissions and        #
16 16
# limitations under the License.                                             #
17
# -------------------------------------------------------------------------- #
17
# -------------------------------------------------------------------------- #
18
from mx.DateTime import DateTime
19
from haizea.core.leases import LeaseWorkload, Site
20

  
21

  
22
class LWFAnalyser(object):
23
    
24
    
25
    def __init__(self, lwffile, utilization_length):
26
        # Arbitrary start time
27
        self.starttime = DateTime(2006,11,25,13)
28
        
29
        self.workload = LeaseWorkload.from_xml_file(lwffile, self.starttime)
30
        self.site = Site.from_lwf_file(lwffile)
31
        
32
        if utilization_length == None:
33
            self.utilization_length = self.workload.get_leases()[-1].submit_time - self.starttime
34
        else:
35
            self.utilization_length = utilization_length
36
        print self.utilization_length
37
        
38
    def analyse(self):
39
        utilization = 0
40
        for lease in self.workload.get_leases():
41
            if lease.start.requested + lease.duration.requested > self.starttime + self.utilization_length:
42
                duration = self.starttime + self.utilization_length - lease.start.requested
43
            else: 
44
                duration = lease.duration.requested.seconds
45
            for res in lease.requested_resources.values():
46
                for i in range(1,res.get_ninstances("CPU") + 1):
47
                    utilization += res.get_quantity_instance("CPU", i) * duration
48
        
49
        if self.site != None:
50
            max_utilization = 0
51
            duration = self.utilization_length.seconds
52
            for res in self.site.nodes.get_all_nodes().values():
53
                for i in range(1,res.get_ninstances("CPU") + 1):
54
                    max_utilization += res.get_quantity_instance("CPU", i) * duration
55
            
56
        
57
        print "Utilization: %.2f%%" % (utilization / max_utilization)
58
        

Also available in: Unified diff