# Path: pympler/util/stringutils.py
# def trunc(obj: str, max: int, left: bool = False) -> str:
#     """
#     Convert `obj` to string, eliminate newlines and truncate the string to
#     `max` characters. If there are more characters in the string add ``...`` to
#     the string. With `left=True`, the string can be truncated at the beginning.
# 
#     @note: Does not catch exceptions when converting `obj` to string with
#         `str`.
# 
#     >>> trunc('This is a long text.', 8)
#     This ...
#     >>> trunc('This is a long text.', 8, left=True)
#     ...text.
#     """
#     s = str(obj)
#     s = s.replace('\n', '|')
#     if len(s) > max:
#         if left:
#             return '...' + s[len(s) - max + 3:]
#         else:
#             return s[:(max - 3)] + '...'
#     else:
#         return s
# 
# def pp(i: Union[int, float], base: int = 1024) -> str:
#     """
#     Pretty-print the integer `i` as a human-readable size representation.
#     """
#     degree = 0
#     pattern = "%4d     %s"
#     while i > base:
#         pattern = "%7.2f %s"
#         i = i / float(base)
#         degree += 1
#     scales = ['B', 'KB', 'MB', 'GB', 'TB', 'EB']
#     return pattern % (i, scales[degree])
# 
# def pp_timestamp(t: Optional[float]) -> str:
#     """
#     Get a friendly timestamp represented as a string.
#     """
#     if t is None:
#         return ''
#     h, m, s = int(t / 3600), int(t / 60 % 60), t % 60
#     return "%02d:%02d:%05.2f" % (h, m, s)
# 
# Path: pympler/asizeof.py
# class Asized(object):
#     '''Stores the results of an **asized** object in the following
#        4 attributes:
# 
#         *size* -- total size of the object (including referents)
# 
#         *flat* -- flat size of the object (in bytes)
# 
#         *name* -- name or ``repr`` of the object
# 
#         *refs* -- tuple containing an **Asized** instance for each referent
#     '''
#     __slots__ = ('flat', 'name', 'refs', 'size')
# 
#     def __init__(self, size, flat, refs=(), name=None):
#         self.size = size  # total size
#         self.flat = flat  # flat size
#         self.name = name  # name, repr or None
#         self.refs = tuple(refs)
# 
#     def __str__(self):
#         return 'size %r, flat %r, refs[%d], name %r' % (
#             self.size, self.flat, len(self.refs), self.name)
# 
#     def format(self, format='%(name)s size=%(size)d flat=%(flat)d',
#                      depth=-1, order_by='size', indent=''):
#         '''Format the size information of the object and of all
#            sized referents as a string.
# 
#             *format* -- Specifies the format per instance (with 'name',
#                         'size' and 'flat' as interpolation parameters)
# 
#             *depth* -- Recursion level up to which the referents are
#                        printed (use -1 for unlimited)
# 
#             *order_by* -- Control sort order of referents, valid choices
#                           are 'name', 'size' and 'flat'
# 
#             *indent* -- Optional indentation (default '')
#         '''
#         t = indent + (format % dict(size=self.size, flat=self.flat,
#                                     name=self.name))
#         if depth and self.refs:
#             rs = sorted(self.refs, key=lambda x: getattr(x, order_by),
#                                    reverse=order_by in ('size', 'flat'))
#             rs = [r.format(format=format, depth=depth-1, order_by=order_by,
#                            indent=indent+'    ') for r in rs]
#             t = '\n'.join([t] + rs)
#         return t
# 
#     def get(self, name, dflt=None):
#         '''Return the named referent (or *dflt* if not found).
#         '''
#         for ref in self.refs:
#             if name == ref.name:
#                 return ref
#         return dflt


from typing import (
    Any, Dict, IO, Iterable, List, Optional, Tuple, TYPE_CHECKING, Union
)
from copy import deepcopy
from pympler.util.stringutils import trunc, pp, pp_timestamp
from pympler.asizeof import Asized
    from .classtracker import TrackedObject, ClassTracker, Snapshot
            from pylab import figure, title, xlabel, ylabel, plot, savefig
            from pylab import (figure, title, xlabel, ylabel, plot, fill,
                               legend, savefig)
            from pylab import figure, title, pie, axes, savefig
            from pylab import sum as pylab_sum
import os
import pickle
import sys
            import matplotlib.mlab as mlab
"""
Provide saving, loading and presenting gathered `ClassTracker` statistics.
"""




if TYPE_CHECKING:


__all__ = ["Stats", "ConsoleStats", "HtmlStats"]


def _ref2key(ref: Asized) -> str:
    return ref.name.split(':')[0]



# Path: pympler/util/stringutils.py
# def trunc(obj: str, max: int, left: bool = False) -> str:
#     """
#     Convert `obj` to string, eliminate newlines and truncate the string to
#     `max` characters. If there are more characters in the string add ``...`` to
#     the string. With `left=True`, the string can be truncated at the beginning.
# 
#     @note: Does not catch exceptions when converting `obj` to string with
#         `str`.
# 
#     >>> trunc('This is a long text.', 8)
#     This ...
#     >>> trunc('This is a long text.', 8, left=True)
#     ...text.
#     """
#     s = str(obj)
#     s = s.replace('\n', '|')
#     if len(s) > max:
#         if left:
#             return '...' + s[len(s) - max + 3:]
#         else:
#             return s[:(max - 3)] + '...'
#     else:
#         return s
# 
# def pp(i: Union[int, float], base: int = 1024) -> str:
#     """
#     Pretty-print the integer `i` as a human-readable size representation.
#     """
#     degree = 0
#     pattern = "%4d     %s"
#     while i > base:
#         pattern = "%7.2f %s"
#         i = i / float(base)
#         degree += 1
#     scales = ['B', 'KB', 'MB', 'GB', 'TB', 'EB']
#     return pattern % (i, scales[degree])
# 
# def pp_timestamp(t: Optional[float]) -> str:
#     """
#     Get a friendly timestamp represented as a string.
#     """
#     if t is None:
#         return ''
#     h, m, s = int(t / 3600), int(t / 60 % 60), t % 60
#     return "%02d:%02d:%05.2f" % (h, m, s)
# 
# Path: pympler/asizeof.py
# class Asized(object):
#     '''Stores the results of an **asized** object in the following
#        4 attributes:
# 
#         *size* -- total size of the object (including referents)
# 
#         *flat* -- flat size of the object (in bytes)
# 
#         *name* -- name or ``repr`` of the object
# 
#         *refs* -- tuple containing an **Asized** instance for each referent
#     '''
#     __slots__ = ('flat', 'name', 'refs', 'size')
# 
#     def __init__(self, size, flat, refs=(), name=None):
#         self.size = size  # total size
#         self.flat = flat  # flat size
#         self.name = name  # name, repr or None
#         self.refs = tuple(refs)
# 
#     def __str__(self):
#         return 'size %r, flat %r, refs[%d], name %r' % (
#             self.size, self.flat, len(self.refs), self.name)
# 
#     def format(self, format='%(name)s size=%(size)d flat=%(flat)d',
#                      depth=-1, order_by='size', indent=''):
#         '''Format the size information of the object and of all
#            sized referents as a string.
# 
#             *format* -- Specifies the format per instance (with 'name',
#                         'size' and 'flat' as interpolation parameters)
# 
#             *depth* -- Recursion level up to which the referents are
#                        printed (use -1 for unlimited)
# 
#             *order_by* -- Control sort order of referents, valid choices
#                           are 'name', 'size' and 'flat'
# 
#             *indent* -- Optional indentation (default '')
#         '''
#         t = indent + (format % dict(size=self.size, flat=self.flat,
#                                     name=self.name))
#         if depth and self.refs:
#             rs = sorted(self.refs, key=lambda x: getattr(x, order_by),
#                                    reverse=order_by in ('size', 'flat'))
#             rs = [r.format(format=format, depth=depth-1, order_by=order_by,
#                            indent=indent+'    ') for r in rs]
#             t = '\n'.join([t] + rs)
#         return t
# 
#     def get(self, name, dflt=None):
#         '''Return the named referent (or *dflt* if not found).
#         '''
#         for ref in self.refs:
#             if name == ref.name:
#                 return ref
#         return dflt


# Path: pympler/classtracker_stats.py
from typing import (
    Any, Dict, IO, Iterable, List, Optional, Tuple, TYPE_CHECKING, Union
)
from copy import deepcopy
from pympler.util.stringutils import trunc, pp, pp_timestamp
from pympler.asizeof import Asized
    from .classtracker import TrackedObject, ClassTracker, Snapshot
            from pylab import figure, title, xlabel, ylabel, plot, savefig
            from pylab import (figure, title, xlabel, ylabel, plot, fill,
                               legend, savefig)
            from pylab import figure, title, pie, axes, savefig
            from pylab import sum as pylab_sum
import os
import pickle
import sys
            import matplotlib.mlab as mlab

"""
Provide saving, loading and presenting gathered `ClassTracker` statistics.
"""




if TYPE_CHECKING:


__all__ = ["Stats", "ConsoleStats", "HtmlStats"]


def _ref2key(ref: Asized) -> str:
    return ref.name.split(':')[0]



def _merge_asized(base: Asized, other: Asized, level: int = 0) -> None: