From 137f8957490f11201845fb69a5269e16276ccca0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 20 Feb 2012 08:42:06 -0500 Subject: [PATCH] Use the last time string parsed by LogTimeProcessor to avoid re-parsing. If you have several requests in the same second, the old approach would re-parse the time string for each request. The new approach recognizes that the time has not changed, and uses the last parsed value instead of re-parsing. --- apachelog/processor/time.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apachelog/processor/time.py b/apachelog/processor/time.py index c6c1aae..fb3922f 100644 --- a/apachelog/processor/time.py +++ b/apachelog/processor/time.py @@ -30,13 +30,18 @@ class LogTimeProcessor (_Processor): """ def __init__(self, previous_log_time_processor=None): self.previous_log_time_processor = previous_log_time_processor - self.last_time = self.start_time = self.stop_time = None + self.last_data = self.last_time = None + self.start_time = self.stop_time = None def process(self, data): if self.previous_log_time_processor is None: - time = _parse_time(data['%t']) + if data['%t'] == self.last_data: + time = self.last_time # don't re-parse a repeated value + else: + time = _parse_time(data['%t']) else: # avoid re-parsing the time data time = self.previous_log_time_processor.last_time + self.last_data = data['%t'] self.last_time = time # for use by subclasses or other processors if self.start_time is None or time < self.start_time: self.start_time = time -- 2.26.2