# Find where a specific method gets called

**URL:** https://discourse.julialang.org/t/find-where-a-specific-method-gets-called/89068
**Category:** General Usage
**Tags:** multidispatch, methods
**Created:** [October 21, 2022, 2:50pm UTC](https://discourse.julialang.org/t/find-where-a-specific-method-gets-called/89068 "2022-10-21T14:50:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)
#### Post date: [October 21, 2022, 2:50pm UTC](https://discourse.julialang.org/t/find-where-a-specific-method-gets-called/89068/1 "2022-10-21T14:50:55Z")

</div>

Is there a way to find all places in my code base where a specific method (not function!) gets called (or may get called)? The method in question for me is `Base.*`, so `grep`ing for \* over the whole code base produces way to many hits and I really only want all the places where my specific implementation of `Base.*` for some custom types gets called.

Could I e.g. inside my method definition add some code to find out where it got called from and  
print that and run the tests that I have? So something like:

```julia

function Base.*(a::MyType, b::MyType)
    println(whocalledme())
    return dostuff(a, b)
end

```

where `whocalledme()` returns where `Base.*` just got called from and probably involves some debugger magic. Is such a thing possible?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [October 21, 2022, 2:53pm UTC](https://discourse.julialang.org/t/find-where-a-specific-method-gets-called/89068/2 "2022-10-21T14:53:17Z")

</div>

```julia
error(1)

```

and read the back trace

---

<div class="post-metadata">

### Author: ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)
#### Post date: [October 21, 2022, 3:09pm UTC](https://discourse.julialang.org/t/find-where-a-specific-method-gets-called/89068/3 "2022-10-21T15:09:07Z")

</div>

`backtrace` was indeed the word I was looking for, thanks for pointing me in that direction!

I do the following now

```julia
function Base.*(a::MyType, b::MyType)
    tr = backtrace()
    Base.show_backtrace(stdout, tr[1:2]) # I don't need the whole trace
    return dostuff(a, b)
end

```

which has the advantage that execution does not stop and prints only the interesting part of the stacktrace.
