当前位置: 首页>>代码示例>>Python>>正文


Python ComponentProxy.get_running_job_number方法代码示例

本文整理汇总了Python中Cobalt.Proxy.ComponentProxy.get_running_job_number方法的典型用法代码示例。如果您正苦于以下问题:Python ComponentProxy.get_running_job_number方法的具体用法?Python ComponentProxy.get_running_job_number怎么用?Python ComponentProxy.get_running_job_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cobalt.Proxy.ComponentProxy的用法示例。


在下文中一共展示了ComponentProxy.get_running_job_number方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PowerMonitor

# 需要导入模块: from Cobalt.Proxy import ComponentProxy [as 别名]
# 或者: from Cobalt.Proxy.ComponentProxy import get_running_job_number [as 别名]

#.........这里部分代码省略.........
        f=open("BGP_avg_power_"+ self.get_log_title(), "a")
        
        print "Length: ", len(spec) 
        for item in spec:
            print >> f, "unixtime", item["unixtime"], "power", item["power"], "utilization", item["utilization"]
        f.close()
        return True
    
    def log_info1(self, spec, filename):
        ''' log a certain string into file specified by filename '''
        f=open(filename, "a")

        print >> f, spec
        f.close()
        return True 
    
    def insert_tag(self, tag):
        ''' insert power & util tag into timeline '''
        pos = len(self.time_power_list)
        
        while tag["unixtime"] < self.time_power_list[pos-1].get("unixtime"):
            pos = pos - 1
        
        if tag["unixtime"] == self.time_power_list[pos-1].get("unixtime"):
            pos = pos -1
            
            # compute average power consumption
            power = self.time_power_list[pos].get("power")
            count = self.time_power_list[pos].get("count")
            
            power_avg = (power*count+tag["power"]) / (count+1)
            
            self.time_power_list[pos]["power"] = int(power_avg)
            
            # compute average utilization
            util = self.time_power_list[pos].get("utilization")
            
            util_avg = (util*count+tag["utilization"]) / (count+1)
            
            self.time_power_list[pos]["count"]= count+1
            self.time_power_list[pos]["utilization"] = util_avg
             
        else:    
            self.time_power_list.insert(pos, {"unixtime":tag["unixtime"], "power":tag["power"],"count":1,"utilization":tag["utilization"]})
        
        return pos
    
    def get_current_price_level(self):
        ''' return price level '''
        time = self.event_manager.get_current_time()
        tmp = datetime.fromtimestamp(time)
        fmtdate = int(tmp.strftime("%H"))
        #print tmp, "    ",fmtdate
        if fmtdate >= 9 and fmtdate <=23:
            return HIGH_PRICE
        else:
            return LOW_PRICE     
    get_current_price_level = exposed(get_current_price_level)
        
    
    def monitor_power(self):
        ''' log current system running information including power '''
        time = self.event_manager.get_current_time()
        total_power = self.bqsim.get_running_job_power_usage()
        price = self.get_current_price_level()
        utilization = self.bqsim.get_utilization_rate()
        queue_length = self.bqsim.get_waiting()
          
        ''' accumulate the total energy cost '''
        self.total_cost += total_power * (time - self.event_manager.get_last_schedule_time()) * price
        
        tmp = datetime.fromtimestamp(time)
        fmtdate_hour = int(tmp.strftime("%H"))
        fmtdate_min = int(tmp.strftime("%M"))
        fmtdate_sec = int(tmp.strftime("%S"))
        
        fmttime = 60*fmtdate_hour + fmtdate_min
        
        tag ={}
        tag["unixtime"]= fmttime
        tag["power"] = total_power
        tag["utilization"] = utilization
        
        self.insert_tag(tag)
        
        time_tag = sec_to_date(time)
        if (self.bqsim.is_power_aware()):
            self.log_info1("%s total_power %.5f jobs %d utilization %.5f waiting %d" % (time_tag, total_power, self.bqsim.get_running_job_number(), utilization, queue_length), "power_log_"+self.get_log_title())
        else:
            self.log_info1("%s total_power %.5f jobs %d utilization %.5f waiting %d " % (time_tag, total_power, self.bqsim.get_running_job_number(), utilization, queue_length),"power_log_"+self.get_log_title())

    
    def get_cost(self):
        ''' get total energy cost '''
        return self.total_cost/10000000
    
    
    def log_power_consumption(self):
        ''' log the power information based on the timeline '''
        return self.log_avg_info(self.time_power_list)
开发者ID:zzhou,项目名称:Qsim_PowerAware,代码行数:104,代码来源:pwmonitor.py


注:本文中的Cobalt.Proxy.ComponentProxy.get_running_job_number方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。