def merge_total_time_dict(a, b):
    """Merge two total-time dictionaries by adding the amount of collected time
    in each hierarchical element.

    Parameters
    ----------
    a, b : total-time dict
        A total-time dict is a dictionary with the keys being the name of the
        timer and the value being a pair of a total time number and a
        dictionary further splitting up the time into lower hierarchical
        components.

    Returns
    -------
    total-time dict
    """
    all_keys = set(a).union(set(b))
    total = dict()
    for key in all_keys:
        t_a, d_a = a.get(key, (0, dict()))
        t_b, d_b = b.get(key, (0, dict()))
        total[key] = (t_a + t_b, merge_total_time_dict(d_a, d_b))
    return total