diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -239,7 +239,7 @@ /*Extension=*/"json", /*useTemporary=*/false); - llvm::timeTraceProfilerWrite(profilerOutput); + llvm::timeTraceProfilerWrite(*profilerOutput); llvm::timeTraceProfilerCleanup(); } diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h --- a/llvm/include/llvm/Support/TimeProfiler.h +++ b/llvm/include/llvm/Support/TimeProfiler.h @@ -1,9 +1,8 @@ //===- llvm/Support/TimeProfiler.h - Hierarchical Time Profiler -*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -33,7 +32,7 @@ /// Write profiling data to output file. /// Data produced is JSON, in Chrome "Trace Event" format, see /// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview -void timeTraceProfilerWrite(std::unique_ptr &OS); +void timeTraceProfilerWrite(raw_pwrite_stream &OS); /// Manually begin a time section, with the given \p Name and \p Detail. /// Profiler copies the string data, so the pointers can be given into @@ -51,6 +50,13 @@ /// the section; and when it is destroyed, it stops it. If the time profiler /// is not initialized, the overhead is a single branch. struct TimeTraceScope { + + TimeTraceScope() = delete; + TimeTraceScope(const TimeTraceScope &) = delete; + TimeTraceScope &operator=(const TimeTraceScope &) = delete; + TimeTraceScope(TimeTraceScope &&) = delete; + TimeTraceScope &operator=(TimeTraceScope &&) = delete; + TimeTraceScope(StringRef Name, StringRef Detail) { if (TimeTraceProfilerInstance != nullptr) timeTraceProfilerBegin(Name, Detail); diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -1,13 +1,12 @@ //===-- TimeProfiler.cpp - Hierarchical Time Profiler ---------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // -/// \file Hierarchical time profiler implementation. +// This file implements hierarchical time profiler. // //===----------------------------------------------------------------------===// @@ -41,13 +40,11 @@ struct TimeTraceProfiler { TimeTraceProfiler() { - Stack.reserve(8); - Entries.reserve(128); StartTime = steady_clock::now(); } void begin(std::string Name, llvm::function_ref Detail) { - Entry E = {steady_clock::now(), {}, Name, Detail()}; + Entry E = {steady_clock::now(), {}, std::move(Name), Detail()}; Stack.push_back(std::move(E)); } @@ -76,7 +73,7 @@ Stack.pop_back(); } - void Write(std::unique_ptr &OS) { + void Write(raw_pwrite_stream &OS) { assert(Stack.empty() && "All profiler sections should be ended when calling Write"); @@ -103,14 +100,14 @@ int Tid = 1; std::vector SortedTotals; SortedTotals.reserve(CountAndTotalPerName.size()); - for (const auto &E : CountAndTotalPerName) { + for (const auto &E : CountAndTotalPerName) SortedTotals.emplace_back(E.getKey(), E.getValue()); - } - std::sort(SortedTotals.begin(), SortedTotals.end(), - [](const NameAndCountAndDurationType &A, - const NameAndCountAndDurationType &B) { - return A.second.second > B.second.second; - }); + + llvm::sort(SortedTotals.begin(), SortedTotals.end(), + [](const NameAndCountAndDurationType &A, + const NameAndCountAndDurationType &B) { + return A.second.second > B.second.second; + }); for (const auto &E : SortedTotals) { auto DurUs = duration_cast(E.second.second).count(); auto Count = CountAndTotalPerName[E.first].first; @@ -140,12 +137,12 @@ {"args", json::Object{{"name", "clang"}}}, }); - *OS << formatv("{0:2}", json::Value(json::Object( - {{"traceEvents", std::move(Events)}}))); + OS << formatv("{0:2}", json::Value(json::Object( + {{"traceEvents", std::move(Events)}}))); } - std::vector Stack; - std::vector Entries; + SmallVector Stack; + SmallVector Entries; StringMap CountAndTotalPerName; time_point StartTime; }; @@ -161,7 +158,7 @@ TimeTraceProfilerInstance = nullptr; } -void timeTraceProfilerWrite(std::unique_ptr &OS) { +void timeTraceProfilerWrite(raw_pwrite_stream &OS) { assert(TimeTraceProfilerInstance != nullptr && "Profiler object can't be null"); TimeTraceProfilerInstance->Write(OS);