File: profile_reset.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (39 lines) | stat: -rw-r--r-- 1,280 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Test to ensure that multiple rounds of dumping, using the
// __memprof_profile_reset interface to close the initial file
// and cause the profile to be reopened, works as expected.

// RUN: %clangxx_memprof  %s -o %t

// RUN: rm -f %t.log.*
// RUN: %env_memprof_opts=print_text=true:log_path=%t.log %run %t

// Check both outputs, starting with the renamed initial dump, then remove it so
// that the second glob matches a single file.
// RUN: FileCheck %s < %t.log.*.sv
// RUN: rm -f %t.log.*.sv
// RUN: FileCheck %s < %t.log.*
// CHECK: Memory allocation stack id

#include <sanitizer/memprof_interface.h>
#include <stdio.h>

#include <stdlib.h>
#include <string.h>
#include <string>
int main(int argc, char **argv) {
  char *x = (char *)malloc(10);
  memset(x, 0, 10);
  free(x);
  __memprof_profile_dump();
  // Save the initial dump in a different file.
  std::string origname = __sanitizer_get_report_path();
  std::string svname = origname + ".sv";
  rename(origname.c_str(), svname.c_str());
  // This should cause the current file descriptor to be closed and the
  // the internal state reset so that the profile filename is reopened
  // on the next write.
  __memprof_profile_reset();
  // This will dump to origname again.
  __memprof_profile_dump();
  return 0;
}