<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="356286" data-post-id="356286">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="benwilson512" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/120/1457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  benwilson512
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Craft GraphQL APIs in Elixir with Absinthe</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Checkout <a href="https://hexdocs.pm/decorator/readme.html" class="inline-onebox" rel="nofollow">Elixir function decorators — decorator v1.4.0</a> which implements a module attribute based decorator pattern.</p>
<p>The main code for defining decorators is here: <a href="https://github.com/arjan/decorator/blob/master/lib/decorator/decorate.ex" class="inline-onebox" rel="nofollow">decorator/lib/decorator/decorate.ex at master · arjan/decorator · GitHub</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356286" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-356286" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356286"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="356300" data-post-id="356300">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dimitarvp" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/120/38664_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dimitarvp
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I wonder if I am missing something here. Whatever solution you end up with, this:</p>
<aside class="quote no-group" data-username="MadsBoydMadsen" data-post="1" data-topic="69381">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/madsboydmadsen/48/37499_2.png" class="avatar"> MadsBoydMadsen:</div>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">    start_time = System.monotonic_time(:millisecond)
    result = apply(fun, args)
    end_time = System.monotonic_time(:millisecond)
</code></pre>
</blockquote>
</aside>
<p>…should be replaced with this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{micros_elapsed, return_value} = :timer.tc(fn -&gt; apply(fun, args) end)
</code></pre>
<p>And I see that <a class="mention" href="/u/garrison" rel="nofollow">@garrison</a> and <a class="mention" href="/u/billylanchantin" rel="nofollow">@billylanchantin</a> already beat me to it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356300" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-356300" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356300"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="356303" data-post-id="356303">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BartOtten" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BartOtten/120/25440_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BartOtten
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Mandatory link in every Macro topic: <a href="https://www.theerlangelist.com/article/macros_1" class="inline-onebox" rel="noopener nofollow ugc">The Erlangelist - Understanding macros, part 1</a></p>
<p>While searching for it I landed on part 6 just to learn me something about AST context which I solved in a pull request less elegantly. “Just in time” they call it <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<p>Read all 6 blog posts and the answer will be in one of them. Guaranteed.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356303" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-356303" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356303"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="356305" data-post-id="356305">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BartOtten" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BartOtten/120/25440_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BartOtten
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Now the other mandatory thing: what do you want to accomplish?</p>
<p>You started by stating what you want the code to be able to, but what do you want with that data? Maybe we can find another solution getting you the same data/analysis.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356305" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-356305" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356305"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="356312" data-post-id="356312">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="MadsBoydMadsen" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/MadsBoydMadsen/120/37499_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  MadsBoydMadsen
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> Thanks a lot for all your lovely contributions.<br>
I’ll look through it all when I have a bit of time.</p>
<p>My aim <a class="mention" href="/u/bartotten" rel="nofollow">@BartOtten</a> is to work out why a particular action, that our users are doing, is timing out. It is critical to solve this problem, as it prevents our users from doing much meaningful work in our system.</p>
<p>It only happens in production. I’ve done significant investigations already (such as analysing the SQL-executions in an attempt to spot poor performance - which has yielded very little), and decided my next step should be to time the call-sequence in the application to narrow down where the problem is occuring.</p>
<p>My colleague already has a solution to time functions, but it struck me as useful <em>only</em> if you want to time little parts of the application. In my use-case, I really need to instrument the entire call-sequence, as I literally have no idea where the problem is coming from, and as it is expensive to repeatedly hotfix the production system.</p>
<p>Maybe there are tools out there which does this at a snap of my fingers - I don’t know.</p>
<p>The functional decomposition of the application is deep rather than flat (please don’t comment on that <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"> <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"> ), so I thought it would be helpful with an instrumentation mechanism that is really easy to apply. It would benefit the PR-review for the hotfix(es) to be able to easily see, that functionality has not been altered by applying timing code. Hence the idea of using a <strong>macro that substitutes <em>def</em> with <em>def_timed</em> - really easy to see in the PRs</strong></p>
<p>Are you with me ?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356312" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-356312" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356312"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="356317" data-post-id="356317">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="MadsBoydMadsen" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/MadsBoydMadsen/120/37499_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  MadsBoydMadsen
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This is great. Using <span class="mention">@decorator</span> looks helpful. I will have a dig into this.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356317" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-356317" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356317"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="356318" data-post-id="356318">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BartOtten" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BartOtten/120/25440_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BartOtten
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I see your point. Trying to come up with less invasive solutions to find the issue.</p>
<ol>
<li>Have you tried to connect erlang Observer to the production machine? It gathers statistics about your runtime (memory usage, function reductions etc)</li>
</ol>
<blockquote>
<p>In a BEAM application, you can potentially have millions of processes running at the same time. In order to ensure that each process gets (roughly) equal share of the available CPU(s), the VM counts reductions. One reduction is essentially equivalent to one function call.</p>
</blockquote>
<ol start="2">
<li>How about erlang tracer or <a href="https://hexdocs.pm/tracer/" rel="noopener nofollow ugc">Tracer</a>? Tracing is very powerful (and overlooked) in the BEAM! <a href="https://medium.com/hackernoon/a-guide-to-tracing-in-elixir-53b1afb996de" rel="noopener nofollow ugc">https://medium.com/hackernoon/a-guide-to-tracing-in-elixir-53b1afb996de</a></li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356318" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-356318" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356318"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="356320" data-post-id="356320">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="MadsBoydMadsen" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/MadsBoydMadsen/120/37499_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  MadsBoydMadsen
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Very helpful suggestions.<br>
I will look into both.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356320" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-356320" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356320"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="356321" data-post-id="356321">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kevinschweikert" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kevinschweikert/120/26866_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kevinschweikert
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Going in that direction maybe you can figure out the issue in dev with tools like <a href="https://hexdocs.pm/eflambe/" class="inline-onebox" rel="noopener nofollow ugc">The eflambe application</a> which produces a flamegraph which you can inspect</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356321" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-356321" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356321"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="356322" data-post-id="356322">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="BartOtten" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/BartOtten/120/25440_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  BartOtten
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Nice once. Although issues caused by n+1, long database (row) locks and memory limits are mostly non existent in dev environments. Every non-indexed table is working in dev environment <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<p><a class="mention" href="/u/madsboydmadsen" rel="nofollow">@MadsBoydMadsen</a> If the problem remains and you are able to spin up a test environment, I know a reliable company which can help stress / durability test the app by carefully drafted scenarios.</p>
<blockquote>
<p>why a <em>particular action</em>, that our users are doing, is timing out.</p>
</blockquote>
<p>Can you tell use the particular action? I like black box riddles <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>Tip for those with no Product Owner or higher Management: have a CI pipeline which tests performance with a large (generated) dataset every night after changes to main branch (or even PR branch). Store the result and auto compare, raising when change is above a threshold. Once found a “add row element” caused the whole DOM tree rendering to come to an halt as in production it caused a lot of new DOM.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356322" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/macro-to-provide-timing-for-a-function-call-handle-any-signature/69381/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-356322" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356322"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/69381/load_more?page=3">Load more posts (9 remaining)</a>
</div></template></turbo-stream>