Skip to content

Id checked but not used in <Use perf_event_open for counting> #1352

Closed
@CpyKing

Description

@CpyKing

I found some code that confused me in Configure multiple counters Section under Use perf_event_open for counting Chapter.
In the code under the annotation // Read the group of counters and print result, it shows like this...

read(fd[0], &counter_results, sizeof(struct read_format));
printf("Num events captured: %"PRIu64"\n", counter_results.nr);
for(int i = 0; i < counter_results.nr; i++) {
  for(int j = 0; j < TOTAL_EVENTS ;j++){
    if(counter_results.values[i].id == id[j]){
      pe_val[i] = counter_results.values[i].value;
    }
  }
}
printf("CPU cycles: %"PRIu64"\n", pe_val[0]);
printf("Instructions retired: %"PRIu64"\n", pe_val[1]);
printf("Frontend stall cycles: %"PRIu64"\n", pe_val[2]);
printf("Backend stall cycles: %"PRIu64"\n", pe_val[3]);
printf("Loads executed speculatively: %"PRIu64"\n", pe_val[4]);
printf("Stores executed speculatively: %"PRIu64"\n", pe_val[5]);

We can see that traverse id[j] here is to check the true_id that value belonged to. However, it assign the value with index i to pe_val with this same index i (not j) and print them sequentially. It make the check part useless.

So, is there any problem around here ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions