<commit_before>import time
import logging
from multiprocessing import Process
import psutil
from cmreslogging.handlers import CMRESHandler

simple = ["cpu_num", 'cpu_percent', 'create_time', 'cwd', 'exe', 'memory_percent', 'nice', 'name', 'num_threads', 'pid', 'ppid', 'status', 'username']


def monitor(p):
    p.start()
    pm = psutil.Process(p.pid)
    pm.cpu_percent()
    while p.is_alive():
        d = {"psutil_process_" + str(k): v for k, v in pm.as_dict().items() if k in simple}
        d["psutil_cpu"] = psutil.cpu_count()
        logger.info("test", extra=d)
        time.sleep(1)
    print("done")


if __name__ == "__main__":
    host = 'search-parsl-logging-test-2yjkk2wuoxukk2wdpiicl7mcrm.us-east-1.es.amazonaws.com'
    port = 443
    index_name = "parsl.campaign"

    handler = CMRESHandler(hosts=[{'host': host,
                                   'port': port}],
                           use_ssl=True,
                           auth_type=CMRESHandler.AuthType.NO_AUTH,
                           es_index_name="my_python_index",
                           es_additional_fields={'Campaign': "test", 'Username': "yadu"})

    logger = logging.getLogger("ParslElasticsearch")
    logger.setLevel(logging.INFO)
    logger.addHandler(handler)

    def f(x):
        for i in range(10**x):
            continue

    t = Process(target=f, args=(9,))
    monitor(t)<commit_msg>Made wrapper for monitoring.<commit_after>import time
import logging
from multiprocessing import Process
import psutil
from cmreslogging.handlers import CMRESHandler

simple = ["cpu_num", 'cpu_percent', 'create_time', 'cwd', 'exe', 'memory_percent', 'nice', 'name', 'num_threads', 'pid', 'ppid', 'status', 'username']


def monitor(p):
    host = 'search-parsl-logging-test-2yjkk2wuoxukk2wdpiicl7mcrm.us-east-1.es.amazonaws.com'
    port = 443
    handler = CMRESHandler(hosts=[{'host': host,
                                   'port': port}],
                           use_ssl=True,
                           auth_type=CMRESHandler.AuthType.NO_AUTH,
                           es_index_name="my_python_index",
                           es_additional_fields={'Campaign': "test", 'Username': "yadu"})

    logger = logging.getLogger("ParslElasticsearch")
    logger.setLevel(logging.INFO)
    logger.addHandler(handler)

    p.start()
    pm = psutil.Process(p.pid)
    pm.cpu_percent()
    while p.is_alive():
        d = {"psutil_process_" + str(k): v for k, v in pm.as_dict().items() if k in simple}
        d["psutil_cpu"] = psutil.cpu_count()
        logger.info("test", extra=d)
        time.sleep(1)
    return p.result()


def monitor_wrapper(f):
    def wrapped(*args, **kwargs):
        p = Process(target=f, args=args, kwargs=kwargs)
        return monitor(p)
    return wrapped


if __name__ == "__main__":
    def f(x):
        for i in range(10**x):
            continue

    wrapped_f = monitor_wrapper(f)
    wrapped_f(9)
{'fraction_non_alphanumeric': 0.13706102966246164, 'fraction_numerical': 0.008182748039549948, 'mean_word_length': 2.556363636363636, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7651949', 'n_tokens_mistral': 972, 'n_tokens_neox': 953, 'n_words': 195}