# How to know where a specific function is called without resorting to debugger?

**URL:** https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513
**Category:** General Usage
**Tags:** question
**Created:** [December 4, 2017, 11:22pm UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513 "2017-12-04T23:22:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)
#### Post date: [December 4, 2017, 11:22pm UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513/1 "2017-12-04T23:22:29Z")

</div>

I’m going through a large julia package where I’m particularly interested in how the computing is done in one specific function (I’m certain that this function is called, as I added a print line therein so that if the function is called it prints something). I tried to use ASTInterpreter2 to help me identify where the function is called. Unfortunately, the package is so complicated that ASTInterpreter2 fails to work (the issue is just too complicated to be filed with a reasonably small MWE). I also tried to add `println(backtrace())` in that function, expecting that the result of `backtrace()` can give me some clue. But what `backtrace()` returns is just too hard to interpret for an average non-geek like myself.

Thanks in advance for any comments.

---

<div class="post-metadata">

### Author: ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)
#### Post date: [December 4, 2017, 11:46pm UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513/2 "2017-12-04T23:46:27Z")

</div>

`stacktrace()` 🙂

---

<div class="post-metadata">

### Author: ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)
#### Post date: [December 5, 2017, 12:15am UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513/3 "2017-12-05T00:15:47Z")

</div>

Thanks a lot! This is pretty much what I’m after. One quick question - `stackback()` seems to only print the names of the files in the stack without giving much information about the locations of the files. Is there a way to let `stackback()` elaborate a little by printing also the directory of each file involved?

---

<div class="post-metadata">

### Author: ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)
#### Post date: [December 5, 2017, 12:30am UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513/4 "2017-12-05T00:30:38Z")

</div>

You can also try [TraceCalls.jl](https://github.com/cstjean/TraceCalls.jl)

```julia
trace = @trace ModuleName ...computation...
filter_lineage(tr -> tr.func==function_youre_interested_in, trace; keep_descendents=false)

```

This will show the callers of `function_youre_interested_in`, in tree form.

---

<div class="post-metadata">

### Author: ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)
#### Post date: [December 5, 2017, 12:42am UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513/5 "2017-12-05T00:42:22Z")

</div>

> [@cstjean](#):
>
> You can also try TraceCalls.jl

Thanks! I’ve tried the package. But here is what I just saw:

```julia
julia> trace = @trace FastSummation ...computation...
ERROR: syntax: "..." expression outside call

```

Can you re-list the commands that you just gave by capitalizing the keywords I should change for my own case? Thanks!

---

<div class="post-metadata">

### Author: ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)
#### Post date: [December 5, 2017, 2:11am UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513/6 "2017-12-05T02:11:18Z")

</div>

TraceCalls returns a tree of all the function calls that happened during the execution of `...computation...` (replace it with whatever code you want to execute). There are many examples in the [manual](http://nbviewer.jupyter.org/github/cstjean/TraceCalls.jl/blob/master/README.ipynb). `filter_lineage(tr -> tr.func==foo, trace; keep_descendents=false)` will get rid of all the function calls in the tree except `foo`, its callers, its callers’ callers, etc. It won’t give you very different information than `stacktrace()`, but it will look nicer, and traces are very manipulable objects. Plus, you don’t have to modify the code you’re exploring.

---

<div class="post-metadata">

### Author: ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)
#### Post date: [December 5, 2017, 3:35am UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513/7 "2017-12-05T03:35:11Z")

</div>

It should be true that only files in base have relative paths, while all of your files will be listed with absolute paths. I think there’s a function (`functionloc`, iirc) that’ll try to distinguish the two for you (used `by less` and `edit` and such)

---

<div class="post-metadata">

### Author: ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)
#### Post date: [December 5, 2017, 5:35am UTC](https://discourse.julialang.org/t/how-to-know-where-a-specific-function-is-called-without-resorting-to-debugger/7513/8 "2017-12-05T05:35:54Z")

</div>

> [@jameson](#):
>
> It should be true that only files in base have relative paths, while all of your files will be listed with absolute paths. I think there’s a function (functionloc, iirc) that’ll try to distinguish the two for you (used by less and edit and such)

Yes, you’re right. It’s `functionloc` and it gives the location of method definition. Thanks for mentioning this function. I didn’t know it until now.
