summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray/xray_inmemory_log.cc
Commit message (Collapse)AuthorAgeFilesLines
* [XRay][compiler-rt] Support string-based config for Basic mode.Dean Michael Berris2018-05-041-465/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This addresses http://llvm.org/PR36790. This change allows the XRay Basic Mode implementation to use the string-based initialization routine provided through `__xray_log_init_mode(...)`. In the process, we've also deprecated some flags defined for the `XRAY_OPTIONS` environment variable. We then introduce another environment variable that can control the XRay Basic Mode implementation through `XRAY_BASIC_OPTIONS`. We also rename files from `xray_inmemory_log` to `xray_basic_logging` to be more in line with the mode implementation. Depends on D46174. Reviewers: echristo, kpw, pelikan, eizan Reviewed By: kpw Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D46246 llvm-svn: 331507
* Implement trampoline and handler for typed xray event tracing.Keith Wyss2018-04-171-0/+1
| | | | | | | | | | | | | | Summary: Compiler-rt support first before defining the __xray_typedevent() lowering in llvm. I'm looking for some early feedback before I touch much more code. Reviewers: dberris Subscribers: delcypher, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D43668 llvm-svn: 330218
* Add Xray instrumentation support to FreeBSDKamil Rytarowski2018-02-151-1/+1
| | | | | | | | | | | | | | | | | | | Summary: - Enabling the build. - Using assembly for the cpuid parts. - Using thr_self FreeBSD call to get the thread id Patch by: David CARLIER Reviewers: dberris, rnk, krytarowski Reviewed By: dberris, krytarowski Subscribers: emaste, stevecheckoway, nglevin, srhines, kubamracek, dberris, mgorny, krytarowski, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D43278 llvm-svn: 325240
* [XRay] [compiler-rt] fix heap overflow by computing record pointers correctlyMartin Pelikan2018-01-191-22/+15
| | | | | | | | | | | | | | | | | | Summary: While there, unify InMemoryRawLog and InMemoryRawLogWithArg's coding style: - swap libc's memcpy(3) for sanitizer's internal memcpy - use basic pointer arithmetics to compute offsets from the first record entry in the pre-allocated buffer, which is always the appropriate type for the given function - lose the local variable references as the TLD.* names fit just as well Reviewers: eizan, kpw, dberris, dblaikie Subscribers: #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D42289 llvm-svn: 322941
* [XRay][compiler-rt] Use __sanitizer::Atexit() instead of atexit()Dean Michael Berris2017-12-051-1/+1
| | | | | | Follow-up to D40828. llvm-svn: 319764
* [XRay][compiler-rt] Implement XRay Basic Mode FilteringDean Michael Berris2017-12-051-54/+161
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This change implements the basic mode filtering similar to what we do in FDR mode. The implementation is slightly simpler in basic-mode filtering because we have less details to remember, but the idea is the same. At a high level, we do the following to decide when to filter function call records: - We maintain a per-thread "shadow stack" which keeps track of the XRay instrumented functions we've encountered in a thread's execution. - We push an entry onto the stack when we enter an XRay instrumented function, and note the CPU, TSC, and type of entry (whether we have payload or not when entering). - When we encounter an exit event, we determine whether the function being exited is the same function we've entered recently, was executing in the same CPU, and the delta of the recent TSC and the recorded TSC at the top of the stack is less than the equivalent amount of microseconds we're configured to ignore -- then we un-wind the record offset an appropriate number of times (so we can overwrite the records later). We also support limiting the stack depth of the recorded functions, so that we don't arbitrarily write deep function call stacks. Reviewers: eizan, pelikan, kpw, dblaikie Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40828 llvm-svn: 319762
* [XRay][compiler-rt] Implement logging implementation registrationDean Michael Berris2017-12-051-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This change allows for registration of multiple logging implementations through a central mechanism in XRay, mapping an implementation to a "mode". Modes are strings that are used as keys to determine which implementation to install through a single API. This mechanism allows users to choose which implementation to install either from the environment variable 'XRAY_OPTIONS' with the `xray_mode=` flag, or programmatically using the `__xray_select_mode(...)` function. Here, we introduce two API functions for the XRay logging: __xray_log_register_mode(Mode, Impl): Associates an XRayLogImpl to a string Mode. We can only have one implementation associated with a given Mode. __xray_log_select_mode(Mode): Finds the associated Impl for Mode and installs it as if by calling `__xray_set_log_impl(...)`. Along with these changes, we also deprecate the xray_naive_log and xray_fdr_log flags and encourage users to instead use the xray_mode flag. Reviewers: kpw, dblaikie, eizan, pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40703 llvm-svn: 319759
* [XRay][compiler-rt] Migrate basic mode logging to the XRay frameworkDean Michael Berris2017-11-211-84/+175
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Before this patch, XRay's basic (naive mode) logging would be initialised and installed in an adhoc manner. This patch ports the implementation of the basic (naive mode) logging implementation to use the common XRay framework. We also make the following changes to reduce the variance between the usage model of basic mode from FDR (flight data recorder) mode: - Allow programmatic control of the size of the buffers dedicated to per-thread records. This removes some hard-coded constants and turns them into runtime-controllable flags and through an Options structure. - Default the `xray_naive_log` option to false. For now, the only way to start basic mode is to set the environment variable, or set the default at build-time compiler options. Because of this change we've had to update a couple of tests relying on basic mode being always on. - Removed the reliance on a non-trivially destructible per-thread resource manager. We use a similar trick done in D39526 to use pthread_key_create() and pthread_setspecific() to ensure that the per-thread cleanup handling is performed at thread-exit time. We also radically simplify the code structure for basic mode, to move most of the implementation in the `__xray` namespace. Reviewers: pelikan, eizan, kpw Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40164 llvm-svn: 318734
* [XRay][compiler-rt] Write out arg1 payload in naive mode loggingDean Michael Berris2017-10-051-14/+106
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This change allows the XRay basic (naive) mode logging implementation to start writing the payload entries through the arg1 logging handler. This implementation writes out the records that the llvm-xray tool and the trace reader library will start processing in D38550. This introduces a new payload record type which logs the data through the in-memory buffer. It uses the same size/alignment that the normal XRay record entries use. We use a new record type to indicate these new entries, so that the trace reader library in LLVM can start reading these entries. Depends on D38550. Reviewers: pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38551 llvm-svn: 314968
* [XRay][compiler-rt] Handle tail-call exits in the XRay runtimeDean Michael Berris2017-09-181-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This change starts differentiating tail exits from normal exits. We also increase the version number of the "naive" log to version 2, which will be the starting version where these records start appearing. In FDR mode we treat the tail exits as normal exits, and are thus subject to the same treatment with regard to record unwriting. Updating the version number is important to signal older builds of the llvm-xray tool that do not deal with the tail exit records must fail early (and that users should only use the llvm-xray tool built after the support for tail exits to get accurate handling of these records). Depends on D37964. Reviewers: kpw, pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D37965 llvm-svn: 313515
* [XRay][compiler-rt] Remove use of std::mutex and std::shared_ptr from global ↵Dean Michael Berris2017-08-021-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | scope. Summary: This change attempts to remove all the dependencies we have on std::mutex and any std::shared_ptr construction in global variables. We instead use raw pointers to these objects, and construct them on the heap. In cases where it's possible, we lazily initialize these pointers. While we do not have a replacement for std::shared_ptr yet in compiler-rt, we use this work-around to avoid having to statically initialize the objects as globals. Subsequent changes should allow us to completely remove our dependency on std::shared_ptr and instead have our own implementation of the std::shared_ptr and std::weak_ptr semantics (or completely rewrite the implementaton to not need these standard-library provided abstractions). Reviewers: dblaikie, kpw, pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D36078 llvm-svn: 309792
* [XRay][compiler-rt] Use emulated TSC when CPU supports rdtscp, but cannot ↵Douglas Yung2017-04-181-3/+7
| | | | | | | | | | | | | | | | | | | | | determine the CPU frequency A problem arises if a machine supports the rdtscp instruction, but the processor frequency cannot be determined by the function getTSCFrequency(). In this case, we want to use the emulated TSC instead. This patch implements that by adding a call to getTSCFrequency() from probeRequiredCPUFeatures(), and the function only returns true if both the processor supports rdtscp and the CPU frequency can be determined. This should fix PR32620. Reviewers: dberris Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32067 llvm-svn: 300525
* [XRay][compiler-rt] Support TSC emulation even for x86_64Dean Michael Berris2017-03-151-11/+32
| | | | | | | | | | | | | | | | | | | Summary: Use TSC emulation in cases where RDTSCP isn't available on the host running an XRay instrumented binary. We can then fall back into emulation instead of not even installing XRay's runtime functionality. We only do this for now in the naive/basic logging implementation, but should be useful in even FDR mode. Should fix http://llvm.org/PR32148. Reviewers: pelikan, rnk, sdardis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D30677 llvm-svn: 297800
* [XRay] [compiler-rt] [NFC] Annotate unused variables for the compiler.Dean Michael Berris2017-02-281-1/+1
| | | | | | | | | | | | | | | | | Summary: Use a common definition of a "this variable is unused" annotation for useless variables only present for their lambda global initializers, to silence gcc's warning. Reviewers: dberris Reviewed By: dberris Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29860 llvm-svn: 296449
* Re-submit r294826 "Fix -Wsign-compare" reverted in r294842 by mistake.Vitaly Buka2017-02-111-2/+1
| | | | | | Fix -Wsign-compare - this might not be quite right, but preserves behavior llvm-svn: 294868
* This reverts commits r294826 and r294781 as they break linking on powerpc.Vitaly Buka2017-02-111-1/+2
| | | | | | | | | | Revert "Fix -Wsign-compare - this might not be quite right, but preserves behavior" Revert "[XRay] Implement powerpc64le xray." This reverts commit r294826. This reverts commit r294781. llvm-svn: 294842
* Fix -Wsign-compare - this might not be quite right, but preserves behaviorDavid Blaikie2017-02-111-2/+1
| | | | llvm-svn: 294826
* [XRay] Refactor TSC related functions into a single header. NFC.Tim Shen2017-02-101-10/+3
| | | | | | | | | | | | | Summary: The implementation, however, is in different arch-specific files, unless it's emulated. Reviewers: dberris, pelikan, javed.absar Subscribers: aemerson, llvm-commits Differential Revision: https://reviews.llvm.org/D29796 llvm-svn: 294777
* [XRay] Probe for CPU features that XRay needsDean Michael Berris2017-02-021-0/+5
| | | | | | | | | | | | | | | | | | | | Summary: In llvm.org/PR31756 it's pointed out that sometimes rdtscp isn't available. We fix it here by checking first whether it's availble before installing the logging handler. In future commits we can have alternative implementations, maybe working around some of the constraints on some systems. This change enables us to make that determination, but report an error instead when the features aren't available. Reviewers: sdardis, javed.absar, rSerge Subscribers: pelikan, llvm-commits Differential Revision: https://reviews.llvm.org/D29438 llvm-svn: 293870
* [XRay][compiler-rt] XRay Flight Data Recorder ModeDean Michael Berris2017-01-251-58/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In this change we introduce the notion of a "flight data recorder" mode for XRay logging, where XRay logs in-memory first, and write out data on-demand as required (as opposed to the naive implementation that keeps logging while tracing is "on"). This depends on D26232 where we implement the core data structure for holding the buffers that threads will be using to write out records of operation. This implementation only currently works on x86_64 and depends heavily on the TSC math to write out smaller records to the inmemory buffers. Also, this implementation defines two different kinds of records with different sizes (compared to the current naive implementation): a MetadataRecord (16 bytes) and a FunctionRecord (8 bytes). MetadataRecord entries are meant to write out information like the thread ID for which the metadata record is defined for, whether the execution of a thread moved to a different CPU, etc. while a FunctionRecord represents the different kinds of function call entry/exit records we might encounter in the course of a thread's execution along with a delta from the last time the logging handler was called. While this implementation is not exactly what is described in the original XRay whitepaper, this one gives us an initial implementation that we can iterate and build upon. Reviewers: echristo, rSerge, majnemer Subscribers: mehdi_amini, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D27038 llvm-svn: 293015
* [XRay] [compiler-rt] Include argv[0] in the log file name.Dean Michael Berris2017-01-031-6/+15
| | | | | | | | | | | | | | | | | Summary: If you decide to recompile parts of your Linux distro with XRay, it may be useful to know which trace belongs to which binary. While there, get rid of the incorrect strncat() usage; it always returns a pointer to the start which makes that if() always true. Replace with snprintf which is bounded so that enough from both strings fits nicely. Reviewers: dberris Subscribers: danalbert, srhines, kubabrecka, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D27912 llvm-svn: 290861
* Revert "[XRay][compiler-rt] XRay Flight Data Recorder Mode"Dean Michael Berris2017-01-031-23/+66
| | | | | | This reverts rL290852 as it breaks aarch64 and arm. llvm-svn: 290854
* [XRay][compiler-rt] XRay Flight Data Recorder ModeDean Michael Berris2017-01-031-66/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In this change we introduce the notion of a "flight data recorder" mode for XRay logging, where XRay logs in-memory first, and write out data on-demand as required (as opposed to the naive implementation that keeps logging while tracing is "on"). This depends on D26232 where we implement the core data structure for holding the buffers that threads will be using to write out records of operation. This implementation only currently works on x86_64 and depends heavily on the TSC math to write out smaller records to the inmemory buffers. Also, this implementation defines two different kinds of records with different sizes (compared to the current naive implementation): a MetadataRecord (16 bytes) and a FunctionRecord (8 bytes). MetadataRecord entries are meant to write out information like the thread ID for which the metadata record is defined for, whether the execution of a thread moved to a different CPU, etc. while a FunctionRecord represents the different kinds of function call entry/exit records we might encounter in the course of a thread's execution along with a delta from the last time the logging handler was called. While this implementation is not exactly what is described in the original XRay whitepaper, this one gives us an initial implementation that we can iterate and build upon. Reviewers: echristo, rSerge, majnemer Subscribers: mehdi_amini, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D27038 llvm-svn: 290852
* [XRay] [compiler-rt] Move machine-dependent code into machine-dependent filesDiana Picus2016-12-221-139/+46
| | | | | | | | | | Reapply r290077. Authors: pelikan Differential Revision: https://reviews.llvm.org/D27979 llvm-svn: 290330
* Revert "[XRay] [compiler-rt] Move machine-dependent code into ↵Diana Picus2016-12-191-46/+139
| | | | | | | | machine-dependent files." This reverts commit r290077, 78, 79 and 83. llvm-svn: 290101
* [XRay][compiler-rt] Explicitly include <cstdint> for typesDean Michael Berris2016-12-191-2/+2
| | | | | | | | This is an attempt to un-break the ARM7, AArch64 builds. Follow-up on D25360. llvm-svn: 290078
* [XRay] [compiler-rt] Move machine-dependent code into machine-dependent files.Dean Michael Berris2016-12-191-139/+46
| | | | | | | | | | | | Summary: Include the necessary headers while there. Reviewers: dberris Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25360 llvm-svn: 290077
* [XRay][compiler-rt] Add newlines to error messages (NFC).Dean Michael Berris2016-11-231-6/+6
| | | | | | | This goes through all the calls to `Report(...)` to make sure that each one would have a newline at the end of the message for readability. llvm-svn: 287736
* [XRay] Support AArch64 in compiler-rtDean Michael Berris2016-11-211-3/+3
| | | | | | | | | | | | | | | | | | This patch adds XRay support in compiler-rt for AArch64 targets. This patch is one of a series: LLVM: https://reviews.llvm.org/D26412 Clang: https://reviews.llvm.org/D26415 Author: rSerge Reviewers: rengolin, dberris Subscribers: aemerson, mgorny, llvm-commits, iid_iunknown Differential Revision: https://reviews.llvm.org/D26413 llvm-svn: 287517
* [XRay][compiler-rt] Disable XRay instrumentation of the XRay runtime.Dean Michael Berris2016-11-161-10/+20
| | | | | | | | | | | | | | | | | | | | | Summary: Adds a CMake check for whether the compiler used to build the XRay library supports XRay-instrumentation. If the compiler we're using does support the `-fxray-instrument` flag (i.e. recently-built Clang), we define the XRAY_NEVER_INSTRUMENT macro that then makes sure that the XRay runtime functions never get XRay-instrumented. This prevents potential weirdness involved with building the XRay library with a Clang that supports XRay-instrumentation, and is attempting to XRay-instrument the build of compiler-rt. Reviewers: majnemer, rSerge, echristo Subscribers: mehdi_amini, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D26597 llvm-svn: 287068
* [compiler-rt][XRay][NFC] clang-format XRay sourcesDean Michael Berris2016-10-061-7/+6
| | | | llvm-svn: 283421
* [XRay] ARM 32-bit no-Thumb support in compiler-rtDean Michael Berris2016-09-201-4/+48
| | | | | | | | | | | | This is a port of XRay to ARM 32-bit, without Thumb support yet. This is one of 3 commits to different repositories of XRay ARM port. The other 2 are: https://reviews.llvm.org/D23931 (LLVM) https://reviews.llvm.org/D23932 (Clang test) Differential Revision: https://reviews.llvm.org/D23933 llvm-svn: 281971
* Revert "[XRay] ARM 32-bit no-Thumb support in compiler-rt"Renato Golin2016-09-081-48/+4
| | | | | | This reverts commit r280890, as the related LLVM commit broke the thumb bots. llvm-svn: 280969
* [XRay] ARM 32-bit no-Thumb support in compiler-rtDean Michael Berris2016-09-081-4/+48
| | | | | | | | | | | | | This is a port of XRay to ARM 32-bit, without Thumb support yet. This is one of 3 commits to different repositories of XRay ARM port. The other 2 are: 1. https://reviews.llvm.org/D23931 (LLVM) 2. https://reviews.llvm.org/D23932 (Clang test) Differential Revision: https://reviews.llvm.org/D23933 llvm-svn: 280890
* Add #include <cstdio> to unbreak build (missing definition of stderr)Krzysztof Parzyszek2016-09-061-0/+1
| | | | llvm-svn: 280714
* [compiler-rt][XRay] Remove unnecessary assertion.Dean Michael Berris2016-08-261-3/+0
| | | | | | This assert only causes issues with signed/unsigned comparisons. llvm-svn: 279819
* [compiler-rt][XRay] Initial per-thread inmemory logging implementationDean Michael Berris2016-08-261-0/+227
Depends on D21612 which implements the building blocks for the compiler-rt implementation of the XRay runtime. We use a naive in-memory log of fixed-size entries that get written out to a log file when the buffers are full, and when the thread exits. This implementation lays some foundations on to allowing for more complex XRay records to be written to the log in subsequent changes. It also defines the format that the function call accounting tool in D21987 will start building upon. Once D21987 lands, we should be able to start defining more tests using that tool once the function call accounting tool becomes part of the llvm distribution. Reviewers: echristo, kcc, rnk, eugenis, majnemer, rSerge Subscribers: sdardis, rSerge, dberris, tberghammer, danalbert, srhines, majnemer, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D21982 llvm-svn: 279805
OpenPOWER on IntegriCloud