<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def enable_global_typechecked_profiler(flag = True):
 """Enables or disables global typechecking mode via a profiler. See flag global_typechecked_profiler. Does not work if checking_enabled is false. """

    global global_typechecked_profiler, _global_type_agent, global_typelogged_profiler
    global_typechecked_profiler = flag
    if flag and checking_enabled:
        if _global_type_agent is None:
            _global_type_agent = TypeAgent()
            _global_type_agent.start()
        elif not _global_type_agent.active:
            _global_type_agent.start()
    elif not flag and not global_typelogged_profiler and \
            not _global_type_agent is None and _global_type_agent.active:
        _global_type_agent.stop()