# Path: opendiamond/protocol.py
# class XDR_search_stats(XDRStruct):
#     '''Search statistics'''
#     members = (
#         'stats', XDR.array(XDR.struct(XDR_stat)),
#         'filter_stats', XDR.optional(XDR.array(XDR.struct(XDR_filter_stats))),
#     )
# 
# class XDR_filter_stats(XDRStruct):
#     '''Filter statistics'''
#     members = (
#         'name', XDR.string(),
#         'stats', XDR.array(XDR.struct(XDR_stat)),
#     )
# 
# class XDR_stat(XDRStruct):
#     '''Statistics key-value pair'''
#     members = (
#         "name", XDR.string(),
#         "value", XDR.hyper(),
#     )


from past.utils import old_div
from builtins import object
from opendiamond.protocol import XDR_search_stats, XDR_filter_stats, XDR_stat
import logging
import multiprocessing as mp
import threading
import time
    '''Statistics for the execution of a single filter.'''

    attrs = (('objs_processed', 'Total objects considered'),
             ('objs_dropped', 'Total objects dropped'),
             ('objs_true_positive', 'Objects passed with label'),
             ('objs_false_negative', 'Objects dropped with label'),
             ('objs_cache_dropped', 'Objects dropped by cache'),
             ('objs_cache_passed', 'Objects skipped by cache'),
             ('objs_computed', 'Objects examined by filter'),
             ('objs_terminate', 'Objects causing filter to terminate'),
             ('execution_us', 'Filter execution time (us)'),
             )

    def __init__(self, name):
        super(FilterStatistics, self).__init__()
        self.name = name
        self.label = 'Filter statistics for %s' % name

    def xdr(self):
        '''Return an XDR statistics structure for these statistics.'''
        with self.lock:
            try:
                avg_exec_us = old_div(self.execution_us, self.objs_processed)
            except ZeroDivisionError:
                avg_exec_us = 0

            stats = []
            stats.append(XDR_stat('avg_exec_time_us', avg_exec_us))
            for name, _desc in self.attrs:
                if name != 'execution_us':

# Path: opendiamond/protocol.py
# class XDR_search_stats(XDRStruct):
#     '''Search statistics'''
#     members = (
#         'stats', XDR.array(XDR.struct(XDR_stat)),
#         'filter_stats', XDR.optional(XDR.array(XDR.struct(XDR_filter_stats))),
#     )
# 
# class XDR_filter_stats(XDRStruct):
#     '''Filter statistics'''
#     members = (
#         'name', XDR.string(),
#         'stats', XDR.array(XDR.struct(XDR_stat)),
#     )
# 
# class XDR_stat(XDRStruct):
#     '''Statistics key-value pair'''
#     members = (
#         "name", XDR.string(),
#         "value", XDR.hyper(),
#     )


# Path: opendiamond/server/statistics.py
from past.utils import old_div
from builtins import object
from opendiamond.protocol import XDR_search_stats, XDR_filter_stats, XDR_stat
import logging
import multiprocessing as mp
import threading
import time

    '''Statistics for the execution of a single filter.'''

    attrs = (('objs_processed', 'Total objects considered'),
             ('objs_dropped', 'Total objects dropped'),
             ('objs_true_positive', 'Objects passed with label'),
             ('objs_false_negative', 'Objects dropped with label'),
             ('objs_cache_dropped', 'Objects dropped by cache'),
             ('objs_cache_passed', 'Objects skipped by cache'),
             ('objs_computed', 'Objects examined by filter'),
             ('objs_terminate', 'Objects causing filter to terminate'),
             ('execution_us', 'Filter execution time (us)'),
             )

    def __init__(self, name):
        super(FilterStatistics, self).__init__()
        self.name = name
        self.label = 'Filter statistics for %s' % name

    def xdr(self):
        '''Return an XDR statistics structure for these statistics.'''
        with self.lock:
            try:
                avg_exec_us = old_div(self.execution_us, self.objs_processed)
            except ZeroDivisionError:
                avg_exec_us = 0

            stats = []
            stats.append(XDR_stat('avg_exec_time_us', avg_exec_us))
            for name, _desc in self.attrs:
                if name != 'execution_us':

                    stats.append(XDR_stat(name, getattr(self, name)))