brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · e7896be Raw
40 lines · cpp
1// Printing memory profiling only works in the configuration where we can2// detect leaks.3// REQUIRES: leak-detection4//5// RUN: %clangxx_asan %s -o %t6// RUN: %run %t 100 10 2>&1 | FileCheck %s --check-prefix=CHECK-100-107// RUN: %run %t 100 1  2>&1 | FileCheck %s --check-prefix=CHECK-100-18// RUN: %run %t 50  10 2>&1 | FileCheck %s --check-prefix=CHECK-50-109#include <sanitizer/common_interface_defs.h>10 11#include <stdio.h>12#include <stdlib.h>13 14char *sink[1000];15 16int main(int argc, char **argv) {17  if (argc < 3)18    return 1;19 20  int idx = 0;21  for (int i = 0; i < 17; i++)22    sink[idx++] = new char[131000];23  for (int i = 0; i < 28; i++)24    sink[idx++] = new char[24000];25 26  __sanitizer_print_memory_profile(atoi(argv[1]), atoi(argv[2]));27}28 29// CHECK-100-10: Live Heap Allocations: {{.*}}; showing top 100% (at most 10 unique contexts)30// CHECK-100-10: 2227000 byte(s) ({{.*}}%) in 17 allocation(s)31// CHECK-100-10: 672000 byte(s) ({{.*}}%) in 28 allocation(s)32 33// CHECK-100-1: Live Heap Allocations: {{.*}}; showing top 100% (at most 1 unique contexts)34// CHECK-100-1: 2227000 byte(s) ({{.*}}%) in 17 allocation(s)35// CHECK-100-1-NOT: allocation36 37// CHECK-50-10: Live Heap Allocations: {{.*}}; showing top 50% (at most 10 unique contexts)38// CHECK-50-10: 2227000 byte(s) ({{.*}}%) in 17 allocation(s)39// CHECK-50-10-NOT: allocation40