Skip to content

Commit 02c015d

Browse files
committed
Add logging and telemetry
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60673160
1 parent 8de590f commit 02c015d

File tree

9 files changed

+68
-15
lines changed

9 files changed

+68
-15
lines changed

lldb/include/lldb/Target/Statistics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ class TargetStats {
184184
void SetFirstPrivateStopTime();
185185
void SetFirstPublicStopTime();
186186
void IncreaseSourceMapDeduceCount();
187+
void IncreaseSourceRealpathAttemptCount();
188+
void IncreaseSourceRealpathCompatibleCount();
187189

188190
StatsDuration &GetCreateTime() { return m_create_time; }
189191
StatsSuccessFail &GetExpressionStats() { return m_expr_eval; }
@@ -198,6 +200,8 @@ class TargetStats {
198200
StatsSuccessFail m_frame_var{"frameVariable"};
199201
std::vector<intptr_t> m_module_identifiers;
200202
uint32_t m_source_map_deduce_count = 0;
203+
uint32_t m_source_realpath_attempt_count = 0;
204+
uint32_t m_source_realpath_compatible_count = 0;
201205
void CollectStats(Target &target);
202206
};
203207

lldb/include/lldb/Utility/RealpathPrefixes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace lldb_private {
2020
class FileSpec;
2121
class FileSpecList;
22+
class Target;
2223
} // namespace lldb_private
2324

2425
namespace lldb_private {
@@ -35,6 +36,10 @@ class RealpathPrefixes {
3536
// filesystem will be used.
3637
void SetFileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs);
3738

39+
// Sets an optional Target instance to gather statistics.
40+
void SetTarget(Target *target) { m_target = target; }
41+
Target *GetTarget() const { return m_target; }
42+
3843
std::optional<FileSpec> ResolveSymlinks(const FileSpec &file_spec) const;
3944

4045
private:
@@ -48,6 +53,9 @@ class RealpathPrefixes {
4853

4954
// The filesystem to use for realpath'ing.
5055
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
56+
57+
// The optional Target instance to gather statistics.
58+
Target *m_target;
5159
};
5260

5361
} // namespace lldb_private

lldb/source/Target/Statistics.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ TargetStats::ToJSON(Target &target,
192192
}
193193
target_metrics_json.try_emplace("sourceMapDeduceCount",
194194
m_source_map_deduce_count);
195+
target_metrics_json.try_emplace("sourceRealpathAttemptCount",
196+
m_source_realpath_attempt_count);
197+
target_metrics_json.try_emplace("sourceRealpathCompatibleCount",
198+
m_source_realpath_compatible_count);
195199
return target_metrics_json;
196200
}
197201

@@ -220,6 +224,14 @@ void TargetStats::IncreaseSourceMapDeduceCount() {
220224
++m_source_map_deduce_count;
221225
}
222226

227+
void TargetStats::IncreaseSourceRealpathAttemptCount() {
228+
++m_source_realpath_attempt_count;
229+
}
230+
231+
void TargetStats::IncreaseSourceRealpathCompatibleCount() {
232+
++m_source_realpath_compatible_count;
233+
}
234+
223235
bool DebuggerStats::g_collecting_stats = false;
224236

225237
llvm::json::Value DebuggerStats::ReportStatistics(

lldb/source/Target/Target.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4359,7 +4359,9 @@ InlineStrategy TargetProperties::GetInlineStrategy() const {
43594359
// this because we want the FileSpecList to normalize the file paths for us.
43604360
RealpathPrefixes TargetProperties::GetSourceRealpathPrefixes() const {
43614361
const uint32_t idx = ePropertySourceRealpathPrefixes;
4362-
return RealpathPrefixes(GetPropertyAtIndexAs<FileSpecList>(idx, {}));
4362+
auto prefixes = RealpathPrefixes(GetPropertyAtIndexAs<FileSpecList>(idx, {}));
4363+
prefixes.SetTarget(this->m_target);
4364+
return prefixes;
43634365
}
43644366

43654367
llvm::StringRef TargetProperties::GetArg0() const {

lldb/source/Utility/FileSpecList.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Utility/FileSpecList.h"
10+
#include "lldb/Target/Statistics.h"
11+
#include "lldb/Target/Target.h"
1012
#include "lldb/Utility/ConstString.h"
13+
#include "lldb/Utility/LLDBLog.h"
14+
#include "lldb/Utility/Log.h"
1115
#include "lldb/Utility/RealpathPrefixes.h"
1216
#include "lldb/Utility/Stream.h"
1317

@@ -176,8 +180,17 @@ size_t SupportFileList::FindCompatibleIndex(
176180
if (realpath_prefixes && result == IsCompatibleResult::kOnlyFileMatch) {
177181
if (std::optional<FileSpec> resolved_curr_file =
178182
realpath_prefixes->ResolveSymlinks(curr_file)) {
179-
if (IsCompatible(*resolved_curr_file, file_spec))
183+
if (IsCompatible(*resolved_curr_file, file_spec)) {
184+
// Stats and logging.
185+
if (Target *target = realpath_prefixes->GetTarget())
186+
target->GetStatistics().IncreaseSourceRealpathCompatibleCount();
187+
Log *log = GetLog(LLDBLog::Source);
188+
LLDB_LOGF(log,
189+
"Realpath'ed support file %s is compatible to input file",
190+
resolved_curr_file->GetPath().c_str());
191+
// We found a match
180192
return idx;
193+
}
181194
}
182195
}
183196
}

lldb/source/Utility/RealpathPrefixes.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88

99
#include "lldb/Utility/RealpathPrefixes.h"
1010

11-
#include "lldb/Host/FileSystem.h"
11+
#include "lldb/Target/Statistics.h"
12+
#include "lldb/Target/Target.h"
1213
#include "lldb/Utility/FileSpec.h"
1314
#include "lldb/Utility/FileSpecList.h"
15+
#include "lldb/Utility/LLDBLog.h"
16+
#include "lldb/Utility/Log.h"
1417

1518
using namespace lldb_private;
1619

1720
RealpathPrefixes::RealpathPrefixes(const FileSpecList &file_spec_list)
18-
: m_fs(llvm::vfs::getRealFileSystem()) {
21+
: m_fs(llvm::vfs::getRealFileSystem()), m_target(nullptr) {
1922
m_prefixes.reserve(file_spec_list.GetSize());
2023
for (const FileSpec &file_spec : file_spec_list) {
2124
m_prefixes.emplace_back(file_spec.GetPath());
@@ -39,12 +42,18 @@ RealpathPrefixes::ResolveSymlinks(const FileSpec &file_spec) const {
3942
std::string file_spec_path = file_spec.GetPath();
4043
for (const std::string &prefix : m_prefixes) {
4144
if (is_prefix(file_spec_path, prefix, file_spec.IsCaseSensitive())) {
45+
// Stats and logging.
46+
if (m_target)
47+
m_target->GetStatistics().IncreaseSourceRealpathAttemptCount();
48+
Log *log = GetLog(LLDBLog::Source);
49+
LLDB_LOGF(log, "Realpath'ing support file %s", file_spec_path.c_str());
50+
4251
// One prefix matched. Try to realpath.
4352
llvm::SmallString<PATH_MAX> buff;
4453
std::error_code ec = m_fs->getRealPath(file_spec_path, buff);
4554
if (ec)
4655
return std::nullopt;
47-
FileSpec realpath(buff);
56+
FileSpec realpath(buff, file_spec.GetPathStyle());
4857

4958
// Only return realpath if it is different from the original file_spec.
5059
if (realpath != file_spec)

lldb/unittests/Utility/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ add_lldb_unittest(UtilityTests
5151
XcodeSDKTest.cpp
5252

5353
LINK_LIBS
54+
lldbTarget
5455
lldbUtility
5556
lldbUtilityHelpers
5657
LLVMTestingSupport

lldb/unittests/Utility/MockSymlinkFileSystem.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ class MockSymlinkFileSystem : public llvm::vfs::FileSystem {
2020

2121
/// Treat \a symlink as a symlink to \a realpath. Treat all other files as
2222
/// non-symlinks.
23-
MockSymlinkFileSystem(FileSpec &&symlink, FileSpec &&realpath)
24-
: m_symlink(std::move(symlink)), m_realpath(std::move(realpath)) {}
23+
MockSymlinkFileSystem(FileSpec &&symlink, FileSpec &&realpath,
24+
FileSpec::Style style = FileSpec::Style::native)
25+
: m_symlink(std::move(symlink)), m_realpath(std::move(realpath)),
26+
m_style(style) {}
2527

2628
/// If \a Path matches the symlink given in the ctor, put the realpath given
2729
/// in the ctor into \a Output.
2830
std::error_code getRealPath(const llvm::Twine &Path,
2931
llvm::SmallVectorImpl<char> &Output) override {
30-
if (FileSpec(Path.str()) == m_symlink) {
32+
if (FileSpec(Path.str(), m_style) == m_symlink) {
3133
std::string path = m_realpath.GetPath();
3234
Output.assign(path.begin(), path.end());
3335
} else {
@@ -58,6 +60,7 @@ class MockSymlinkFileSystem : public llvm::vfs::FileSystem {
5860
private:
5961
FileSpec m_symlink;
6062
FileSpec m_realpath;
63+
FileSpec::Style m_style;
6164
};
6265

6366
} // namespace lldb_private

lldb/unittests/Utility/RealpathPrefixesTest.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,24 @@ TEST(RealpathPrefixesTest, MatchingRelativePrefix) {
5151
EXPECT_EQ(ret, FileSpec("dir2/real.h"));
5252
}
5353

54-
// Should resolve a symlink which match a prefix with a case-insensitive support
55-
// file
56-
TEST(RealpathPrefixesTest, CaseInsensitive) {
54+
// Should resolve in Windows and/or with a case-insensitive support file
55+
TEST(RealpathPrefixesTest, WindowsAndCaseInsensitive) {
5756
// Prepare FS
5857
llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem(
59-
FileSpec("/dir1/link.h"), FileSpec("/dir2/real.h")));
58+
FileSpec("f:\\dir1\\link.h", FileSpec::Style::windows),
59+
FileSpec("f:\\dir2\\real.h", FileSpec::Style::windows),
60+
FileSpec::Style::windows));
6061

6162
// Prepare RealpathPrefixes
6263
FileSpecList file_spec_list;
63-
file_spec_list.EmplaceBack("/dir1");
64+
file_spec_list.EmplaceBack(FileSpec("f:\\dir1", FileSpec::Style::windows));
6465
RealpathPrefixes prefixes(std::move(file_spec_list));
6566
prefixes.SetFileSystem(fs);
6667

6768
// Test
6869
std::optional<FileSpec> ret = prefixes.ResolveSymlinks(
69-
FileSpec("/DIR1/LINK.H", FileSpec::Style::posix));
70-
EXPECT_EQ(ret, FileSpec("/dir2/real.h"));
70+
FileSpec("F:\\DIR1\\LINK.H", FileSpec::Style::windows));
71+
EXPECT_EQ(ret, FileSpec("f:\\dir2\\real.h", FileSpec::Style::windows));
7172
}
7273

7374
// Should resolve a symlink when there is mixture of matching and mismatching

0 commit comments

Comments
 (0)