# Profiling the execution of a model

**URL:** <https://discourse.mc-stan.org/t/profiling-the-execution-of-a-model/5068>\
**Category:** Developers\
**Created:** [August 2, 2018, 7:26pm UTC](https://discourse.mc-stan.org/t/profiling-the-execution-of-a-model/5068 "2018-08-02T19:26:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [August 2, 2018, 7:26pm UTC](https://discourse.mc-stan.org/t/profiling-the-execution-of-a-model/5068/1 "2018-08-02T19:26:15Z")

</div>

Is there any option inside CmdStan to profile the execution of a model? Any easy way of seeing which parts of AD are the bottlenecks etc.

If there is not, does anyone have any ideas if this is possible at all and how?

So far the best solution I have is simply brute forcing a bunch of time measurements and prints in all the functions that I presume could be bottlenecks. I also measure the time of one transition ([here](https://github.com/stan-dev/stan/blob/develop/src/stan/services/util/generate_transitions.hpp)) and if the time execution times of the functions add up to the execution time of the transition or something close to it, I know I have found all of them.

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [August 2, 2018, 7:36pm UTC](https://discourse.mc-stan.org/t/profiling-the-execution-of-a-model/5068/2 "2018-08-02T19:36:23Z")

</div>

I’ve done some stuff with google-perftools before: [Adjoint sensitivities](http://discourse.mc-stan.org/t/adjoint-sensitivities/935/11)

[https://github.com/gperftools/gperftools](https://github.com/gperftools/gperftools) and for Ubuntu [https://github.com/ahorn/benchmarks/wiki/Profiling-with-google-perftools](https://github.com/ahorn/benchmarks/wiki/Profiling-with-google-perftools)

You gotta beware of inlining and optimization making the stack traces look be misleading, but I thought it worked pretty well. You can use google-perftools with about anything though, so a Stan binary should be fine.

---

<div class="post-metadata">

**Author:** ![seantalts](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/seantalts/32/32_2.png) [@seantalts](https://discourse.mc-stan.org/u/seantalts)\
**Post date:** [August 8, 2018, 8:36pm UTC](https://discourse.mc-stan.org/t/profiling-the-execution-of-a-model/5068/3 "2018-08-08T20:36:44Z")

</div>

[This thread](http://discourse.mc-stan.org/t/profiling-c-code/3033) has some generic suggestions, but I know you were seeing all of the virtual `chain()` calls being identified as the same call and I’m not sure how that works. I was seeing that with `-g` (in [this post](http://discourse.mc-stan.org/t/profiling-c-code/3033/19?u=seantalts) in that thread) that it was identifying at least which class’s chain methods were being called most.

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [August 9, 2018, 6:35am UTC](https://discourse.mc-stan.org/t/profiling-the-execution-of-a-model/5068/4 "2018-08-09T06:35:49Z")

</div>

Thanks to both of you. I will report back.
