Skip to content

Commit

Permalink
Fix #509: Add mplotqueries --type docsExamined/n (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
stennie authored and kevinadi committed Sep 21, 2017
1 parent 52fedbf commit d4edc99
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mtools/mplotqueries/plottypes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from scatter_type import ScatterPlotType, NScannedNPlotType, DurationLineType
from scatter_type import ScatterPlotType, NScannedNPlotType, DocsExaminedPlotType, DurationLineType
from event_type import EventPlotType, RSStatePlotType
from range_type import RangePlotType
from histogram_type import HistogramPlotType
Expand Down
31 changes: 30 additions & 1 deletion mtools/mplotqueries/plottypes/scatter_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ class NScannedNPlotType(ScatterPlotType):
plot_type_str = 'nscanned/n'
default_group_by = 'namespace'


def __init__(self, args=None, unknown_args=None):
# Only call baseplot type constructor, we don't need argparser
BasePlotType.__init__(self, args, unknown_args)
Expand All @@ -208,5 +207,35 @@ def plot_group(self, group, idx, axis):
return artist


class DocsExaminedPlotType(ScatterPlotType):

plot_type_str = 'docsExamined/n'
default_group_by = 'namespace'

def __init__(self, args=None, unknown_args=None):
# Only call baseplot type constructor, we don't need argparser
BasePlotType.__init__(self, args, unknown_args)

self.ylabel = 'docsExamined / n ratio'

def accept_line(self, logevent):
""" return True if the log line has a duration. """
# For backward compatibility the relevant logevent attribute is currently nscannedObject.
# This will have the value of nscannedObjects or equivalent docsExamined metric.
return getattr(logevent, 'nscannedObjects') and getattr(logevent, 'nreturned')

def plot_group(self, group, idx, axis):
# create x-coordinates for all log lines in this group
x = date2num( [ logevent.datetime for logevent in self.groups[group] ] )

color, marker = self.color_map(group)

y = [ getattr(logevent, 'nscannedObjects') / (float(getattr(logevent, 'nreturned')) if getattr(logevent, 'nreturned') != 0 else 1.0) for logevent in self.groups[group] ]
artist = axis.plot_date(x, y, color=color, marker=marker, alpha=0.8, \
markersize=7, picker=5, label=group)[0]
# add meta-data for picking
artist._mt_plot_type = self
artist._mt_group = group

return artist

0 comments on commit d4edc99

Please sign in to comment.