title: How can I profile the TLB hits and TLB misses in ubuntu
body: <p>I have written a simple C++ program using for-loop to print the numbers from 1 to 100. I want to find the number of TLB hits and misses occurring for the particular program while running. Is there any possibility to get this data?</p>
  
  <p>I am using Ubuntu. I have used perf tool. But it is producing different result in different times. I am very confused what part of my code is leading to such a huge number TLB hits, TLB misses and cache misses. </p>
  
  <p>Ofcourse there might be other processes running simultaneously like Ubuntu GUI. But, does this result includes those process too?
  command I used: perf stat -e dTLB-loads -e dTPerformance counter stats for './hellocc':</p>
  
  <p>result: first time--           </p>
  
  <pre><code>       909,822 dTLB-loads                                                  
           2,023 dTLB-misses               #    0.22% of all dTLB cache hits 
           4,512 cache-misses                                                
  
     0.006821182 seconds time elapsed
  </code></pre>
  
  <p>LB-misses ./hellocc</p>
  
  <p>result: Second time--    Performance counter stats for './hellocc':</p>
  
  <pre><code>       907,810 dTLB-loads                                                  
           2,045 dTLB-misses               #    0.23% of all dTLB cache hits 
           4,533 cache-misses                                                
  
     0.006780635 seconds time elapsed
  </code></pre>
  
  <p>My simple code:</p>
  
  <pre><code>#include &lt;iostream&gt;    
  using namespace std;    
  int main
  {    
      cout &lt;&lt; "hello" &lt;&lt; "\n";    
      for(int i=1; i &lt;= 100; i = i + 1)    
          cout&lt;&lt; i &lt;&lt; "\t" ;    
      return 0;    
  }
  </code></pre>