Skip to content

Commit

Permalink
rueckstiess#710 - Log Reaped Cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
savinay-vijay committed Jul 8, 2019
1 parent 5035426 commit ef7b166
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 2 deletions.
1 change: 1 addition & 0 deletions mtools/mloginfo/sections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .query_section import QuerySection
from .rs_state_section import RsStateSection
from .rs_info_section import RsInfoSection
from .cursor_section import CursorSection
88 changes: 88 additions & 0 deletions mtools/mloginfo/sections/cursor_section.py
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('')
Loading

0 comments on commit ef7b166

Please sign in to comment.