| 1 | // Check profile with a single malloc call and set of loads and stores. Ensures |
| 2 | // we get the same profile regardless of whether the memory is deallocated |
| 3 | // before exit. |
| 4 | |
| 5 | // RUN: %clang_memprof -O0 %s -o %t |
| 6 | // RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s |
| 7 | |
| 8 | // RUN: %clang_memprof -DFREE -O0 %s -o %t |
| 9 | // RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s |
| 10 | |
| 11 | // This is actually: |
| 12 | // Memory allocation stack id = STACKID |
| 13 | // alloc_count 1, size (ave/min/max) 40.00 / 40 / 40 |
| 14 | // but we need to look for them in the same CHECK to get the correct STACKID. |
| 15 | // CHECK: Memory allocation stack id = [[STACKID:[0-9]+]]{{[[:space:]].*}}alloc_count 1, size (ave/min/max) 40.00 / 40 / 40 |
| 16 | // CHECK-NEXT: access_count (ave/min/max): 20.00 / 20 / 20 |
| 17 | // CHECK-NEXT: lifetime (ave/min/max): [[AVELIFETIME:[0-9]+]].00 / [[AVELIFETIME]] / [[AVELIFETIME]] |
| 18 | // CHECK-NEXT: num migrated: {{[0-1]}}, num lifetime overlaps: 0, num same alloc cpu: 0, num same dealloc_cpu: 0 |
| 19 | // CHECK: Stack for id [[STACKID]]: |
| 20 | // CHECK-NEXT: #0 {{.*}} in {{.*}}malloc |
| 21 | // CHECK-NEXT: #1 {{.*}} in main {{.*}}:[[@LINE+6]] |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | |
| 26 | int main() { |
| 27 | int *p = (int *)malloc(size: 10 * sizeof(int)); |
| 28 | for (int i = 0; i < 10; i++) |
| 29 | p[i] = i; |
| 30 | int j = 0; |
| 31 | for (int i = 0; i < 10; i++) |
| 32 | j += p[i]; |
| 33 | #ifdef FREE |
| 34 | free(p); |
| 35 | #endif |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |