Coder Social home page Coder Social logo

memoryinspector.jl's Introduction

MemoryInspector.jl

Build Status

  • MemoryInspector.@inspect x

An interactive tool for exploring the sizes of julia objects:

julia> d = Dict(1=>(1,2), 2=>3)
Dict{Int64,Any} with 2 entries:
  2 => 3
  1 => (1, 2)

julia> MemoryInspector.@inspect d
—————————————————————————————————————————————————————————————————————————————————————————————————————————
Select a field to recurse into or  to ascend. [q]uit.

Commands: [J]ump to field path.
Toggles: [v]alue of the current field.

(d)::Dict{Int64,Any} => 480.0 B
   64.0 B internal
3 Allocated Fields:
  vals::Array{Any,1} => 192.0 B
   keys::Array{Int64,1} => 168.0 B
   slots::Array{UInt8,1} => 56.0 B
   
—————————————————————————————————————————————————————————————————————————————————————————————————————————
Select a field to recurse into or  to ascend. [q]uit.

Commands: [J]ump to field path.
Toggles: [v]alue of the current field.

(d.vals)::Array{Any,1} => 192.0 B
   168.0 B internal
2 Allocated Indexes:
  16::Tuple{Int64,Int64} => 16.0 B
   6::Int64 => 8.0 B
   
—————————————————————————————————————————————————————————————————————————————————————————————————————————
Select a field to recurse into or  to ascend. [q]uit.

Commands: [J]ump to field path.
Toggles: [v]alue of the current field.

(d.vals[16])::Tuple{Int64,Int64} => 16.0 B
0 Allocated Indexes:
  

—————————————————————————————————————————————————————————————————————————————————————————————————————————
Select a field to recurse into or  to ascend. [q]uit.

Commands: [J]ump to field path.
Toggles: [v]alue of the current field.

(1, 2) => 16.0 B
0 Allocated Indexes:
  

Featuring True Size Accounting!

Importantly (like Base.summarysize(x)) @inspect x is able to account for self-references and shared references inside of objects, so that only the true sizes of fields are displayed! This allows you to correctly investigate the size of truly complex objects.

For example:

julia> mutable struct Obj{T1,T2}
           a::T1
           b::T2
           Obj{A,B}(a::A,b::B) where {A,B} = new{A,B}(a,b)
           Obj{A,B}(a::A) where {A,B} = new{A,B}(a) # Allow partial construction
           Obj{A,B}() where {A,B} = new{A,B}() # Allow partial construction
           Obj(a::A,b::B) where {A,B} = Obj{A,B}(a,b)
       end

julia> s = join(rand('a':'z', 1024*1024)); # 1 MiB string

julia> multistring = Obj(s,s);   # Shared references to large object

julia> selfie = Obj{Obj,Obj}(multistring);

julia> selfie.b = selfie;    # Self-reference

julia> MemoryInspector.@inspect selfie
———————————————————————————————————————————————————
(selfie)::Obj{Obj,Obj} => 1.0 MiB
2 Fields:
   a::Obj{String,String} => 1.0 MiB
  b::Obj{Obj,Obj} => <self-reference>
   
———————————————————————————————————————————————————
(selfie.b)::Obj{Obj,Obj} => <self-reference>
0 Fields:
  

———————————————————————————————————————————————————
(selfie)::Obj{Obj,Obj} => 1.0 MiB
2 Fields:
  a::Obj{String,String} => 1.0 MiB
   b::Obj{Obj,Obj} => <self-reference>
   
———————————————————————————————————————————————————
(selfie.a)::Obj{String,String} => 1.0 MiB
2 Fields:
  a::String => 1.0 MiB
   b::String => <self-reference>
   
———————————————————————————————————————————————————
(selfie.a.a)::String => 1.0 MiB
0 Fields:
  

Note that this does mean that sometimes the bytes may be accounted for in a sub-reference that may not match your expectations. This tradeoff between breadth-first and depth-first searching is something we should investigate tuning in the future!

Inspecting Memory via graph and flamegraph layouts:

We support exporting to a PProf profile, via MemoryInspector.@mem_pprof:

julia> d = Dict(1=>2, 2=>"hello", 3=>"hi", ("hi",2)=>3)
Dict{Any,Any} with 4 entries:
  2         => "hello"
  3         => "hi"
  ("hi", 2) => 3
  1         => 2

julia> MemoryInspector.@mem_pprof web=true webport=23222 d
"mem-inspect-profile.pb.gz"

Serving web UI on http://localhost:23222

Graph:

Screen Shot 2020-06-03 at 9 00 58 PM

Flamegraph:

Screen Shot 2020-06-03 at 9 05 35 PM

Desired Features

See this GitHub Issue for some desired features: #1

memoryinspector.jl's People

Contributors

nhdaly avatar

Stargazers

ebigram avatar Alexandre Bergel avatar Elias Carvalho avatar Casey Kneale avatar Eric Hanson avatar Christian Rorvik avatar Peter avatar Vikrant Sagar avatar  avatar

Watchers

Gustavo Goretkin avatar James Cloos avatar  avatar  avatar

memoryinspector.jl's Issues

Support later versions of Julia than 1.4

Currently this segfaults on 1.6, and I'm not sure about v1.5.

Likely we'll need to either make multiple copies of summarysize.jl for the different julia versions we support, or we'll need to include various static ifdefs for the various versions.

Desired Features

  • Toggle sorting by size vs alphabetically
  • Allow toggling between "container view" and "fields view"
  • Support container representation for more types (Dicts, Sets, any other kind of iterable?)
  • Allow displaying the value of a variable (or a summary of the value somehow), not just the variable's type. (Fixed in #6)
    • or maybe allow resuming previous session so you can ^c, investigate the value, then come back in? ("resuming a session" sort of added via "[J]ump to path" command in #5)
  • Allow scrolling sideways with arrowkeys for long field type names. (Fixed in #3)
    For example:
      ..ve.Database.DBHandle, AbstractComponent},SourceName},Salsa.DerivedValue{Tuple{Delve.Compiler.Front.Module,Array{Delve.Compiler.Front.SyntaxTrees.SyntaxError,1}}}} => 1.5 KiB

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.