Skip to content

Commit 66ed0cc

Browse files
committed
[clang-doc] address pr comments
1 parent 6c93f48 commit 66ed0cc

File tree

6 files changed

+34
-39
lines changed

6 files changed

+34
-39
lines changed

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, T I) {
671671

672672
template <>
673673
llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, Reference *I) {
674-
llvm::TimeTraceScope("clang-doc", "readRecord Reference");
674+
llvm::TimeTraceScope("readRecord");
675675
Record R;
676676
llvm::StringRef Blob;
677677
llvm::Expected<unsigned> MaybeRecID = Stream.readRecord(ID, R, &Blob);
@@ -683,7 +683,7 @@ llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, Reference *I) {
683683
// Read a block of records into a single info.
684684
template <typename T>
685685
llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
686-
llvm::TimeTraceScope("readBlock", "ClangDocBitcodeReader");
686+
llvm::TimeTraceScope("readBlock");
687687
if (llvm::Error Err = Stream.EnterSubBlock(ID))
688688
return Err;
689689

@@ -714,7 +714,7 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
714714

715715
template <typename T>
716716
llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
717-
llvm::TimeTraceScope("readSubBlock", "ClangDocBitcodeReader");
717+
llvm::TimeTraceScope("readSubBlock");
718718
switch (ID) {
719719
// Blocks can only have certain types of sub blocks.
720720
case BI_COMMENT_BLOCK_ID: {
@@ -821,7 +821,7 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
821821

822822
ClangDocBitcodeReader::Cursor
823823
ClangDocBitcodeReader::skipUntilRecordOrBlock(unsigned &BlockOrRecordID) {
824-
llvm::TimeTraceScope("skipUntilRecordOrBlock", "ClangDocBitcodeReader");
824+
llvm::TimeTraceScope("skipUntilRecordOrBlock");
825825
BlockOrRecordID = 0;
826826

827827
while (!Stream.AtEndOfStream()) {
@@ -883,7 +883,7 @@ llvm::Error ClangDocBitcodeReader::validateStream() {
883883
}
884884

885885
llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
886-
llvm::TimeTraceScope("readBlockInfoBlock", "ClangDocBitcodeReader");
886+
llvm::TimeTraceScope("readBlockInfoBlock");
887887
Expected<std::optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
888888
Stream.ReadBlockInfoBlock();
889889
if (!MaybeBlockInfo)
@@ -900,7 +900,7 @@ llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
900900
template <typename T>
901901
llvm::Expected<std::unique_ptr<Info>>
902902
ClangDocBitcodeReader::createInfo(unsigned ID) {
903-
llvm::TimeTraceScope("createInfo", "ClangDocBitcodeReader");
903+
llvm::TimeTraceScope("createInfo");
904904
std::unique_ptr<Info> I = std::make_unique<T>();
905905
if (auto Err = readBlock(ID, static_cast<T *>(I.get())))
906906
return std::move(Err);
@@ -909,7 +909,7 @@ ClangDocBitcodeReader::createInfo(unsigned ID) {
909909

910910
llvm::Expected<std::unique_ptr<Info>>
911911
ClangDocBitcodeReader::readBlockToInfo(unsigned ID) {
912-
llvm::TimeTraceScope("readBlockToInfo", "ClangDocBitcodeReader");
912+
llvm::TimeTraceScope("readBlockToInfo");
913913
switch (ID) {
914914
case BI_NAMESPACE_BLOCK_ID:
915915
return createInfo<NamespaceInfo>(ID);

clang-tools-extra/clang-doc/Mapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace doc {
2020

2121
void MapASTVisitor::HandleTranslationUnit(ASTContext &Context) {
2222
if (CDCtx.FTimeTrace)
23-
llvm::timeTraceProfilerInitialize(CDCtx.Granularity, "clang-doc");
23+
llvm::timeTraceProfilerInitialize(200, "clang-doc");
2424
TraverseDecl(Context.getTranslationUnitDecl());
2525
if (CDCtx.FTimeTrace)
2626
llvm::timeTraceProfilerFinishThread();
@@ -35,7 +35,7 @@ template <typename T> bool MapASTVisitor::mapDecl(const T *D) {
3535
if (D->getParentFunctionOrMethod())
3636
return true;
3737

38-
llvm::timeTraceProfilerBegin("emit info phase", "emit info");
38+
llvm::timeTraceProfilerBegin("emitInfo", "emit info from ast node");
3939
llvm::SmallString<128> USR;
4040
// If there is an error generating a USR for the decl, skip this decl.
4141
if (index::generateUSRForDecl(D, USR))
@@ -48,7 +48,7 @@ template <typename T> bool MapASTVisitor::mapDecl(const T *D) {
4848
IsFileInRootDir, CDCtx.PublicOnly);
4949
llvm::timeTraceProfilerEnd();
5050

51-
llvm::timeTraceProfilerBegin("serializing info", "serializing");
51+
llvm::timeTraceProfilerBegin("serialize", "serialize info");
5252
// A null in place of I indicates that the serializer is skipping this decl
5353
// for some reason (e.g. we're only reporting public decls).
5454
if (I.first)

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ void Index::sort() {
366366

367367
ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
368368
StringRef ProjectName, bool PublicOnly,
369-
bool FTimeTrace, int Granularity,
370369
StringRef OutDirectory, StringRef SourceRoot,
371370
StringRef RepositoryUrl,
372-
std::vector<std::string> UserStylesheets)
371+
std::vector<std::string> UserStylesheets,
372+
bool FTimeTrace)
373373
: ECtx(ECtx), ProjectName(ProjectName), PublicOnly(PublicOnly),
374-
FTimeTrace(FTimeTrace), Granularity(Granularity),
375-
OutDirectory(OutDirectory), UserStylesheets(UserStylesheets) {
374+
OutDirectory(OutDirectory), UserStylesheets(UserStylesheets),
375+
FTimeTrace(FTimeTrace) {
376376
llvm::SmallString<128> SourceRootDir(SourceRoot);
377377
if (SourceRoot.empty())
378378
// If no SourceRoot was provided the current path is used as the default

clang-tools-extra/clang-doc/Representation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,10 @@ mergeInfos(std::vector<std::unique_ptr<Info>> &Values);
480480
struct ClangDocContext {
481481
ClangDocContext() = default;
482482
ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName,
483-
bool PublicOnly, bool FTimeTrace, int Granularity,
484-
StringRef OutDirectory, StringRef SourceRoot,
483+
bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot,
485484
StringRef RepositoryUrl,
486-
std::vector<std::string> UserStylesheets);
485+
std::vector<std::string> UserStylesheets,
486+
bool FTimeTrace = false);
487487
tooling::ExecutionContext *ECtx;
488488
std::string ProjectName; // Name of project clang-doc is documenting.
489489
bool PublicOnly; // Indicates if only public declarations are documented.

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ Turn on time profiler. Generates clang-doc-tracing.json)"),
105105
llvm::cl::init(false),
106106
llvm::cl::cat(ClangDocCategory));
107107

108-
static llvm::cl::opt<int> FTimeGranularity("ftime-gran", llvm::cl::desc(R"(
109-
Specify granularity for ftime-trace defaults to 200)"),
110-
llvm::cl::init(200),
111-
llvm::cl::cat(ClangDocCategory));
112-
113108
enum OutputFormatTy {
114109
md,
115110
yaml,
@@ -242,9 +237,9 @@ Example usage for a project using a compile commands database:
242237

243238
// turns on ftime trace profiling
244239
if (FTimeTrace)
245-
llvm::timeTraceProfilerInitialize(FTimeGranularity, "clang-doc");
240+
llvm::timeTraceProfilerInitialize(200, "clang-doc");
246241

247-
llvm::TimeTraceScope("clang-doc", "main");
242+
llvm::TimeTraceScope("main", "clang-doc");
248243

249244
// Fail early if an invalid format was provided.
250245
std::string Format = getFormatString();
@@ -266,12 +261,11 @@ Example usage for a project using a compile commands database:
266261
Executor->get()->getExecutionContext(),
267262
ProjectName,
268263
PublicOnly,
269-
FTimeTrace,
270-
FTimeGranularity,
271264
OutDirectory,
272265
SourceRoot,
273266
RepositoryUrl,
274-
{UserStylesheets.begin(), UserStylesheets.end()}};
267+
{UserStylesheets.begin(), UserStylesheets.end()},
268+
FTimeTrace};
275269

276270
if (Format == "html") {
277271
if (auto Err = getHtmlAssetFiles(argv[0], CDCtx)) {
@@ -280,7 +274,7 @@ Example usage for a project using a compile commands database:
280274
}
281275
}
282276

283-
llvm::timeTraceProfilerBegin("mapping phase", "mapping");
277+
llvm::timeTraceProfilerBegin("mapping decls", "clang-doc");
284278
// Mapping phase
285279
llvm::outs() << "Mapping decls...\n";
286280
auto Err =
@@ -300,7 +294,7 @@ Example usage for a project using a compile commands database:
300294
// Collect values into output by key.
301295
// In ToolResults, the Key is the hashed USR and the value is the
302296
// bitcode-encoded representation of the Info object.
303-
llvm::timeTraceProfilerBegin("clang-doc", "collection phase");
297+
llvm::timeTraceProfilerBegin("collecting infos", "clang-doc");
304298
llvm::outs() << "Collecting infos...\n";
305299
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
306300
Executor->get()->getToolResults()->forEachResult(
@@ -316,7 +310,7 @@ Example usage for a project using a compile commands database:
316310
llvm::StringMap<std::unique_ptr<doc::Info>> USRToInfo;
317311

318312
// First reducing phase (reduce all decls into one info per decl).
319-
llvm::timeTraceProfilerBegin("reduction phase", "reducing");
313+
llvm::timeTraceProfilerBegin("reducing infos", "clang-doc");
320314
llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
321315
std::atomic<bool> Error;
322316
Error = false;
@@ -326,9 +320,9 @@ Example usage for a project using a compile commands database:
326320
for (auto &Group : USRToBitcode) {
327321
Pool.async([&]() {
328322
if (FTimeTrace)
329-
llvm::timeTraceProfilerInitialize(FTimeGranularity, "clang-doc");
323+
llvm::timeTraceProfilerInitialize(200, "clang-doc");
330324

331-
llvm::timeTraceProfilerBegin("decoding bitcode phase", "decoding");
325+
llvm::timeTraceProfilerBegin("decoding bitcode", "decoding");
332326
std::vector<std::unique_ptr<doc::Info>> Infos;
333327
for (auto &Bitcode : Group.getValue()) {
334328
llvm::BitstreamCursor Stream(Bitcode);
@@ -344,7 +338,7 @@ Example usage for a project using a compile commands database:
344338
}
345339
llvm::timeTraceProfilerEnd();
346340

347-
llvm::timeTraceProfilerBegin("merging bitcode phase", "merging");
341+
llvm::timeTraceProfilerBegin("merging infos", "clang-doc");
348342
auto Reduced = doc::mergeInfos(Infos);
349343
if (!Reduced) {
350344
llvm::errs() << llvm::toString(Reduced.takeError());
@@ -358,6 +352,7 @@ Example usage for a project using a compile commands database:
358352
clang::doc::Generator::addInfoToIndex(CDCtx.Idx, Reduced.get().get());
359353
}
360354
// Save in the result map (needs a lock due to threaded access).
355+
361356
{
362357
std::lock_guard<llvm::sys::Mutex> Guard(USRToInfoMutex);
363358
USRToInfo[Group.getKey()] = std::move(Reduced.get());
@@ -374,7 +369,7 @@ Example usage for a project using a compile commands database:
374369
if (Error)
375370
return 1;
376371

377-
llvm::timeTraceProfilerBegin("generating phase", "generating");
372+
llvm::timeTraceProfilerBegin("generating docs", "clang-doc");
378373
// Ensure the root output directory exists.
379374
if (std::error_code Err = llvm::sys::fs::create_directories(OutDirectory);
380375
Err != std::error_code()) {
@@ -401,11 +396,11 @@ Example usage for a project using a compile commands database:
401396
std::error_code EC;
402397
llvm::raw_fd_ostream OS("clang-doc-tracing.json", EC,
403398
llvm::sys::fs::OF_Text);
404-
if (!EC) {
399+
if (!EC)
405400
llvm::timeTraceProfilerWrite(OS);
406-
} else {
407-
llvm::errs() << "Error opening file: " << EC.message() << "\n";
408-
}
401+
else
402+
return 1;
403+
409404
}
410405
return 0;
411406
}

clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ClangDocContext
3030
getClangDocContext(std::vector<std::string> UserStylesheets = {},
3131
StringRef RepositoryUrl = "") {
3232
ClangDocContext CDCtx{
33-
{}, "test-project", {}, {}, {}, {}, {}, RepositoryUrl, UserStylesheets};
33+
{}, "test-project", {}, {}, {}, RepositoryUrl, UserStylesheets};
3434
CDCtx.UserStylesheets.insert(
3535
CDCtx.UserStylesheets.begin(),
3636
"../share/clang/clang-doc-default-stylesheet.css");

0 commit comments

Comments
 (0)