#!/usr/bin/python import os import string import StringIO from time import gmtime, strftime import datetime from optparse import OptionParser from DataCollector import * from YamlToMap import * from HistoryManager import * import Version #################### Taking all the arguments ########################## parser = OptionParser(version=Version.full) parser.set_description( "Efficiency Guardian launches efficiency tests comparing the results with a reference execution. "+ "It also may interact with a server which stores the history.") parser.set_usage("%prog [options] [command [command-options] ]") parser.disable_interspersed_args() # The first non option argument stops options to allow program arguments parser.add_option("-u", "--upload-data", action="store_true",dest="Upload", help="upload this execution efficiency to the server") parser.add_option("-s", "--set-as-reference", action="store_true",dest="Last", help="set this execution efficiency as local reference") parser.add_option("-d", "--get-reference", action="store_true",dest="Reference", help="download the server's reference") #parser.add_option("-b", "--download-reference-alarms", action="store_true",dest="References", # help="Download the current reference and Alarms files") parser.add_option("-c", "--change-reference", dest="Change", metavar="DATE", help="download efficiency status at DATE as reference (format (YYMMDD-HHMMSS)") parser.add_option("-a","--get-alarms", action="store_true",dest="Alarms", help="download alarms thresholds from server") parser.add_option("-p", "--project", dest="Project", action='store', metavar="PROJECT", default="DEFAULT", help="use PROJECT for remote operations") (options, args) = parser.parse_args() #################### Error Management ############################ print options values=[options.Reference,options.Alarms,options.Change] if values.count(None)<2: parser.error("options -c, -a and -d are mutually exclusive") if values.count(None)<1: if options.Upload or options.Last: parser.error ("options -s, -a and -d are incompatible with -u, -c") if args==None: parser.error("options -s, -a and -d needs an argument") if (options.Upload or options.Change) and args==None: parser.error("options -u and -c needs an argument") project = options.Project #################### Guardian Services ############################# HM=HistoryManager() if options.Reference: HM.Connect() referenceFile=HM.GetReference(project) if referenceFile=="": parser.error("There isn\'t any project called '%s'"%project) #file("Reference.yml").write(HM.GetReference(project)) elif options.Alarms: HM.Connect() alarmsFile=HM.GetAlarms(project) if alarmsFile=="": parser.error("There isn\'t any project called '%s'"%project) #file("Alarms.yml").write(HM.GetAlarms(project)) elif options.Change: HM.Connect() referenceFile=HM.GetDatedReference(options.Change[1:],project) if referenceFile=="": parser.error("There isn\'t any project called '%s'"%project) #file("Reference.yml").write(HM.GetDatedReference(options.change[1:],project)) HM.closeConn() ##################### Collecting data ############################ elif args: testingDate = strftime("%Y%m%d-%H%M%S",gmtime()) os.spawnv(os.P_WAIT, "/usr/bin/valgrind", [ "valgrind", "-q", "--tool=callgrind", "--simulate-cache=yes", "--base=callgrind-"+testingDate+".out", ] +args) os.system("cp callgrind-"+testingDate+".out.* logfile") inputFile=open("logfile",'r') dataCollector=DataCollector() dataCollector.costsToYamlFile(inputFile) os.system("mv YamlFile.yml module-"+testingDate+".yml") if options.Last: os.system("cp module-"+testingDate+".yml Reference.yml") if options.Upload: HM.Connect() yamlToMap=YamlToMap() yamlFile=open("module-"+testingDate+".yml") entry=yamlToMap.fileToMap(yamlFile) HM.AddEntry(project,testingDate,entry) HM.closeConn()