summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/TimeProfiler.cpp
AgeCommit message (Collapse)Author
2024-10-23[llvm] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#113415)Kazu Hirata
2024-10-08[TimeProfiler] Added instant events to llvm TimeProfiler. (#103039)ivanaivanovska
This adds support for adding instant events to the TimeProfiler. Later we plan to use it to record deferring of template instantiations.
2024-07-21Reapply "Add source file name for template instantiations in -ftime-trace" ↵Utkarsh Saxena
(#99757) Reverts https://github.com/llvm/llvm-project/pull/99731 Remove accidentally added temporary file. Also, fix the uninitialized read of line number.
2024-07-19Revert "Reapply "Add source file name for template instantiations in ↵Jorge Gorbe Moya
-ftime-trace"" (#99731) Reverts llvm/llvm-project#99545 There were a couple of issues reported in the PR: a sanitizer warning (https://lab.llvm.org/buildbot/#/builders/164/builds/1246/steps/14/logs/stdio) and a tmp file accidentally included in the commit.
2024-07-19Reapply "Add source file name for template instantiations in -ftime-trace" ↵Utkarsh Saxena
(#99545) Fix the Windows test.
2024-07-18Revert "Add source file name for template instantiations in -ftime-trace" ↵Utkarsh Saxena
(#99534) Reverts llvm/llvm-project#98320 Breaks windows tests: ``` Step 8 (test-build-unified-tree-check-clang-unit) failure: test (failure) ******************** TEST 'Clang-Unit :: Support/./ClangSupportTests.exe/1/3' FAILED ******************** Script(shard): -- GTEST_OUTPUT=json:C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Support\.\ClangSupportTests.exe-Clang-Unit-4296-1-3.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=3 GTEST_SHARD_INDEX=1 C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Support\.\ClangSupportTests.exe -- Script: -- C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Support\.\ClangSupportTests.exe --gtest_filter=TimeProfilerTest.TemplateInstantiations -- C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\clang\unittests\Support\TimeProfilerTest.cpp(278): error: Expected equality of these values: R"( Frontend | ParseFunctionDefinition (fooB) | ParseFunctionDefinition (fooMTA) | ParseFunctionDefinition (fooA) | ParseDeclarationOrFunctionDefinition (test.cc:3:5) | | ParseFunctionDefinition (user) | PerformPendingInstantiations | | InstantiateFunction (fooA<int>, ./a.h:7) | | | InstantiateFunction (fooB<int>, ./b.h:3) | | | InstantiateFunction (fooMTA<int>, ./a.h:4) )" Which is: "\nFrontend\n| ParseFunctionDefinition (fooB)\n| ParseFunctionDefinition (fooMTA)\n| ParseFunctionDefinition (fooA)\n| ParseDeclarationOrFunctionDefinition (test.cc:3:5)\n| | ParseFunctionDefinition (user)\n| PerformPendingInstantiations\n| | InstantiateFunction (fooA<int>, ./a.h:7)\n| | | InstantiateFunction (fooB<int>, ./b.h:3)\n| | | InstantiateFunction (fooMTA<int>, ./a.h:4)\n" buildTraceGraph(Json) Which is: "\nFrontend\n| ParseFunctionDefinition (fooB)\n| ParseFunctionDefinition (fooMTA)\n| ParseFunctionDefinition (fooA)\n| ParseDeclarationOrFunctionDefinition (test.cc:3:5)\n| | ParseFunctionDefinition (user)\n| PerformPendingInstantiations\n| | InstantiateFunction (fooA<int>, .\\a.h:7)\n| | | InstantiateFunction (fooB<int>, .\\b.h:3)\n| | | InstantiateFunction (fooMTA<int>, .\\a.h:4)\n" With diff: @@ -7,5 +7,5 @@ | | ParseFunctionDefinition (user) | PerformPendingInstantiations -| | InstantiateFunction (fooA<int>, ./a.h:7) -| | | InstantiateFunction (fooB<int>, ./b.h:3) -| | | InstantiateFunction (fooMTA<int>, ./a.h:4)\n +| | InstantiateFunction (fooA<int>, .\\a.h:7) +| | | InstantiateFunction (fooB<int>, .\\b.h:3) +| | | InstantiateFunction (fooMTA<int>, .\\a.h:4)\n C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\clang\unittests\Support\TimeProfilerTest.cpp:278 Expected equality of these values: R"( Frontend | ParseFunctionDefinition (fooB) | ParseFunctionDefinition (fooMTA) | ParseFunctionDefinition (fooA) | ParseDeclarationOrFunctionDefinition (test.cc:3:5) | | ParseFunctionDefinition (user) | PerformPendingInstantiations | | InstantiateFunction (fooA<int>, ./a.h:7) ```
2024-07-18Add source file name for template instantiations in -ftime-trace (#98320)Utkarsh Saxena
This is helpful in identifying file and location which contain the particular template declaration.
2024-07-07[llvm] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#97914)Kazu Hirata
2024-03-19Expose TimeTraceProfiler for Async Events (#83778)Takuto Ikuta
To avoid issue like https://github.com/llvm/llvm-project/issues/56554 and https://github.com/llvm/llvm-project/issues/83236 due to no guarantees for nested relationships between file level span and syntax tree level span, I'd like to have a `timeTraceAsyncProfilerBegin` specific to trace handling only `Source` spans around https://github.com/llvm/llvm-project/blob/8715f256911786520bb727ce067098d7082ac45c/clang/lib/Sema/Sema.cpp#L153-L170. This is a preparation PR to do that in [following PR](https://github.com/llvm/llvm-project/pull/83961).
2022-09-16[support] Prepare TimeProfiler for cross-thread supportmbs
This NFC prepares the TimeProfiler to support the construction and completion of time profiling 'entries' across threads. Add ClockType alias so we can change the clock in one place. (trivial) Use c++ usings instead of typedefs Rename Entry to TimeTraceProfilerEntry since this type will eventually become public. Add an intro comment. Add some smoke unit tests. Reviewed By: russell.gallop, rriddle, lattner, jloser Differential Revision: https://reviews.llvm.org/D133153
2022-08-03ManagedStatic: remove from TimeProfilerNicolai Hähnle
Differential Revision: https://reviews.llvm.org/D129121
2022-01-24Move STLFunctionalExtras out of STLExtrasserge-sans-paille
Only using that change in StringRef already decreases the number of preoprocessed lines from 7837621 to 7776151 for LLVMSupport Perhaps more interestingly, it shows that many files were relying on the inclusion of StringRef.h to have the declaration from STLExtras.h. This patch tries hard to patch relevant part of llvm-project impacted by this hidden dependency removal. Potential impact: - "llvm/ADT/StringRef.h" no longer includes <memory>, "llvm/ADT/Optional.h" nor "llvm/ADT/STLExtras.h" Related Discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-21[llvm] Cleanup header dependencies in ADT and Supportserge-sans-paille
The cleanup was manual, but assisted by "include-what-you-use". It consists in 1. Removing unused forward declaration. No impact expected. 2. Removing unused headers in .cpp files. No impact expected. 3. Removing unused headers in .h files. This removes implicit dependencies and is generally considered a good thing, but this may break downstream builds. I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the modification in the second part of the commit. 4. Replacing header inclusion by forward declaration. This has the same impact as 3. Notable changes: - llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h - llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h - llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h - llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h You may need to add some of these headers in your compilation units, if needs be. As an hint to the impact of the cleanup, running clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 8000919 lines after: 7917500 lines Reduced dependencies also helps incremental rebuilds and is more ccache friendly, something not shown by the above metric :-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2021-10-31[TimeProfiler] Reset variable to nullptrShoaib Meenai
Otherwise we'll hit a spurious assert failure when we reset and then reinitialize TimeProfiler on the same thread, as can happen when e.g. using LLD as a library and running it multiple times in the same process. Makes `lld/test/MachO/time-trace.s` pass with `LLD_IN_TEST=2`, which runs the linker twice in the same process and exposed the issue. Reviewed By: MaskRay, mehdi_amini Differential Revision: https://reviews.llvm.org/D112880
2021-10-24Use llvm::any_of and llvm::none_of (NFC)Kazu Hirata
2021-09-06[Support] Qualify auto (NFC)Kazu Hirata
Identified with readability-qualified-auto.
2021-07-16Use ManagedStatic and lazy initialization of cl::opt in libSupport to make ↵Mehdi Amini
it free of global initializer We can build it with -Werror=global-constructors now. This helps in situation where libSupport is embedded as a shared library, potential with dlopen/dlclose scenario, and when command-line parsing or other facilities may not be involved. Avoiding the implicit construction of these cl::opt can avoid double-registration issues and other kind of behavior. Reviewed By: lattner, jpienaar Differential Revision: https://reviews.llvm.org/D105959
2021-07-16Revert "Use ManagedStatic and lazy initialization of cl::opt in libSupport ↵Mehdi Amini
to make it free of global initializer" This reverts commit af9321739b20becf170e6bb5060b8d780e1dc8dd. Still some specific config broken in some way that requires more investigation.
2021-07-16Use ManagedStatic and lazy initialization of cl::opt in libSupport to make ↵Mehdi Amini
it free of global initializer We can build it with -Werror=global-constructors now. This helps in situation where libSupport is embedded as a shared library, potential with dlopen/dlclose scenario, and when command-line parsing or other facilities may not be involved. Avoiding the implicit construction of these cl::opt can avoid double-registration issues and other kind of behavior. Reviewed By: lattner, jpienaar Differential Revision: https://reviews.llvm.org/D105959
2021-07-16Revert "Use ManagedStatic and lazy initialization of cl::opt in libSupport ↵Mehdi Amini
to make it free of global initializer" This reverts commit 42f588f39c5ce6f521e3709b8871d1fdd076292f. Broke some buildbots
2021-07-16Use ManagedStatic and lazy initialization of cl::opt in libSupport to make ↵Mehdi Amini
it free of global initializer We can build it with -Werror=global-constructors now. This helps in situation where libSupport is embedded as a shared library, potential with dlopen/dlclose scenario, and when command-line parsing or other facilities may not be involved. Avoiding the implicit construction of these cl::opt can avoid double-registration issues and other kind of behavior. Reviewed By: lattner, jpienaar Differential Revision: https://reviews.llvm.org/D105959
2021-04-06[SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag ↵Abhina Sreeskantharajan
instead of OF_Text Problem: On SystemZ we need to open text files in text mode. On Windows, files opened in text mode adds a CRLF '\r\n' which may not be desirable. Solution: This patch adds two new flags - OF_CRLF which indicates that CRLF translation is used. - OF_TextWithCRLF = OF_Text | OF_CRLF indicates that the file is text and uses CRLF translation. Developers should now use either the OF_Text or OF_TextWithCRLF for text files and OF_None for binary files. If the developer doesn't want carriage returns on Windows, they should use OF_Text, if they do want carriage returns on Windows, they should use OF_TextWithCRLF. So this is the behaviour per platform with my patch: z/OS: OF_None: open in binary mode OF_Text : open in text mode OF_TextWithCRLF: open in text mode Windows: OF_None: open file with no carriage return OF_Text: open file with no carriage return OF_TextWithCRLF: open file with carriage return The Major change is in llvm/lib/Support/Windows/Path.inc to only set text mode if the OF_CRLF is set. ``` if (Flags & OF_CRLF) CrtOpenFlags |= _O_TEXT; ``` These following files are the ones that still use OF_Text which I left unchanged. I modified all these except raw_ostream.cpp in recent patches so I know these were previously in Binary mode on Windows. ./llvm/lib/Support/raw_ostream.cpp ./llvm/lib/TableGen/Main.cpp ./llvm/tools/dsymutil/DwarfLinkerForBinary.cpp ./llvm/unittests/Support/Path.cpp ./clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp ./clang/lib/Frontend/CompilerInstance.cpp ./clang/lib/Driver/Driver.cpp ./clang/lib/Driver/ToolChains/Clang.cpp Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D99426
2020-04-23[TimeProfiler] Emit clock synchronization pointSergej Jaskiewicz
Time profiler emits relative timestamps for events (the number of microseconds passed since the start of the current process). This patch allows combining events from different processes while preserving their relative timing by emitting a new attribute "beginningOfTime". This attribute contains the system time that corresponds to the zero timestamp of the time profiler. This has at least two use cases: - Build systems can use this to merge time traces from multiple compiler invocations and generate statistics for the whole build. Tools like ClangBuildAnalyzer could also leverage this feature. - Compilers that use LLVM as their backend by invoking llc/opt in a child process. If such a compiler supports generating time traces of its own events, it could merge those events with LLVM-specific events received from llc/opt, and produce a more complete time trace. A proof-of-concept script that merges multiple logs that contain a synchronization point into one log: https://github.com/broadwaylamb/merge_trace_events Differential Revision: https://reviews.llvm.org/D78030
2020-04-23[TimeProfiler] Emit real process ID and thread namesSergej Jaskiewicz
Differential Revision: https://reviews.llvm.org/D78027
2020-04-15[TimeProfiler] Fix some style issues. NFCFangrui Song
Reviewed By: broadwaylamb, russell.gallop Differential Revision: https://reviews.llvm.org/D78153
2020-03-06Refactor TimeProfiler write methods (NFC)Andrew Monshizadeh
Added a write method for TimeTrace that takes two strings representing file names. The first is any file name that may have been provided by the user via `time-trace-file` flag, and the second is a fallback that should be configured by the caller. This method makes it cleaner to write the trace output because there is no longer a need to check file names at the caller and simplifies future TimeTrace usages. Reviewed By: modocache Differential Revision: https://reviews.llvm.org/D74514
2020-01-31[Support] Wrap extern TLS variable in getter functionMarkus Böck
This patch wraps an external thread local storage variable inside of a getter function and makes it have internal linkage. This allows LLVM to be built with BUILD_SHARED_LIBS on windows with MinGW. Additionally it allows Clang versions prior to 10 to compile current trunk for MinGW. Differential Revision: https://reviews.llvm.org/D73639
2020-01-29Address implicit conversions detected by g++ 5 only.Benjamin Kramer
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-27Re-land [Support] Extend TimeProfiler to support multiple threadsRussell Gallop
This makes TimeTraceProfilerInstance thread local. Added timeTraceProfilerFinishThread() which moves the thread local instance to a global vector of instances. timeTraceProfilerWrite() then writes recorded data from all instances. Threads are identified based on their thread ids. Totals are reported with artificial thread ids higher than the real ones. This fixes the previous version to work with __thread as well as thread_local. Differential Revision: https://reviews.llvm.org/D71059
2019-12-24Revert "[Support] Extend TimeProfiler to support multiple threads"Russell Gallop
and "[Support] Try to fix bot failure after 8ddcd1dc26" This reverts commits f70f180148 and 8ddcd1dc26 as this was breaking the MacOS build, which doesn't support thread_local.
2019-12-17Revert "[Support] Fix time trace multi threaded support with ↵Russell Gallop
LLVM_ENABLE_THREADS=OFF" This reverts commit 2bbcf156acc157377e814fbb1828a9fe89367ea2. This was failing on systems which use __thread such as http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/30851
2019-12-17[Support] Fix time trace multi threaded support with LLVM_ENABLE_THREADS=OFFRussell Gallop
Following on from 8ddcd1dc26ba, which added the support. As pointed out on D71059 this does not build on some systems with LLVM_ENABLE_THREADS=OFF. Differential Revision: https://reviews.llvm.org/D71548
2019-12-12[Support] Try to fix bot failure after 8ddcd1dc26Russell Gallop
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/41755
2019-12-12[Support] Extend TimeProfiler to support multiple threadsRussell Gallop
This makes TimeTraceProfilerInstance thread local. Added timeTraceProfilerFinishThread() which moves the thread local instance to a global vector of instances. timeTraceProfilerWrite() then writes recorded data from all instances. Threads are identified based on their thread ids. Totals are reported with artificial thread ids higher than the real ones. Replaced raw pointer for TimeTraceProfilerInstance with unique_ptr. Differential Revision: https://reviews.llvm.org/D71059
2019-12-11[Support] Add TimeTraceScope constructor without detail argRussell Gallop
This simplifies code where no extra details are required Also don't write out detail when it is empty. Differential Revision: https://reviews.llvm.org/D71347
2019-12-03[Support] Add ProcName to TimeTraceProfilerRussell Gallop
This was hard-coded to "clang". This change allows it to to be used on processes other than clang (such as lld). This gets reported as clang-10 on Linux and clang.exe on Windows so adapted test to accommodate this. Differential Revision: https://reviews.llvm.org/D70950
2019-12-03[NFC] Tidy-ups to TimeProfiler.cppRussell Gallop
Remove unused include Make fields const where possible Move initialisation to initialiser list Differential Revision: https://reviews.llvm.org/D70904
2019-11-08TimeTraceProfiler - fix uninitialized variable warning. NFCI.Simon Pilgrim
2019-09-05Fix time-trace breaking flame graph assumptionsRussell Gallop
-ftime-trace could break flame-graph assumptions on Windows, with an inner scope overrunning outer scopes. This was due to the way that times were truncated. Changed this so time_points for the flame-graph are truncated instead of durations, preserving the relative order of event starts and ends. I have tried to retain the extra precision for the totals, which count thousands or millions of events. Added assert to check this property holds in future. Fixes PR43043 Differential Revision: https://reviews.llvm.org/D66411 llvm-svn: 371039
2019-08-19[Support][Time profiler] Make FE codegen blocks to be inside frontend blocksAnton Afanasyev
Summary: Add `Frontend` time trace entry to `HandleTranslationUnit()` function. Add test to check all codegen blocks are inside frontend blocks. Also, change `--time-trace-granularity` option a bit to make sure very small time blocks are outputed to json-file when using `--time-trace-granularity=0`. This fixes http://llvm.org/pr41969 Reviewers: russell.gallop, lebedev.ri, thakis Reviewed By: russell.gallop Subscribers: vsapsai, aras-p, lebedev.ri, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D63325 llvm-svn: 369308
2019-07-24[Support] Fix `-ftime-trace-granularity` optionAnton Afanasyev
Summary: Move `-ftime-trace-granularity` option to frontend options. Without patch this option is showed up in the help for any tool that links libSupport. Reviewers: sammccall Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D65202 llvm-svn: 366911
2019-04-25[Support] Add JSON streaming output API, faster where the heavy value types ↵Sam McCall
aren't needed. Summary: There's still a little bit of constant factor that could be trimmed (e.g. more overloads to avoid round-tripping primitives through json::Value). But this solves the memory scaling problem, and greatly improves the performance constant factor, and the API should leave room for optimization if needed. Adapt TimeProfiler to use it, eliminating almost all the performance regression from r358476. Performance test on my machine: perf stat -r 5 ~/llvmbuild-opt/bin/clang++ -w -S -ftime-trace -mllvm -time-trace-granularity=0 spirit.cpp Handcrafted JSON (HEAD=r358532 with r358476 reverted): 2480ms json::Value (HEAD): 2757ms (+11%) After this patch: 2520 ms (+1.6%) Reviewers: anton-afanasyev, lebedev.ri Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60804 llvm-svn: 359186
2019-04-16Time profiler: optimize json output timeAnton Afanasyev
Summary: Use llvm::json::Array.reserve() to optimize json output time. Here is motivation: https://reviews.llvm.org/D60609#1468941. In short: for the json array with ~32K entries, pushing back each entry takes ~4% of whole time compared to the method of preliminary memory reservation: (3995-3845)/3995 = 3.75%. Reviewers: lebedev.ri Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60792 llvm-svn: 358522
2019-04-16Use native llvm JSON library for time profiler outputAnton Afanasyev
Summary: Replace plain json text output with llvm JSON library wrapper using. Reviewers: takuto.ikuta, lebedev.ri Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60609 llvm-svn: 358476
2019-04-15Time profiler: small fixes and optimizationsAnton Afanasyev
Summary: Fixes from Roman's review here: https://reviews.llvm.org/D58675#1465336 Reviewers: lebedev.ri Subscribers: hiraditya, mgrang, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D60663 llvm-svn: 358448
2019-04-09Improve hashing for time profilerAnton Afanasyev
Summary: Use optimized hashing while writing time trace by join two hashes to one. Used for -ftime-trace option. Reviewers: rnk, takuto.ikuta Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60404 llvm-svn: 357998
2019-03-30Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` ↵Anton Afanasyev
compatible JSON profiling output dumps. This change adds hierarchical "time trace" profiling blocks that can be visualized in Chrome, in a "flame chart" style. Each profiling block can have a "detail" string that for example indicates the file being processed, template name being instantiated, function being optimized etc. This is taken from GitHub PR: https://github.com/aras-p/llvm-project-20170507/pull/2 Patch by Aras Pranckevičius. Differential Revision: https://reviews.llvm.org/D58675 llvm-svn: 357340