39 lines · cpp
1// Test the histogram support in memprof using the text format output.2// Shadow memory counters per object are limited to 8b. In memory counters3// aggregating counts across multiple objects are 64b.4 5// RUN: %clangxx_memprof -O0 -mllvm -memprof-histogram -mllvm -memprof-use-callbacks=true %s -o %t6// RUN: %env_memprof_opts=print_text=1:histogram=1:log_path=stdout %run %t 2>&1 | FileCheck %s7 8#include <stdio.h>9#include <stdlib.h>10 11int main() {12 // Allocate memory that will create a histogram13 char *buffer = (char *)malloc(1024);14 if (!buffer)15 return 1;16 17 for (int i = 0; i < 10; ++i) {18 // Access every 8th byte (since shadow granularity is 8b.19 buffer[i * 8] = 'A';20 }21 22 for (int j = 0; j < 200; ++j) {23 buffer[8] = 'B'; // Count = previous count + 20024 }25 26 for (int j = 0; j < 400; ++j) {27 buffer[16] = 'B'; // Count is saturated at 25528 }29 30 // Free the memory to trigger MIB creation with histogram31 free(buffer);32 33 printf("Test completed successfully\n");34 return 0;35}36 37// CHECK: AccessCountHistogram[128]: 1 201 255 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 038// CHECK: Test completed successfully39