[PATCH] D89086: [MemProf] Allow the binary to specify the profile output filename
Teresa Johnson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 22 08:30:43 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c20d7db9f27: [MemProf] Allow the binary to specify the profile output filename (authored by tejohnson).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89086/new/
https://reviews.llvm.org/D89086
Files:
compiler-rt/lib/memprof/memprof_interface_internal.h
compiler-rt/lib/memprof/memprof_rtl.cpp
compiler-rt/lib/memprof/weak_symbols.txt
compiler-rt/test/memprof/TestCases/log_path_test.cpp
Index: compiler-rt/test/memprof/TestCases/log_path_test.cpp
===================================================================
--- compiler-rt/test/memprof/TestCases/log_path_test.cpp
+++ compiler-rt/test/memprof/TestCases/log_path_test.cpp
@@ -21,6 +21,24 @@
// RUN: not %run %t 2> %t.out
// RUN: FileCheck %s --check-prefix=CHECK-LONG < %t.out
+// Specifying the log name via the __memprof_profile_filename variable.
+// RUN: %clangxx_memprof %s -o %t -DPROFILE_NAME_VAR="%t.log2"
+// RUN: rm -f %t.log2.*
+// RUN: %run %t 2> %t.out
+// RUN: FileCheck %s --check-prefix=CHECK-GOOD < %t.log2.*
+
+// Check that the log_path option overrides the log name set via the
+// __memprof_profile_filename variable.
+// RUN: rm -f %t.log.*
+// RUN: %env_memprof_opts=log_path=%t.log %run %t 2> %t.out
+// RUN: FileCheck %s --check-prefix=CHECK-GOOD < %t.log.*
+
+#ifdef PROFILE_NAME_VAR
+#define xstr(s) str(s)
+#define str(s) #s
+char __memprof_profile_filename[] = xstr(PROFILE_NAME_VAR);
+#endif
+
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
Index: compiler-rt/lib/memprof/weak_symbols.txt
===================================================================
--- compiler-rt/lib/memprof/weak_symbols.txt
+++ compiler-rt/lib/memprof/weak_symbols.txt
@@ -1 +1 @@
-___memprof_default_options
+___memprof_default_options __memprof_profile_filename
Index: compiler-rt/lib/memprof/memprof_rtl.cpp
===================================================================
--- compiler-rt/lib/memprof/memprof_rtl.cpp
+++ compiler-rt/lib/memprof/memprof_rtl.cpp
@@ -27,6 +27,9 @@
uptr __memprof_shadow_memory_dynamic_address; // Global interface symbol.
+// Allow the user to specify a profile output file via the binary.
+SANITIZER_WEAK_ATTRIBUTE char __memprof_profile_filename[1];
+
namespace __memprof {
static void MemprofDie() {
@@ -172,7 +175,12 @@
AddDieCallback(MemprofDie);
SetCheckFailedCallback(MemprofCheckFailed);
- __sanitizer_set_report_path(common_flags()->log_path);
+ // Use profile name specified via the binary itself if it exists, and hasn't
+ // been overrriden by a flag at runtime.
+ if (__memprof_profile_filename[0] != 0 && !common_flags()->log_path)
+ __sanitizer_set_report_path(__memprof_profile_filename);
+ else
+ __sanitizer_set_report_path(common_flags()->log_path);
__sanitizer::InitializePlatformEarly();
Index: compiler-rt/lib/memprof/memprof_interface_internal.h
===================================================================
--- compiler-rt/lib/memprof/memprof_interface_internal.h
+++ compiler-rt/lib/memprof/memprof_interface_internal.h
@@ -46,6 +46,9 @@
SANITIZER_INTERFACE_ATTRIBUTE
extern uptr __memprof_shadow_memory_dynamic_address;
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern char
+ __memprof_profile_filename[1];
+
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_load(uptr p);
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_store(uptr p);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89086.299987.patch
Type: text/x-patch
Size: 2972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201022/92bca797/attachment.bin>
More information about the llvm-commits
mailing list