How to use the pympler.summary function in Pympler

To help you get started, we’ve selected a few Pympler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebookincubator / memory-analyzer / tests / test_analysis_template.py View on Github external
def setUp(self):	
        self.items = [	
            ["builtins.test1", 1, 10000],	
            ["__main__.test2", 3, 5],	
            ["ast._things.test3", 10, 1024],	
        ]	
        # TODO: Add tests for summary obj and the _repr	
        mock_summ = mock.patch.object(summary, "summarize", return_value=self.items)	
        mock_summ.start()	
        self.addCleanup(mock_summ.stop)
github pympler / pympler / pympler / tracker.py View on Github external
def format_diff(self, ignore=()):
        """Format the diff to the last time the state of objects was measured.

        keyword arguments
        ignore -- list of objects to ignore
        """
        # ignore this and the caller frame
        lines = []
        diff = self.get_diff(ignore+(inspect.currentframe(),))
        lines.append("Added objects:")
        for line in summary.format_(summary.summarize(diff['+'])):
            lines.append(line)
        lines.append("Removed objects:")
        for line in summary.format_(summary.summarize(diff['-'])):
            lines.append(line)
        return lines
github pympler / pympler / pympler / muppy.py View on Github external
def _get_summaries(function, *args):
        """Get a 2-tuple containing one summary from before, and one summary
        from after the function has been invoked.

        """
        s_before = summary.summarize(get_objects())
        function(*args)
        s_after = summary.summarize(get_objects())
        return (s_before, s_after)
github facebookincubator / memory-analyzer / memory_analyzer / analysis_utils.py View on Github external
the first PID listed to the first PID in the file. Any unmatched or non-first
    PIDs will be ignored because we don't know what to compare them to.
    """
    try:
        prev_items = list(frontend_utils.get_pages(snapshot_file))
    except pickle.UnpicklingError as e:
        frontend_utils.echo_error(
            f"Error unpickling the data from {snapshot_file}: {e}"
        )
        return None

    differences = []
    for cur_item in cur_items:
        for prev_item in prev_items:
            if cur_item.pid == prev_item.pid:
                diff = summary.get_diff(cur_item.data, prev_item.data)
                differences.append(
                    RetrievedObjects(
                        pid=cur_item.pid,
                        title=f"Snapshot Differences for {cur_item.pid}",
                        data=diff,
                    )
                )
    if not differences:
        diff = summary.get_diff(cur_items[0].data, prev_items[0].data)
        differences.append(
            RetrievedObjects(pid=0, title=f"Snapshot Differences", data=diff)
        )
    return differences
github mozilla / ActiveData / vendor / pyLibrary / meta.py View on Github external
)

                    from pympler import summary
                    from pympler import muppy
                    sum1 = sorted(summary.summarize(muppy.get_objects()), key=lambda r: -r[2])[:30]
                    Log.warning("{{data}}", data=sum1)
                elif end_memory > 1000*1000*1000:
                    Log.warning(
                        "MEMORY WARNING (over {{end_memory|comma}}bytes): "+self.description,
                        default_params=self.params,
                        end_memory=end_memory
                    )

                    from pympler import summary
                    from pympler import muppy
                    sum1 = sorted(summary.summarize(muppy.get_objects()), key=lambda r: -r[2])[:30]
                    Log.warning("{{data}}", data=sum1)

            except Exception as e:
                Log.warning("problem in memory measure", cause=e)
github mozilla / jx-sqlite / vendor / pyLibrary / meta.py View on Github external
)

                    from pympler import summary
                    from pympler import muppy
                    sum1 = sorted(summary.summarize(muppy.get_objects()), key=lambda r: -r[2])[:30]
                    Log.warning("{{data}}", data=sum1)
                elif end_memory > 1000*1000*1000:
                    Log.warning(
                        "MEMORY WARNING (over {{end_memory|comma}}bytes): "+self.description,
                        default_params=self.params,
                        end_memory=end_memory
                    )

                    from pympler import summary
                    from pympler import muppy
                    sum1 = sorted(summary.summarize(muppy.get_objects()), key=lambda r: -r[2])[:30]
                    Log.warning("{{data}}", data=sum1)

            except Exception as e:
                Log.warning("problem in memory measure", cause=e)
github facebookexperimental / eden / edenscm / hgext / sigtrace.py View on Github external
def printmemory(sig, currentframe):
    try:
        from pympler import muppy, summary

        muppy.get_objects
    except ImportError:
        return

    all_objects = muppy.get_objects()
    sum1 = summary.summarize(all_objects)
    path = mempathformat % {"time": time.time(), "pid": os.getpid()}
    with open(path, "w") as f:
        f.write("\n".join(summary.format_(sum1, limit=50, sort="#")))
github Pyomo / pyomo / pyomo / scripting / util.py View on Github external
if not data.options.runtime.logging == 'quiet':
            if not os.path.exists(fname):
                print("ERROR: file "+fname+" has not been created!")
            else:
                print("Model written to file '"+str(fname)+"'")

        if data.options.runtime.report_timing is True:
            total_time = time.time() - write_start_time
            print("      %6.2f seconds required to write file" % total_time)

        if (pympler_available is True) and (data.options.runtime.profile_memory >= 2):
            print("")
            print("      Summary of objects following file output")
            post_file_output_summary = summary.summarize(muppy.get_objects())
            summary.print_(post_file_output_summary, limit=100)

            print("")

    for ep in ExtensionPoint(IPyomoScriptSaveInstance):
        ep.apply( options=data.options, instance=instance )

    if (pympler_available is True) and (data.options.runtime.profile_memory >= 1):
        mem_used = muppy.get_size(muppy.get_objects())
        if mem_used > data.local.max_memory:
            data.local.max_memory = mem_used
        print("   Total memory = %d bytes following Pyomo instance creation" % mem_used)

    return pyutilib.misc.Options(
                    model=model, instance=instance,
                    smap_id=smap_id, filename=fname, local=data.local )