summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/Linux/Perf.cpp
AgeCommit message (Collapse)Author
2025-04-29[lldb][AIX] get host info for AIX (#134354)Hemang Gadhavi
This PR is in reference to porting LLDB on AIX. Link to discussions on llvm discourse and github: 1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640 2. https://github.com/llvm/llvm-project/issues/101657 The complete changes for porting are present in this draft PR: https://github.com/llvm/llvm-project/pull/102601 - Added changes to make the common host support functions under `Host/posix` for unix-like system. Also, created the `unittests/Host/posix/` to test the hostInfo & support functions for unix-like system. - Added changes to get the host information for AIX. (GetProcessInfo()) (Information like : executable path, arch, process status etc.)
2023-09-01[lldb] Fix duplicate word typos; NFCFangrui Song
Those fixes were taken from https://reviews.llvm.org/D137338
2022-12-16[trace] Migrate uses of operator<<(raw_ostream &OS, const Optional<T> &O) to ↵Fangrui Song
std::optional
2022-12-04[lldb] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-10-05Fix LLDB build on old Linux kernels (pre-4.1)David Spickett
These fields are guarded elsewhere, but were missing here. Reviewed By: wallace Differential Revision: https://reviews.llvm.org/D133778
2022-08-11[NFC][lldb][trace] Fix formatting of tracing filesWalter Erquinigo
Pavel Labath taught me that clang-format sorts headers automatically using llvm's rules, and it's better not to have spaces between So in this diff I'm removing those spaces and formatting them as well. I used `clang-format -i` to format these files.
2022-06-28[lldb] Fix build on older Linux kernel versionsYi Kong
PERF_COUNT_SW_DUMMY is introduced in Linux 3.12. Differential Revision: https://reviews.llvm.org/D128707
2022-06-19[lldb] Use value_or instead of getValueOr (NFC)Kazu Hirata
2022-06-16[trace][intelpt] Support system-wide tracing [22] - Some final touchesWalter Erquinigo
Having a member variable TraceIntelPT * makes it look as if it was optional. I'm using instead a weak_ptr to indicate that it's not optional and the object is under the ownership of TraceIntelPT. Besides that, I've simplified the Perf aux and data buffers copying by using vector.insert. I'm also renaming Lookup2 to Lookup. The 2 in the name is confusing. Differential Revision: https://reviews.llvm.org/D127881
2022-06-16[trace][intelpt] Support system-wide tracing [21] - Support long numbers in JSONWalter Erquinigo
llvm's JSON parser supports 64 bit integers, but other tools like the ones written in JS don't support numbers that big, so we need to represent these possibly big numbers as a string. This diff uses that to represent addresses and tsc zero. The former is printed in hex for and the latter in decimal string form. The schema was updated mentioning that. Besides that, I fixed some remaining issues and now all test pass. Before I wasn't running all tests because for some reason my computer reverted perf_paranoid to 1. Differential Revision: https://reviews.llvm.org/D127819
2022-06-16[trace][intelpt] Support system-wide tracing [20] - Rename some fields in ↵Walter Erquinigo
the schema As discusses offline with @jj10305, we are updating some naming used throughout the code, specially in the json schema - traceBuffer -> iptTrace - core -> cpu Differential Revision: https://reviews.llvm.org/D127817
2022-06-16[trace][intelpt] Support system-wide tracing [18] - some more improvementsWalter Erquinigo
This applies the changes requested for diff 12. - use DenseMap<ConstString, _> instead of std::unordered_map<ConstString, _>, which is more idiomatic and possibly performant. - deduplicate some code in Trace.cpp by using helper functions for fetching in maps - stop using size and offset when fetching binary data, because we in fact read the entire buffers all the time. If we ever need streaming, we can implement it then. Now, the size is used only to check that we are getting the correct amount of data. This is useful because in some cases determining the size doesn't involve fetching the actual data. - added back the x86_64 macro to the perf tests - added more documentation - simplified some file handling - fixed some comments Differential Revision: https://reviews.llvm.org/D127752
2022-06-16[trace][intelpt] Support system-wide tracing [17] - Some improvementsWalter Erquinigo
This improves several things and addresses comments up to the diff [11] in this stack. - Simplify many functions to receive less parameters that they can identify easily - Create Storage classes for Trace and TraceIntelPT that can make it easier to reason about what can change with live process refreshes and what cannot. - Don't cache the perf zero conversion numbers in lldb-server to make sure we get the most up-to-date numbers. - Move the thread identifaction from context switches to the bundle parser, to leave TraceIntelPT simpler. This also makes sure that the constructor of TraceIntelPT is invoked when the entire data has been checked to be correct. - Normalize all bundle paths before the Processes, Threads and Modules are created, so that they can assume that all paths are correct and absolute - Fix some issues in the tests. Now they all pass. - return the specific instance when constructing PerThread and MultiCore processor tracers. - Properly implement IntelPTMultiCoreTrace::TraceStart. - Improve some comments. - Use the typedef ContextSwitchTrace more often for clarity. - Move CreateContextSwitchTracePerfEvent to Perf.h as a utility function. - Synchronize better the state of the context switch and the intel pt perf events. - Use a booblean instead of an enum for the PerfEvent state. Differential Revision: https://reviews.llvm.org/D127456
2022-06-16[trace][intelpt] Support system-wide tracing [13] - Add context switch decodingWalter Erquinigo
- Add the logic that parses all cpu context switch traces and produces blocks of continuous executions, which will be later used to assign intel pt subtraces to threads and to identify gaps. This logic can also identify if the context switch trace is malformed. - The continuous executions blocks are able to indicate when there were some contention issues when producing the context switch trace. See the inline comments for more information. - Update the 'dump info' command to show information and stats related to the multicore decoding flow, including timing about context switch decoding. - Add the logic to conver nanoseconds to TSCs. - Fix a bug when returning the context switches. Now they data returned makes sense and even empty traces can be returned from lldb-server. - Finish the necessary bits for loading and saving a multi-core trace bundle from disk. - Change some size_t to uint64_t for compatibility with 32 bit systems. Tested by saving a trace session of a program that sleeps 100 times, it was able to produce the following 'dump info' text: ``` (lldb) trace load /tmp/trace3/trace.json (lldb) thread trace dump info Trace technology: intel-pt thread #1: tid = 4192415 Total number of instructions: 1 Memory usage: Total approximate memory usage (excluding raw trace): 2.51 KiB Average memory usage per instruction (excluding raw trace): 2573.00 bytes Timing for this thread: Timing for global tasks: Context switch trace decoding: 0.00s Events: Number of instructions with events: 0 Number of individual events: 0 Multi-core decoding: Total number of continuous executions found: 2499 Number of continuous executions for this thread: 102 Errors: Number of TSC decoding errors: 0 ``` Differential Revision: https://reviews.llvm.org/D126267
2022-06-15[trace][intelpt] Support system-wide tracing [12] - Support multi-core trace ↵Walter Erquinigo
load and save :q! This diff is massive, but it's because it connects the client with lldb-server and also ensures that the postmortem case works. - Flatten the postmortem trace schema. The reason is that the schema has become quite complex due to the new multicore case, which defeats the original purpose of having a schema that could work for every trace plug-in. At this point, it's better that each trace plug-in defines it's own full schema. This means that the only common field is "type". -- Because of this new approach, I merged the "common" trace load and saving functionalities into the IntelPT one. This simplified the code quite a bit. If we eventually implement another trace plug-in, we can see then what we could reuse. -- The new schema, which is flattened, has now better comments and is parsed better. A change I did was to disallow hex addresses, because they are a bit error prone. I'm asking now to print the address in decimal. -- Renamed "intel" to "GenuineIntel" in the schema because that's what you see in /proc/cpuinfo. - Implemented reading the context switch trace data buffer. I had to do some refactors to do that cleanly. -- A major change that I did here was to simplify the perf_event circular buffer reading logic. It was too complex. Maybe the original Intel author had something different in mind. - Implemented all the necessary bits to read trace.json files with per-core data. - Implemented all the necessary bits to save to disk per-core trace session. - Added a test that ensures that parsing and saving to disk works. Differential Revision: https://reviews.llvm.org/D126015
2022-06-15[trace][intelpt] Support system-wide tracing [9] - Collect and return ↵Walter Erquinigo
context switch traces - Add collection of context switches per cpu grouped with the per-cpu intel pt traces. - Move the state handling from the interl pt trace class to the PerfEvent one. - Add support for stopping and enabling perf event groups. - Return context switch entries as part of the jLLDBTraceGetState response. - Move the triggers of whenever the process stopped or resumed. Now the will-resume notification is in a better location, which will ensure that we'll capture the instructions that will be executed. - Remove IntelPTSingleBufferTraceUP. The unique pointer was useless. - Add unit tests Differential Revision: https://reviews.llvm.org/D125897
2022-05-17[trace][intelpt] Support system-wide tracing [5] - Disable/enable per-core ↵Walter Erquinigo
tracing based on the process state When tracing on per-core mode, we are tracing all processes, which means that after hitting a breakpoint, our process will stop running (thus producing no more tracing data) but other processes will continue writing to our trace buffers. This causes a big data loss for our trace. As a way to remediate this, I'm adding some logic to pause and unpause tracing based on the target's state. The earlier we do it the better, however, I'm not adding the trigger at the earliest possible point for simplicity of this diff. Later we can improve that part. Differential Revision: https://reviews.llvm.org/D124962
2022-05-17[trace][intelpt] Support system-wide tracing [4] - Support per core tracing ↵Walter Erquinigo
on lldb-server This diffs implements per-core tracing on lldb-server. It also includes tests that ensure that tracing can be initiated from the client and that the jLLDBGetState ppacket returns the list of trace buffers per core. This doesn't include any decoder changes. Finally, this makes some little changes here and there improving the existing code. A specific piece of code that can't reliably be tested is when tracing per core fails due to permissions. In this case we add a troubleshooting message and this is the manual test: ``` /proc/sys/kernel/perf_event_paranoid set to 1 (lldb) process trace start --per-core-tracing error: perf event syscall failed: Permission denied You might need that /proc/sys/kernel/perf_event_paranoid has a value of 0 or -1. `` Differential Revision: https://reviews.llvm.org/D124858
2022-05-09[trace][intelpt] Support system-wide tracing [3] - Refactor IntelPTThreadTraceWalter Erquinigo
I'm refactoring IntelPTThreadTrace into IntelPTSingleBufferTrace so that it can both single threads or single cores. In this diff I'm basically renaming the class, moving it to its own file, and removing all the pieces that are not used along with some basic cleanup. Differential Revision: https://reviews.llvm.org/D124648
2022-05-02[trace][intelpt] Support system-wide tracing [1] - Add a method for ↵Walter Erquinigo
accessing the list of logical core ids In order to open perf events per core, we need to first get the list of core ids available in the system. So I'm adding a function that does that by parsing /proc/cpuinfo. That seems to be the simplest and most portable way to do that. Besides that, I made a few refactors and renames to reflect better that the cpu info that we use in lldb-server comes from procfs. Differential Revision: https://reviews.llvm.org/D124573
2022-03-24[trace][intelpt] Server side changes for TSC to wall time conversionJakob Johnson
Update the response schema of the TraceGetState packet and add Intel PT specific response structure that contains the TSC conversion, if it exists. The IntelPTCollector loads the TSC conversion and caches it to prevent unnecessary calls to perf_event_open. Move the TSC conversion calculation from Perf.h to TraceIntelPTGDBRemotePackets.h to remove dependency on Linux specific headers. Differential Revision: https://reviews.llvm.org/D122246
2022-03-21Fix e6c84f82b87576a57d1fa1c7e8c289d3d4fa7ab1Jakob Johnson
Failed buildbot: https://lab.llvm.org/buildbot/#/builders/17/builds/19480 The fix seems to be simply be adding some type casts to make the compiler happy
2022-03-21Add thin wrapper for perf_event_open APIJakob Johnson
- Add PerfEvent class to handle creating ring buffers and handle the resources associated with a perf_event - Refactor IntelPT collection code to use this new API - Add TSC to timestamp conversion logic with unittest Differential Revision: https://reviews.llvm.org/D121734