title: Getting gperftools to work with Rcpp
body: <p>I've read related posts <a href="https://stackoverflow.com/questions/13224322/profiling-rcpp-code-on-os-x">here</a> and <a href="https://stackoverflow.com/questions/23685206/is-my-using-gperftools-to-profile-a-r-script-with-rcpp-correct">here</a>, and looked at Dirk Eddelbuettel's talk <a href="http://dirk.eddelbuettel.com/papers/ismNov2009introHPCwithR.pdf" rel="nofollow noreferrer">here</a> and yet I'm failing to even get a .log file from <code>gperftools</code>.  Here is my <code>R</code> file, called <code>Rcpp_practice.R</code>:</p>
  
  <pre><code>library(Rcpp)
  
  Sys.setenv("PKG_LIBS"="-lprofiler")
  sourceCpp('eigen.cpp')
  
  a &lt;- matrix(rnorm(300^2), 300, 300)
  getEigenValues(a)
  </code></pre>
  
  <p>Here are the contents of <code>eigen.cpp</code>:</p>
  
  <pre><code>#include &lt;RcppArmadillo.h&gt;
  #include &lt;gperftools/profiler.h&gt;
  // [[Rcpp::depends(RcppArmadillo)]]
  
  // [[Rcpp::export]]
  arma::vec getEigenValues(arma::mat M) {
      return arma::eig_sym(M);
  }
  </code></pre>
  
  <p>Then, on Terminal (I'm using OSX):</p>
  
  <pre><code>CPUPROFILE="eigenprof.log" R -f "Rcpp_practice.R"
  </code></pre>
  
  <p>I was hoping to see <code>eigenprof.log</code> sitting  in my working directory but I don't.  Also, I don't get the message that I've seen in other posts of the form <code>PROFILE: interrupts/evictions/bytes = 012/34/567891</code></p>
  
  <p>I verified that I have the latest version of <code>gperftools</code> installed. (<code>$ brew upgrade google-perftools</code> gives <code>Error: gperftools 2.5 already installed</code>).</p>
  
  <p>What am I missing?</p>
  
  <p><strong>Update</strong></p>
  
  <p>After I modified my code to match @nrussell's I get this error message:</p>
  
  <pre><code>Error in dyn.load("/private/var/folders/6k/ffcchdq52kbb7d631b5vsqcw0000gn/T/RtmpCIdHkG/sourceCpp-x86_64-apple-darwin13.4.0-0.12.7/sourcecpp_6c3253d60384/sourceCpp_2.so") : 
  unable to load shared object '/private/var/folders/6k/ffcchdq52kbb7d631b5vsqcw0000gn/T/RtmpCIdHkG/sourceCpp-x86_64-apple-darwin13.4.0-0.12.7/sourcecpp_6c3253d60384/sourceCpp_2.so':
  dlopen(/private/var/folders/6k/ffcchdq52kbb7d631b5vsqcw0000gn/T/RtmpCIdHkG/sourceCpp-x86_64-apple-darwin13.4.0-0.12.7/sourcecpp_6c3253d60384/sourceCpp_2.so, 6): Symbol not found: _ProfilerStart
  Referenced from: /private/var/folders/6k/ffcchdq52kbb7d631b5vsqcw0000gn/T/RtmpCIdHkG/sourceCpp-x86_64-apple-darwin13.4.0-0.12.7/sourcecpp_6c3253d60384/sourceCpp_2.so
  Expected in: flat namespace
  in /private/var/folders/6k/ffcchdq52kbb7d631b5vsqcw0000gn/T/RtmpCIdHkG/sourceCpp-x86_64-apple-darwin13.4.0-0.12.7/sourcecpp_6c3253d60384/sourceCpp_2.so
  Calls: sourceCpp -&gt; source -&gt; withVisible -&gt; eval -&gt; eval -&gt; dyn.load
  Execution halted
  </code></pre>
  
  <p>This appears on the line with <code>sourceCpp</code> if I run the script interactively.</p>