How to use the pympler.summary.summarize 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 Jenyay / outwiker / tests / utils.py View on Github external
def print_memory(count=30):
    '''
    Print the statistics of the objects in the memory.
    Need pympler to use.
    '''
    from pympler import muppy, summary

    gc.collect()
    all_objects = muppy.get_objects()
    my_types = muppy.filter(all_objects, Type=wx.Object)
    sum1 = summary.summarize(my_types)
    # sum1 = summary.summarize(all_objects)
    summary.print_(sum1, limit=count)
github sdss / marvin / python / marvin / utils / general / general.py View on Github external
def memory_usage(where):
    """
    Print out a basic summary of memory usage.

    Parameters:
        where (str):
            A string description of where in the code you are summarizing memory usage
    """

    assert pympler is not None, 'the pympler python package is required to run this function'

    mem_summary = pympler.summary.summarize(pympler.muppy.get_objects())
    print("Memory summary: {0}".format(where))
    pympler.summary.print_(mem_summary, limit=2)
    print("VM: {0:.2f}Mb".format(get_virtual_memory_usage_kb() / 1024.0))
github mediatum / mediatum / web / admin / modules / memstats.py View on Github external
"count": len(all_objects),
        "total_size": 0,
        "summary": ""
    }

    sessions = athana._ATHANA_HANDLER.sessions

    sessions_info = {
        "count": len(sessions),
        "total_size": 0,
        "summary": ""
    }

    if pympler:
        sessions_info["total_size"] = asizeof(sessions)
        summarized_all_objects = sorted(summary.summarize(all_objects), key=lambda t: t[2], reverse=True)
        memory_info["summary"] = summarized_all_objects[:500]

    import os
    if "MEDIATUM_EMBED_IPYTHON" in os.environ:
        import IPython
        IPython.embed()

    del all_objects

    return render_template("memstats.j2.jade",
                           sessions=sessions_info,
                           memory=memory_info,
                           naturalsize=humanize.filesize.naturalsize)
github Pyomo / pyomo / pyomo / core / base / PyomoModel.py View on Github external
% total_time)
                    tmp_clone_counter = expr_common.clone_counter
                    if clone_counter != tmp_clone_counter:
                        clone_counter = tmp_clone_counter
                        print("             Cloning detected! (clone count: %d)" % clone_counters)

            # Note: As is, connectors are expanded when using command-line pyomo but not calling model.create(...) in a Python script.
            # John says this has to do with extension points which are called from commandline but not when writing scripts.
            # Uncommenting the next two lines switches this (command-line fails because it tries to expand connectors twice)
            #connector_expander = ConnectorExpander()
            #connector_expander.apply(instance=self)

            if (pympler_available is True) and (profile_memory >= 2):
                print("")
                print("      Summary of objects following instance construction")
                post_construction_summary = summary.summarize(muppy.get_objects())
                summary.print_(post_construction_summary, limit=100)
                print("")
github HenryHu / pybbs / rosters.py View on Github external
def handle_signal_abort(self, signum, frame):
        Log.warn("Someone want to kill me! But I'll not die now! Hahahaha!")
        s = summary.summarize(muppy.get_objects())
        Log.debug("Current memory usage:")
        summary.print_(s)
        diff = summary.get_diff(self.mem_sum, s)
        self.mem_sum = s
        Log.debug("New memory usage:")
        summary.print_(diff)
github klahnakoski / SpotManager / 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 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