title: How to use PERF_SAMPLE_READ with mmap
body: <p>This question is related to the <code>perf_event_open</code> syscall, but there is no tag for it.</p>
  
  <p>I'm currently looking to use the <code>PERF_SAMPLE_READ</code> member of the enum <code>perf_event_sample_format</code> to retreive some data from a memory map, but for an unknown reason, the syscall itself return "invalid argument" (errno 22).</p>
  
  <hr>
  
  <p>I have the following configuration :</p>
  
  <pre><code>this-&gt;eventConfiguration.sample_freq = 11;
  this-&gt;eventConfiguration.freq = true;
  this-&gt;eventConfiguration.inherit = true;
  this-&gt;eventConfiguration.sample_type = PERF_SAMPLE_CPU | PERF_SAMPLE_TIME | PERF_SAMPLE_PERIOD /*| PERF_SAMPLE_READ*/;
  </code></pre>
  
  <p>The event I'm tracking is <code>PERF_COUNT_HW_CPU_CYCLES</code>.</p>
  
  <p>There is my syscall. I spy each core of my computer :</p>
  
  <pre><code>int fileDescriptor = syscall(__NR_perf_event_open, this-&gt;configuration.getEventConfiguration() , -1, i, -1, 0);
  </code></pre>
  
  <p>The handling of the error is shown below, but I don't think it's useful...</p>
  
  <pre><code>if(fileDescriptor &lt; 0) {
    switch(errno) {
      // here is some cases
    };
  }
  </code></pre>
  
  <hr>
  
  <p>Thanks in advance ! :-)</p>