Project

General

Profile

root / branches / 1.1 / src / haizea / lwf / analysis.py @ 798

1
# -------------------------------------------------------------------------- #
2
# Copyright 2006-2010, University of Chicago                                 #
3
# Copyright 2008-2010, Distributed Systems Architecture Group, Universidad   #
4
# Complutense de Madrid (dsa-research.org)                                   #
5
#                                                                            #
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
7
# not use this file except in compliance with the License. You may obtain    #
8
# a copy of the License at                                                   #
9
#                                                                            #
10
# http://www.apache.org/licenses/LICENSE-2.0                                 #
11
#                                                                            #
12
# Unless required by applicable law or agreed to in writing, software        #
13
# distributed under the License is distributed on an "AS IS" BASIS,          #
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15
# See the License for the specific language governing permissions and        #
16
# limitations under the License.                                             #
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