Coder Social home page Coder Social logo

traceit.jl's Introduction

TraceIt.jl

The goal is to trace functions with minimal overhead and no modifications to the source code.

The package is a prototype for demonstration purposes, use at your own risk (e.g., attempting to trace Base.:+ will likely crash Julia).

Example

using TraceIt

@trace Base.sum; @trace Base.log

reduce(log, map(sum, [[1, 2, 3], [4, 5], [6]]))

# mostly compile time on the first run:
printtrace()
Func. ╲ Stat. │ called  mem, b  gctime, s    time, s  time, %
──────────────┼──────────────────────────────────────────────
sum           │      3   12272        0.0  0.0102889  54.94 %
log           │      2  138281        0.0  0.0084373  45.06 %
──────────────┼──────────────────────────────────────────────
Σ             │      5  150553        0.0  0.0187262  100.0 %

The implementation

The tracing is implemented with the use of Base.invoke_in_world, in the following way.

Say, there is function foo to be traced in Foo:

module Foo
    foo(x) = x
end

Tracing is done by (somewhere inside @trace Foo.foo):

primary_world = Base.get_world_counter()
@eval Foo function foo(x)
    #=  record some statistics globally  =#
    @info "foo is now traced!"
    return Base.invoke_in_world($primary_world, foo, x)
end

Un-tracing (somewhere inside @untrace Foo.foo):

@eval Foo function foo(x)
    return Base.invoke_in_world($primary_world, foo, x)
end

traceit.jl's People

Stargazers

 avatar

Watchers

 avatar

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.