本文整理汇总了Python中bzt.utils.FileReader.get_line方法的典型用法代码示例。如果您正苦于以下问题:Python FileReader.get_line方法的具体用法?Python FileReader.get_line怎么用?Python FileReader.get_line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bzt.utils.FileReader
的用法示例。
在下文中一共展示了FileReader.get_line方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scheduler
# 需要导入模块: from bzt.utils import FileReader [as 别名]
# 或者: from bzt.utils.FileReader import get_line [as 别名]
class Scheduler(object):
REC_TYPE_SCHEDULE = 0
REC_TYPE_LOOP_START = 1
REC_TYPE_STOP = 2
def __init__(self, load, payload_filename, parent_logger):
super(Scheduler, self).__init__()
self.need_start_loop = None
self.log = parent_logger.getChild(self.__class__.__name__)
self.load = load
self.payload_file = FileReader(filename=payload_filename, parent_logger=self.log)
if not load.duration and not load.iterations:
self.iteration_limit = 1
else:
self.iteration_limit = load.iterations
self.concurrency = load.concurrency if load.concurrency is not None else 1
self.step_len = load.ramp_up / load.steps if load.steps and load.ramp_up else 0
if load.throughput:
self.ramp_up_slope = load.throughput / load.ramp_up if load.ramp_up else 0
self.step_size = float(load.throughput) / load.steps if load.steps else 0
else:
self.ramp_up_slope = None
self.step_size = float(self.concurrency) / load.steps if load.steps else 0
self.count = 0.0
self.time_offset = 0.0
self.iterations = 0
def _payload_reader(self):
self.iterations = 1
rec_type = self.REC_TYPE_SCHEDULE
while True:
payload_offset = self.payload_file.offset
line = self.payload_file.get_line()
if not line: # rewind
self.payload_file.offset = 0
self.iterations += 1
if self.need_start_loop and not self.iteration_limit:
self.need_start_loop = False
self.iteration_limit = self.iterations
rec_type = self.REC_TYPE_LOOP_START
if self.iteration_limit and self.iterations > self.iteration_limit:
self.log.debug("Schedule iterations limit reached: %s", self.iteration_limit)
break
if not line.strip(): # we're fine to skip empty lines between records
continue
parts = line.split(' ')
if len(parts) < 2:
raise TaurusInternalException("Wrong format for meta-info line: %s" % line)
payload_len, marker = parts
payload_len = int(payload_len)
payload = self.payload_file.get_bytes(payload_len)
yield payload_len, payload_offset, payload, marker.strip(), len(line), rec_type
rec_type = self.REC_TYPE_SCHEDULE
def generate(self):
for payload_len, payload_offset, payload, marker, meta_len, record_type in self._payload_reader():
if self.load.throughput:
self.time_offset += self.__get_time_offset_rps()
if self.load.duration and self.time_offset > self.load.duration:
self.log.debug("Duration limit reached: %s", self.time_offset)
break
else: # concurrency schedule
self.time_offset = self.__get_time_offset_concurrency()
overall_len = payload_len + meta_len
yield self.time_offset, payload_len, payload_offset, payload, marker, record_type, overall_len
self.count += 1
def __get_time_offset_concurrency(self):
if not self.load.ramp_up or self.count >= self.concurrency:
if self.need_start_loop is None:
self.need_start_loop = True
return -1 # special case, means no delay
elif self.load.steps:
step = math.floor(self.count / self.step_size)
return step * self.step_len
else: # ramp-up case
return self.count * self.load.ramp_up / self.concurrency
def __get_time_offset_rps(self):
if not self.load.ramp_up or self.time_offset > self.load.ramp_up:
# limit iterations
rps = self.load.throughput
if self.need_start_loop is None:
self.need_start_loop = True
elif self.load.steps:
rps = self.step_size * (math.floor(self.time_offset / self.step_len) + 1)
else: # ramp-up case
xpos = math.sqrt(2 * self.count / self.ramp_up_slope)
rps = xpos * self.ramp_up_slope
return 1.0 / rps if rps else 0