forked from rueckstiess/mtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5035426
commit ef7b166
Showing
5 changed files
with
250 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import re | ||
from collections import namedtuple | ||
from mtools.util import OrderedDict | ||
from mtools.util.grouping import Grouping | ||
from mtools.util.print_table import print_table | ||
from .base_section import BaseSection | ||
|
||
from collections import namedtuple | ||
from operator import itemgetter | ||
|
||
from .base_section import BaseSection | ||
from mtools.util import OrderedDict | ||
from mtools.util.grouping import Grouping | ||
from mtools.util.print_table import print_table | ||
|
||
|
||
try: | ||
import numpy as np | ||
except ImportError: | ||
np = None | ||
|
||
LogTuple = namedtuple('LogTuple', ['datetime', 'cursorid', 'reapedtime']) | ||
|
||
|
||
def op_or_cmd(le): | ||
return le.operation if le.operation != 'command' else le.command | ||
|
||
|
||
class CursorSection(BaseSection): | ||
"""CursorSection class.""" | ||
|
||
name = 'cursor' | ||
|
||
def __init__(self, mloginfo): | ||
BaseSection.__init__(self, mloginfo) | ||
helptext = 'outputs statistics about cursor' | ||
self.mloginfo.argparser_sectiongroup.add_argument('--cursor', action='store_true', help=helptext) | ||
|
||
@property | ||
def active(self): | ||
"""Return boolean if this section is active.""" | ||
return self.mloginfo.args['cursor'] | ||
|
||
def run(self): | ||
|
||
"""Run this section and print out information.""" | ||
grouping = Grouping(group_by=lambda x: (x.datetime, x.cursorid, x.reapedtime)) | ||
logfile = self.mloginfo.logfile | ||
|
||
if logfile.start and logfile.end: | ||
progress_start = self.mloginfo._datetime_to_epoch(logfile.start) | ||
progress_total = (self.mloginfo._datetime_to_epoch(logfile.end) - progress_start) | ||
else: | ||
self.mloginfo.progress_bar_enabled = False | ||
|
||
for i, le in enumerate(logfile): | ||
|
||
if (re.search('Cursor id', le.line_str)): | ||
lt = LogTuple(le.datetime, le.cursor, le._reapedtime) | ||
grouping.add(lt) | ||
|
||
grouping.sort_by_size() | ||
|
||
# clear progress bar again | ||
if self.mloginfo.progress_bar_enabled: | ||
self.mloginfo.update_progress(1.0) | ||
|
||
# no cursor information in the log file | ||
if len(grouping) < 1: | ||
print('no cursor information found.') | ||
return | ||
|
||
titles = ['datetime', 'cursorid', 'reapedtime'] | ||
|
||
table_rows = [] | ||
# using only important key-values | ||
for g in grouping: | ||
# calculate statistics for this group | ||
datetime, cursorid, reapedtime = g | ||
stats = OrderedDict() | ||
stats['datetime'] = str(datetime) | ||
stats['cursorid'] = str(cursorid) | ||
stats['reapedtime'] = str(reapedtime) | ||
table_rows.append(stats) | ||
|
||
print_table(table_rows, titles, uppercase_headers=True) | ||
|
||
print('') |
Oops, something went wrong.