<commit_before># Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# coding: utf-8
# pylint: disable=fixme, invalid-name, too-many-arguments, too-many-locals, too-many-lines
# pylint: disable=too-many-branches, too-many-statements
"""Profiler setting methods."""
from __future__ import absolute_import
import ctypes
import warnings
from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array, py_str


def set_config(**kwargs):
    """Set up the configure of profiler (only accepts keyword arguments).

    Parameters
    ----------
    filename : string,
        output file for profile data
    profile_all : boolean,
        all profile types enabled
    profile_symbolic : boolean,
        whether to profile symbolic operators
    profile_imperative : boolean,
        whether to profile imperative operators
    profile_memory : boolean,
        whether to profile memory usage
    profile_api : boolean,
        whether to profile the C API
    contiguous_dump : boolean,
        whether to periodically dump profiling data to file
    dump_period : float,
        seconds between profile data dumps
    aggregate_stats : boolean,
        whether to maintain aggregate stats in memory for console
        dump.  Has some negative performance impact.
    """
    kk = kwargs.keys()
    vv = kwargs.values()
    check_call(_LIB.MXSetProfilerConfig(len(kwargs),
                                        c_str_array([key for key in kk]),
                                        c_str_array([str(val) for val in vv])))


def profiler_set_config(mode='symbolic', filename='profile.json'):
    """Set up the configure of profiler.

    Parameters
    ----------
    mode : string, optional
        Indicates whether to enable the profiler, can
        be 'symbolic', or 'all'. Defaults to `symbolic`.
    filename : string, optional
        The name of output trace file. Defaults to 'profile.json'.
    """
    warnings.warn('profiler.profiler_set_config() is deprecated. ' \
                  'Please use profiler.set_config() instead')
    keys = c_str_array([key for key in ["profile_" + mode, "filename"]])
    values = c_str_array([str(val) for val in [True, filename]])
    assert len(keys) == len(values)
    check_call(_LIB.MXSetProfilerConfig(len(keys), keys, values))


def set_state(state='stop'):
    """Set up the profiler state to 'run' or 'stop'.

    Parameters
    ----------
    state : string, optional
        Indicates whether to run the profiler, can
        be 'stop' or 'run'. Default is `stop`.
    """
    state2int = {'stop': 0, 'run': 1}
    check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))


def dump(finished=True):
    """Dump profile and stop profiler. Use this to save profile
    in advance in case your program cannot exit normally.

    Parameters
    ----------
    finished : boolean
        Indicates whether to stop statistic output (dumping) after this dump.
        Default is True
    """
    fin = 1 if finished is True else False
    check_call(_LIB.MXDumpProfile(fin))


def dump_profile():
    """Dump profile and stop profiler. Use this to save profile
    in advance in case your program cannot exit normally."""
    warnings.warn('profiler.dump_profile() is deprecated. ' \
                  'Please use profiler.dump() instead')
    dump(True)


def dumps(reset=False):
    """Return a printable string of aggregate profile stats.

    Parameters
    ----------
    reset: boolean
        Indicates whether to clean aggeregate statistical data collected up to this point
    """
    debug_str = ctypes.c_char_p()
    do_reset = 1 if reset is True else 0
    check_call(_LIB.MXAggregateProfileStatsPrint(ctypes.byref(debug_str), int(do_reset)))
    return py_str(debug_str.value)
<commit_msg>add deprecated profiler_set_state() (#10156)<commit_after># Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# coding: utf-8
# pylint: disable=fixme, invalid-name, too-many-arguments, too-many-locals, too-many-lines
# pylint: disable=too-many-branches, too-many-statements
"""Profiler setting methods."""
from __future__ import absolute_import
import ctypes
import warnings
from .base import _LIB, check_call, c_str, ProfileHandle, c_str_array, py_str


def set_config(**kwargs):
    """Set up the configure of profiler (only accepts keyword arguments).

    Parameters
    ----------
    filename : string,
        output file for profile data
    profile_all : boolean,
        all profile types enabled
    profile_symbolic : boolean,
        whether to profile symbolic operators
    profile_imperative : boolean,
        whether to profile imperative operators
    profile_memory : boolean,
        whether to profile memory usage
    profile_api : boolean,
        whether to profile the C API
    contiguous_dump : boolean,
        whether to periodically dump profiling data to file
    dump_period : float,
        seconds between profile data dumps
    aggregate_stats : boolean,
        whether to maintain aggregate stats in memory for console
        dump.  Has some negative performance impact.
    """
    kk = kwargs.keys()
    vv = kwargs.values()
    check_call(_LIB.MXSetProfilerConfig(len(kwargs),
                                        c_str_array([key for key in kk]),
                                        c_str_array([str(val) for val in vv])))


def profiler_set_config(mode='symbolic', filename='profile.json'):
    """Set up the configure of profiler (Deprecated).

    Parameters
    ----------
    mode : string, optional
        Indicates whether to enable the profiler, can
        be 'symbolic', or 'all'. Defaults to `symbolic`.
    filename : string, optional
        The name of output trace file. Defaults to 'profile.json'.
    """
    warnings.warn('profiler.profiler_set_config() is deprecated. '
                  'Please use profiler.set_config() instead')
    keys = c_str_array([key for key in ["profile_" + mode, "filename"]])
    values = c_str_array([str(val) for val in [True, filename]])
    assert len(keys) == len(values)
    check_call(_LIB.MXSetProfilerConfig(len(keys), keys, values))


def set_state(state='stop'):
    """Set up the profiler state to 'run' or 'stop'.

    Parameters
    ----------
    state : string, optional
        Indicates whether to run the profiler, can
        be 'stop' or 'run'. Default is `stop`.
    """
    state2int = {'stop': 0, 'run': 1}
    check_call(_LIB.MXSetProfilerState(ctypes.c_int(state2int[state])))


def profiler_set_state(state='stop'):
    """Set up the profiler state to 'run' or 'stop' (Deprecated).

    Parameters
    ----------
    state : string, optional
        Indicates whether to run the profiler, can
        be 'stop' or 'run'. Default is `stop`.
    """
    warnings.warn('profiler.profiler_set_state() is deprecated. '
                  'Please use profiler.set_state() instead')
    set_state(state)

def dump(finished=True):
    """Dump profile and stop profiler. Use this to save profile
    in advance in case your program cannot exit normally.

    Parameters
    ----------
    finished : boolean
        Indicates whether to stop statistic output (dumping) after this dump.
        Default is True
    """
    fin = 1 if finished is True else False
    check_call(_LIB.MXDumpProfile(fin))


def dump_profile():
    """Dump profile and stop profiler. Use this to save profile
    in advance in case your program cannot exit normally."""
    warnings.warn('profiler.dump_profile() is deprecated. '
                  'Please use profiler.dump() instead')
    dump(True)


def dumps(reset=False):
    """Return a printable string of aggregate profile stats.

    Parameters
    ----------
    reset: boolean
        Indicates whether to clean aggeregate statistical data collected up to this point
    """
    debug_str = ctypes.c_char_p()
    do_reset = 1 if reset is True else 0
    check_call(_LIB.MXAggregateProfileStatsPrint(ctypes.byref(debug_str), int(do_reset)))
    return py_str(debug_str.value)

{'fraction_non_alphanumeric': 0.09409652550427712, 'fraction_numerical': 0.0030626254092301192, 'mean_word_length': 2.9327242524916945, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3677607', 'n_tokens_mistral': 2580, 'n_tokens_neox': 2547, 'n_words': 974}