<commit_before># Copyright (c) 2016 Intracom S.A. Telecom Solutions. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this distribution,
# and is available at http://www.eclipse.org/legal/epl-v10.html

""" Controller Class- All controller-related functionality is here"""

import gevent.queue
import json
import logging
import re
import queue
import subprocess
import time
import util.sysstats


class Monitor:

    def __init__(self, controller):
        """Create a Monitor. Options from JSON input file
        :param nb_gen_base_dir: emulator base directory
        :param controller: object of the Controller class
        :param sbemu: object of the SBEmu subclass
        :type nb_gen_base_dir: str
        :type controller: object
        :type sbemu: object
        """
        print("create a MONITOR object")
        self.controller = controller
        self.global_sample_id = 0
        self.repeat_id = 0

    def system_results(self):
        """ Collect runtime statistics
        :returns: experiment statistics in dictionary
        :rtype: dict
        """

        system_statistics = {}
        system_statistics['total_memory_bytes'] = \
            util.sysstats.sys_total_memory_bytes(self.controller.ssh_client)
        system_statistics['controller_cwd'] = \
            util.sysstats.proc_cwd(self.controller.cpid,
                                   self.controller.ssh_client)
        system_statistics['controller_java_xopts'] = \
            util.sysstats.get_java_options(self.controller.cpid,
                                           self.controller.ssh_client)
        system_statistics['timestamp'] = \
            int(subprocess.check_output('date +%s',
                                        shell=True,
                                        universal_newlines=True).strip())
        system_statistics['date'] = \
            subprocess.check_output('date',
                                    shell=True,
                                    universal_newlines=True).strip()
        system_statistics['used_memory_bytes'] = \
            util.sysstats.sys_used_memory_bytes(self.controller.ssh_client)
        system_statistics['free_memory_bytes'] = \
            util.sysstats.sys_free_memory_bytes(self.controller.ssh_client)
        system_statistics['controller_cpu_system_time'] = \
            util.sysstats.proc_cpu_system_time(self.controller.cpid,
                                               self.controller.ssh_client)
        system_statistics['controller_cpu_user_time'] = \
            util.sysstats.proc_cpu_user_time(self.controller.cpid,
                                             self.controller.ssh_client)
        system_statistics['controller_vm_size'] = \
            util.sysstats.proc_vm_size(self.controller.cpid,
                                       self.controller.ssh_client)
        system_statistics['controller_num_fds'] = \
            util.sysstats.proc_num_fds(self.controller.cpid,
                                       self.controller.ssh_client)
        system_statistics['controller_num_threads'] = \
            util.sysstats.proc_num_threads(self.controller.cpid,
                                           self.controller.ssh_client)
        system_statistics['one_minute_load'] = \
            util.sysstats.sys_load_average(self.controller.ssh_client)[0]
        system_statistics['five_minute_load'] = \
            util.sysstats.sys_load_average(self.controller.ssh_client)[1]
        system_statistics['fifteen_minute_load'] = \
            util.sysstats.sys_load_average(self.controller.ssh_client)[2]
        return system_statistics


class Oftraf:

    def __init__(self, controller, oftraf):
        print("create an OFTRAF MONITOR object")<commit_msg>Fix controller attributes (_ssh_conn instead of ssh_client)<commit_after># Copyright (c) 2016 Intracom S.A. Telecom Solutions. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this distribution,
# and is available at http://www.eclipse.org/legal/epl-v10.html

""" Controller Class- All controller-related functionality is here"""

import gevent.queue
import json
import logging
import re
import queue
import subprocess
import time
import util.sysstats


class Monitor:

    def __init__(self, controller):
        """Create a Monitor. Options from JSON input file
        :param nb_gen_base_dir: emulator base directory
        :param controller: object of the Controller class
        :param sbemu: object of the SBEmu subclass
        :type nb_gen_base_dir: str
        :type controller: object
        :type sbemu: object
        """
        print("create a MONITOR object")
        self.controller = controller
        self.global_sample_id = 0
        self.repeat_id = 0

    def system_results(self):
        """ Collect runtime statistics
        :returns: experiment statistics in dictionary
        :rtype: dict
        """

        system_statistics = {}
        system_statistics['total_memory_bytes'] = \
            util.sysstats.sys_total_memory_bytes(self.controller._ssh_conn)
        system_statistics['controller_cwd'] = \
            util.sysstats.proc_cwd(self.controller.cpid,
                                   self.controller._ssh_conn)
        system_statistics['controller_java_xopts'] = \
            util.sysstats.get_java_options(self.controller.cpid,
                                           self.controller._ssh_conn)
        system_statistics['timestamp'] = \
            int(subprocess.check_output('date +%s',
                                        shell=True,
                                        universal_newlines=True).strip())
        system_statistics['date'] = \
            subprocess.check_output('date',
                                    shell=True,
                                    universal_newlines=True).strip()
        system_statistics['used_memory_bytes'] = \
            util.sysstats.sys_used_memory_bytes(self.controller._ssh_conn)
        system_statistics['free_memory_bytes'] = \
            util.sysstats.sys_free_memory_bytes(self.controller._ssh_conn)
        system_statistics['controller_cpu_system_time'] = \
            util.sysstats.proc_cpu_system_time(self.controller.cpid,
                                               self.controller._ssh_conn)
        system_statistics['controller_cpu_user_time'] = \
            util.sysstats.proc_cpu_user_time(self.controller.cpid,
                                             self.controller._ssh_conn)
        system_statistics['controller_vm_size'] = \
            util.sysstats.proc_vm_size(self.controller.cpid,
                                       self.controller._ssh_conn)
        system_statistics['controller_num_fds'] = \
            util.sysstats.proc_num_fds(self.controller.cpid,
                                       self.controller._ssh_conn)
        system_statistics['controller_num_threads'] = \
            util.sysstats.proc_num_threads(self.controller.cpid,
                                           self.controller._ssh_conn)
        system_statistics['one_minute_load'] = \
            util.sysstats.sys_load_average(self.controller._ssh_conn)[0]
        system_statistics['five_minute_load'] = \
            util.sysstats.sys_load_average(self.controller._ssh_conn)[1]
        system_statistics['fifteen_minute_load'] = \
            util.sysstats.sys_load_average(self.controller._ssh_conn)[2]
        return system_statistics


class Oftraf:

    def __init__(self, controller, oftraf):
        print("create an OFTRAF MONITOR object")
{'fraction_non_alphanumeric': 0.08226950354609928, 'fraction_numerical': 0.003352675693101225, 'mean_word_length': 2.106127352823388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '80274', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1987, 'n_words': 365}