summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2018-07-19 09:20:19 +0000
committerDean Michael Berris <dberris@google.com>2018-07-19 09:20:19 +0000
commit41cea19b4f835ff91c83b1e6a677319157639ff4 (patch)
treeed0a8ccf79f933b5188292ccbe35017076706fc1 /compiler-rt/lib/xray
parentdd7bf598cc050c3c01c817194c508490f36d8bbe (diff)
downloadbcm5719-llvm-41cea19b4f835ff91c83b1e6a677319157639ff4.tar.gz
bcm5719-llvm-41cea19b4f835ff91c83b1e6a677319157639ff4.zip
[XRay][compiler-rt] Profiling: No files when empty
This change makes it so that the profiling mode implementation will only write files when there are buffers to write. Before this change, we'd always open a file even if there were no profiles collected when flushing. llvm-svn: 337443
Diffstat (limited to 'compiler-rt/lib/xray')
-rw-r--r--compiler-rt/lib/xray/xray_profiling.cc50
1 files changed, 27 insertions, 23 deletions
diff --git a/compiler-rt/lib/xray/xray_profiling.cc b/compiler-rt/lib/xray/xray_profiling.cc
index a11fddcc2c9..786084c7722 100644
--- a/compiler-rt/lib/xray/xray_profiling.cc
+++ b/compiler-rt/lib/xray/xray_profiling.cc
@@ -132,31 +132,35 @@ XRayLogFlushStatus profilingFlush() XRAY_NEVER_INSTRUMENT {
// At this point, we'll create the file that will contain the profile, but
// only if the options say so.
if (!profilingFlags()->no_flush) {
- int Fd = -1;
- Fd = getLogFD();
- if (Fd == -1) {
- if (__sanitizer::Verbosity())
- Report(
- "profiler: Failed to acquire a file descriptor, dropping data.\n");
+ // First check whether we have data in the profile collector service
+ // before we try and write anything down.
+ XRayBuffer B = profileCollectorService::nextBuffer({nullptr, 0});
+ if (B.Data == nullptr) {
+ if (Verbosity())
+ Report("profiling: No data to flush.\n");
} else {
- XRayProfilingFileHeader Header;
- Header.Timestamp = NanoTime();
- Header.PID = internal_getpid();
- retryingWriteAll(Fd, reinterpret_cast<const char *>(&Header),
- reinterpret_cast<const char *>(&Header) +
- sizeof(Header));
-
- // Now for each of the threads, write out the profile data as we would see
- // it in memory, verbatim.
- XRayBuffer B = profileCollectorService::nextBuffer({nullptr, 0});
- while (B.Data != nullptr && B.Size != 0) {
- retryingWriteAll(Fd, reinterpret_cast<const char *>(B.Data),
- reinterpret_cast<const char *>(B.Data) + B.Size);
- B = profileCollectorService::nextBuffer(B);
+ int Fd = getLogFD();
+ if (Fd == -1) {
+ if (Verbosity())
+ Report("profiling: Failed to flush to file, dropping data.\n");
+ } else {
+ XRayProfilingFileHeader Header;
+ Header.Timestamp = NanoTime();
+ Header.PID = internal_getpid();
+ retryingWriteAll(Fd, reinterpret_cast<const char *>(&Header),
+ reinterpret_cast<const char *>(&Header) +
+ sizeof(Header));
+
+ // Now for each of the threads, write out the profile data as we would
+ // see it in memory, verbatim.
+ while (B.Data != nullptr && B.Size != 0) {
+ retryingWriteAll(Fd, reinterpret_cast<const char *>(B.Data),
+ reinterpret_cast<const char *>(B.Data) + B.Size);
+ B = profileCollectorService::nextBuffer(B);
+ }
+ // Then we close out the file.
+ internal_close(Fd);
}
-
- // Then we close out the file.
- internal_close(Fd);
}
}
OpenPOWER on IntegriCloud