Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added __init__.py
Empty file.
16 changes: 8 additions & 8 deletions redis-faina.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _record_duration(self, entry):
self.last_ts = ts

def _record_command(self, entry):
self.commands[entry['command']] += 1
self.commands[entry['command'].upper()] += 1

def _record_key(self, key):
self.keys[key] += 1
Expand Down Expand Up @@ -76,10 +76,10 @@ def _get_or_sort_list(self, ls):
def _time_stats(self, times):
sorted_times = self._get_or_sort_list(times)
num_times = len(sorted_times)
percent_50 = sorted_times[int(num_times / 2)][0]
percent_75 = sorted_times[int(num_times * .75)][0]
percent_90 = sorted_times[int(num_times * .90)][0]
percent_99 = sorted_times[int(num_times * .99)][0]
percent_50 = sorted_times[int(num_times / 2)][0] if num_times else 0
percent_75 = sorted_times[int(num_times * .75)][0] if num_times else 0
percent_90 = sorted_times[int(num_times * .90)][0] if num_times else 0
percent_99 = sorted_times[int(num_times * .99)][0] if num_times else 0
return (("Median", percent_50),
("75%", percent_75),
("90%", percent_90),
Expand All @@ -88,7 +88,7 @@ def _time_stats(self, times):
def _heaviest_commands(self, times):
times_by_command = defaultdict(int)
for time, entry in times:
times_by_command[entry['command']] += time
times_by_command[entry['command'].upper()] += time
return self._top_n(times_by_command)

def _slowest_commands(self, times, n=8):
Expand All @@ -99,10 +99,10 @@ def _slowest_commands(self, times, n=8):
return printable_commands

def _general_stats(self):
total_time = (self.last_ts - self.start_ts) / (1000*1000)
total_time = (self.last_ts - self.start_ts) / (1000*1000) if self.last_ts and self.start_ts else 0
return (
("Lines Processed", self.line_count),
("Commands/Sec", '%.2f' % (self.line_count / total_time))
("Commands/Sec", '%.2f' % (self.line_count / total_time if total_time else 0))
)

def process_entry(self, entry):
Expand Down