<commit_before>from __future__ import absolute_import
import sys
import cProfile
import profile


__all__ = [
    'PythonCProfiler',
]

class PythonCProfiler(cProfile.Profile):
    """ The normal python cProfiler adapted to work with the pikos Monitor class.
    """
    def __init__(self, *args, **kwrds):
        super(PythonCProfiler, self).__init__(*args, **kwrds)
        self._run_count = 0

    def __enter__(self):
        self._run_count += 1
        if self._run_count == 1:
            self.enable()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self._run_count -= 1
        if self._run_count == 0:
            self.disable()
<commit_msg>use the KeepTrack in the context manager<commit_after>from __future__ import absolute_import
import sys
import cProfile

from pikos._internal.keep_track import KeepTrack

__all__ = [
    'PythonCProfiler',
]

class PythonCProfiler(cProfile.Profile):
    """ The normal python cProfiler adapted to work with the pikos Monitor class.


    """
    def __init__(self, *args, **kwrds):
        super(PythonCProfiler, self).__init__(*args, **kwrds)
        self._call_tracker = KeepTrack()

    def __enter__(self):
        if self._call_tracker('ping'):
            self.enable()

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self._call_tracker('pong'):
            self.disable()

{'fraction_non_alphanumeric': 0.10309278350515463, 'fraction_numerical': 0.003681885125184094, 'mean_word_length': 3.044642857142857, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2957532', 'n_tokens_mistral': 438, 'n_tokens_neox': 429, 'n_words': 110}