# Path: gtimer/private/focus.py
# def create_next_timer(*args, **kwargs):
# def remove_last_timer():
# def create_next_loop(*args, **kwargs):
# def remove_last_loop():
# def refresh_shortcuts():
# def hard_reset():
# def get_current_timer():
# 
# Path: gtimer/private/loop.py
# def enter_loop(name=None,
#                rgstr_stamps=None,
#                save_itrs=True,
#                keep_subdivisions=True):
# def loop_start():
# def loop_end(loop_end_stamp=None,
#              end_stamp_unique=True,
#              keep_subdivisions=True,
#              quick_print=False):
# def exit_loop():
# def _subdivide_named_loop(name, rgstr_stamps, save_itrs):
# def _end_subdivision_named_loop():
# 
# Path: gtimer/public/timer.py
# SET = {'SI': True,  # save iterations
#        'KS': True,  # keep subdivisions
#        'QP': False,  # quick print
#        'UN': True,  # unique (stamp name)
#        }
#     SET['SI'] = setting
#     SET['KS'] = setting
#     SET['QP'] = setting
#     SET['UN'] = setting
# def start(backdate=None):
# def stamp(name, backdate=None,
#           unique=None, keep_subdivisions=None, quick_print=None,
#           un=None, ks=None, qp=None):
# def stop(name=None, backdate=None,
#          unique=None, keep_subdivisions=None, quick_print=None,
#          un=None, ks=None, qp=None):
# def pause():
# def resume():
# def blank_stamp(name=None, backdate=None,
#                 unique=None, keep_subdivisions=False, quick_print=None,
#                 un=None, ks=False, qp=None):
# def reset():
# def current_time():
# def wrap(func, subdivide=True, name=None, rgstr_stamps=None, save_itrs=None):
#         def gtimer_wrapped(*args, **kwargs):
#         def gtimer_wrapped(*args, **kwargs):
# def subdivide(name, rgstr_stamps=None, save_itrs=SET['SI']):
# def end_subdivision():
# def rename_root(name):
# def set_save_itrs_root(setting):
# def rgstr_stamps_root(rgstr_stamps):
# def reset_root():
# def is_timer_stopped():
# def is_timer_paused():
# def has_subdvsn_awaiting():
# def has_par_subdvsn_awaiting():
# def get_active_lineage():
# def set_def_save_itrs(setting):
# def set_def_keep_subdivisions(setting):
# def set_def_quick_print(setting):
# def set_def_unique(setting):
# def clear_subdvsn_awaiting():
# def clear_par_subdvsn_awaiting():
# def _stamp(name, elapsed, unique, keep_subdivisions, quick_print):
# def _loop_stamp(name, elapsed, unique=True):
# def _init_loop_stamp(name, unique=True, do_lp=True):
# def _auto_subdivide(name, rgstr_stamps=None, save_itrs=True):
# def _close_subdivision():
# def _end_auto_subdivision():


import copy
from gtimer.private import focus as f
from gtimer.private import loop
from gtimer.public import timer as timer_pub
from __future__ import absolute_import



def collapse_times():
    """Make copies of everything, assign to global shortcuts so functions work
    on them, extract the times, then restore the running stacks.
    """
    orig_ts = f.timer_stack
    orig_ls = f.loop_stack
    copy_ts = _copy_timer_stack()
    copy_ls = copy.deepcopy(f.loop_stack)
    f.timer_stack = copy_ts
    f.loop_stack = copy_ls
    f.refresh_shortcuts()
    while (len(f.timer_stack) > 1) or f.t.in_loop:
        _collapse_subdivision()
    timer_pub.stop()
    collapsed_times = f.r
    f.timer_stack = orig_ts  # (loops throw error if not same object!)
    f.loop_stack = orig_ls
    f.refresh_shortcuts()
    return collapsed_times


def _collapse_subdivision():
    if f.t.in_loop:
        loop.loop_end(end_stamp_unique=False)
        loop.exit_loop()
    else:

# Path: gtimer/private/focus.py
# def create_next_timer(*args, **kwargs):
# def remove_last_timer():
# def create_next_loop(*args, **kwargs):
# def remove_last_loop():
# def refresh_shortcuts():
# def hard_reset():
# def get_current_timer():
# 
# Path: gtimer/private/loop.py
# def enter_loop(name=None,
#                rgstr_stamps=None,
#                save_itrs=True,
#                keep_subdivisions=True):
# def loop_start():
# def loop_end(loop_end_stamp=None,
#              end_stamp_unique=True,
#              keep_subdivisions=True,
#              quick_print=False):
# def exit_loop():
# def _subdivide_named_loop(name, rgstr_stamps, save_itrs):
# def _end_subdivision_named_loop():
# 
# Path: gtimer/public/timer.py
# SET = {'SI': True,  # save iterations
#        'KS': True,  # keep subdivisions
#        'QP': False,  # quick print
#        'UN': True,  # unique (stamp name)
#        }
#     SET['SI'] = setting
#     SET['KS'] = setting
#     SET['QP'] = setting
#     SET['UN'] = setting
# def start(backdate=None):
# def stamp(name, backdate=None,
#           unique=None, keep_subdivisions=None, quick_print=None,
#           un=None, ks=None, qp=None):
# def stop(name=None, backdate=None,
#          unique=None, keep_subdivisions=None, quick_print=None,
#          un=None, ks=None, qp=None):
# def pause():
# def resume():
# def blank_stamp(name=None, backdate=None,
#                 unique=None, keep_subdivisions=False, quick_print=None,
#                 un=None, ks=False, qp=None):
# def reset():
# def current_time():
# def wrap(func, subdivide=True, name=None, rgstr_stamps=None, save_itrs=None):
#         def gtimer_wrapped(*args, **kwargs):
#         def gtimer_wrapped(*args, **kwargs):
# def subdivide(name, rgstr_stamps=None, save_itrs=SET['SI']):
# def end_subdivision():
# def rename_root(name):
# def set_save_itrs_root(setting):
# def rgstr_stamps_root(rgstr_stamps):
# def reset_root():
# def is_timer_stopped():
# def is_timer_paused():
# def has_subdvsn_awaiting():
# def has_par_subdvsn_awaiting():
# def get_active_lineage():
# def set_def_save_itrs(setting):
# def set_def_keep_subdivisions(setting):
# def set_def_quick_print(setting):
# def set_def_unique(setting):
# def clear_subdvsn_awaiting():
# def clear_par_subdvsn_awaiting():
# def _stamp(name, elapsed, unique, keep_subdivisions, quick_print):
# def _loop_stamp(name, elapsed, unique=True):
# def _init_loop_stamp(name, unique=True, do_lp=True):
# def _auto_subdivide(name, rgstr_stamps=None, save_itrs=True):
# def _close_subdivision():
# def _end_auto_subdivision():


# Path: gtimer/private/collapse.py
import copy
from gtimer.private import focus as f
from gtimer.private import loop
from gtimer.public import timer as timer_pub

from __future__ import absolute_import



def collapse_times():
    """Make copies of everything, assign to global shortcuts so functions work
    on them, extract the times, then restore the running stacks.
    """
    orig_ts = f.timer_stack
    orig_ls = f.loop_stack
    copy_ts = _copy_timer_stack()
    copy_ls = copy.deepcopy(f.loop_stack)
    f.timer_stack = copy_ts
    f.loop_stack = copy_ls
    f.refresh_shortcuts()
    while (len(f.timer_stack) > 1) or f.t.in_loop:
        _collapse_subdivision()
    timer_pub.stop()
    collapsed_times = f.r
    f.timer_stack = orig_ts  # (loops throw error if not same object!)
    f.loop_stack = orig_ls
    f.refresh_shortcuts()
    return collapsed_times


def _collapse_subdivision():
    if f.t.in_loop:
        loop.loop_end(end_stamp_unique=False)
        loop.exit_loop()
    else:

        timer_pub.stop()