Project

General

Profile

root / trunk / traces / undocumented / generators.py @ 641

1
# -------------------------------------------------------------------------- #
2
# Copyright 2006-2009, University of Chicago                                 #
3
# Copyright 2008-2009, 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

    
19
from haizea.common.config import TraceConfig, ImageConfig
20
from haizea.traces.formats import LWF, LWFEntry
21

    
22
def generateTrace(config, file, guaranteeAvg = False):
23
    tracedur = config.getTraceDuration()
24
    
25
    print config.intervaldist.getAvg()
26
    
27
    avgnumreq = tracedur / config.intervaldist.getAvg()
28
    idealaccumdur = avgnumreq * config.durationdist.getAvg() * config.numnodesdist.getAvg()
29

    
30
    print avgnumreq
31
    print config.durationdist.getAvg()
32
    print config.numnodesdist.getAvg()
33
    print idealaccumdur
34

    
35
    good = False
36
    deadlineavg = config.deadlinedist.get()
37

    
38
    while not good:
39
        entries = []
40
        time = - deadlineavg
41
        accumdur = 0
42
        while time + deadlineavg + config.durationdist.getAvg() < tracedur:
43
            entry = LWFEntry()
44
            entry.reqTime = time
45
            entry.startTime = time + config.deadlinedist.get()
46
            entry.duration = config.durationdist.get()
47
            entry.realDuration = entry.duration
48
            entry.numNodes = config.numnodesdist.get()
49
            entry.CPU = 1
50
            entry.mem = 1024
51
            entry.disk = 0
52
            entry.vmImage = "NONE.img"
53
            entry.vmImageSize = 600
54
            accumdur += entry.duration * entry.numNodes
55
            entries.append(entry)
56

    
57
            interval = config.intervaldist.get()          
58
            time += interval
59
            
60
        if not guaranteeAvg:
61
            good = True
62
        else:
63
            dev = abs((accumdur / idealaccumdur) - 1)
64
            if dev < 0.01:
65
                print "Deviation is satisfactory: %.3f" % dev
66
                good = True
67
            else:
68
                print "Deviation is too big: %.3f. Generating again." % dev
69

    
70
    for e in entries:
71
        if e.reqTime < 0:
72
            e.reqTime = 0
73

    
74
    lwf = LWF(entries)
75
    lwf.toFile(file)
76
        
77
        
78
def generateImages(config, file):
79
    f = open(file, "w")
80
    
81
    # Write image sizes
82
    for i in config.images:
83
        print >>f, "%s %i" % (i, config.sizedist.get())
84
    
85
    print >>f, "#"
86
    
87
    l = config.getFileLength()
88
    for i in xrange(l):
89
        print >>f, config.imagedist.get()
90

    
91
    f.close()
92

    
93

    
94
if __name__ == "__main__":
95
    configfile="../configfiles/images.conf"
96
    imagefile="../traces/examples/generated.images"
97

    
98

    
99
    config = ImageConfig.fromFile(configfile)
100
    
101
    generateImages(config, imagefile)