# How to trace the functions called by my script？

**URL:** https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975
**Category:** General Usage
**Tags:** question
**Created:** [December 1, 2023, 5:11am UTC](https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975 "2023-12-01T05:11:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jiang\_ming\_zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiang_ming_zhang/32/204063_2.png) [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)
#### Post date: [December 1, 2023, 5:11am UTC](https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975/1 "2023-12-01T05:11:51Z")

</div>

Suppose I have a julia script, in which many functions are called. There might be even be nested calling. Namely, the main function calls function A, which calls function B, which in turn calls function C.

How can get a summary of these call relationships?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [December 1, 2023, 5:14am UTC](https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975/2 "2023-12-01T05:14:15Z")

</div>

profiling is the easiest way here. I would recommend ProfileView.jl which will give you nice flamegraphs

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [December 1, 2023, 6:22am UTC](https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975/3 "2023-12-01T06:22:00Z")

</div>

Out of curiosity, is there any function or macro that when called in a certain place returns the call stack as a vector or similar?

---

<div class="post-metadata">

### Author: ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)
#### Post date: [December 1, 2023, 7:31am UTC](https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975/4 "2023-12-01T07:31:16Z")

</div>

Might not be exactly what you are after, but my package [TraceFuns.jl](https://github.com/bertschi/TraceFuns.jl) allows you to see which functions get called from a specific top-level call.

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [December 1, 2023, 7:33am UTC](https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975/5 "2023-12-01T07:33:07Z")

</div>

That’s really nice.

---

<div class="post-metadata">

### Author: ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)
#### Post date: [December 1, 2023, 9:57pm UTC](https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975/6 "2023-12-01T21:57:18Z")

</div>

You might be looking for `stacktrace()`:

```julia
julia> stacktrace()
14-element Vector{Base.StackTraces.StackFrame}:
 top-level scope at REPL[10]:1
 eval at boot.jl:383 [inlined]
 eval_user_input(ast::Any, backend::REPL.REPLBackend, mod::Module) at REPL.jl:150
 repl_backend_loop(backend::REPL.REPLBackend, get_module::Function) at REPL.jl:246
 start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function) at REPL.jl:231
 kwcall(::NamedTuple, ::typeof(REPL.start_repl_backend), backend::REPL.REPLBackend, consumer::Any) at REPL.jl:228
 run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any) at REPL.jl:389
 run_repl(repl::REPL.AbstractREPL, consumer::Any) at REPL.jl:375
 (::Base.var"#1013#1015"{Bool, Bool, Bool})(REPL::Module) at client.jl:432
 #invokelatest#2 at essentials.jl:887 [inlined]
 invokelatest at essentials.jl:884 [inlined]
 run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool) at client.jl:416
 exec_options(opts::Base.JLOptions) at client.jl:333
 _start() at client.jl:552

```

---

<div class="post-metadata">

### Author: ![mikeliux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeliux/32/35170_2.png) [@mikeliux](https://discourse.julialang.org/u/mikeliux)
#### Post date: [February 12, 2025, 11:21am UTC](https://discourse.julialang.org/t/how-to-trace-the-functions-called-by-my-script/106975/7 "2025-02-12T11:21:53Z")

</div>

You can use [Debugger.jl](https://github.com/JuliaDebug/Debugger.jl) to track the execution of a complex code in julia

1. Turn your script into a function. Let us call it `myfunction(x, y)`
2. Add `Debugger.jl` package
3. Load the module by typing: `using Debugger`
4. Enter debug mode in the REPL with  
`@Debugger.enter myfunction(x, y)`
5. To avoid seeing low level functions, press ‘C’ to toggle compiled mode.
6. Press ‘s’ to step into a function, ‘n’ to go to the next line, or use breakpoints as described in the package documentation
7. At any point, type ‘bt’. This will show a backtrace, where you can see the stack of functions being called.
8. Use ‘q’ to quit
