[PATCH] D27912: [XRay] [compiler-rt] Include argv[0] in the log file name.
Martin Pelikán via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 19 01:16:43 PST 2016
pelikan updated this revision to Diff 81928.
pelikan added a comment.
add a test
https://reviews.llvm.org/D27912
Files:
lib/xray/xray_inmemory_log.cc
test/xray/TestCases/Linux/fixedsize-logging.cc
Index: test/xray/TestCases/Linux/fixedsize-logging.cc
===================================================================
--- test/xray/TestCases/Linux/fixedsize-logging.cc
+++ test/xray/TestCases/Linux/fixedsize-logging.cc
@@ -2,6 +2,7 @@
// RUN: %clangxx_xray -std=c++11 %s -o %t
// RUN: XRAY_OPTIONS="verbosity=1 xray_logfile_base=fixedsize-logging-" %run %t 2>&1 | FileCheck %s
+// RUN: ls -la fixedsize-logging-$(basename %t).?????? 2>&1
//
// After all that, clean up the output xray log.
//
Index: lib/xray/xray_inmemory_log.cc
===================================================================
--- lib/xray/xray_inmemory_log.cc
+++ lib/xray/xray_inmemory_log.cc
@@ -112,14 +112,23 @@
// Open a temporary file once for the log.
static char TmpFilename[256] = {};
static char TmpWildcardPattern[] = "XXXXXX";
- auto E = internal_strncat(TmpFilename, flags()->xray_logfile_base,
- sizeof(TmpFilename) - 10);
- if (static_cast<size_t>((E + 6) - TmpFilename) > (sizeof(TmpFilename) - 1)) {
- Report("XRay log file base too long: %s\n", flags()->xray_logfile_base);
+ auto Argv = GetArgv();
+ const char *Progname = Argv[0] == nullptr ? "(unknown)" : Argv[0];
+ const char *LastSlash = internal_strrchr(Progname, '/');
+
+ if (LastSlash != nullptr)
+ Progname = LastSlash + 1;
+
+ const int HalfLength = sizeof(TmpFilename) / 2 - sizeof(TmpWildcardPattern);
+ int NeededLength = internal_snprintf(TmpFilename, sizeof(TmpFilename),
+ "%.*s%.*s.%s",
+ HalfLength, flags()->xray_logfile_base,
+ HalfLength, Progname,
+ TmpWildcardPattern);
+ if (NeededLength > int(sizeof(TmpFilename))) {
+ Report("XRay log file name too long (%d): %s\n", NeededLength, TmpFilename);
return -1;
}
- internal_strncat(TmpFilename, TmpWildcardPattern,
- sizeof(TmpWildcardPattern) - 1);
int Fd = mkstemp(TmpFilename);
if (Fd == -1) {
Report("XRay: Failed opening temporary file '%s'; not logging events.\n",
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27912.81928.patch
Type: text/x-patch
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161219/32ba6bd4/attachment.bin>
More information about the llvm-commits
mailing list