|
29 | 29 | #include "llvm/Support/Endian.h"
|
30 | 30 | #include "llvm/Support/ErrorHandling.h"
|
31 | 31 | #include "llvm/Support/FileSystem.h"
|
| 32 | +#include "llvm/Support/FormatVariadic.h" |
32 | 33 | #include "llvm/Support/MathExtras.h"
|
33 | 34 | #include "llvm/Support/MemoryBuffer.h"
|
34 | 35 | #include "llvm/Support/Path.h"
|
@@ -2227,6 +2228,28 @@ LLVM_DUMP_METHOD void SourceManager::dump() const {
|
2227 | 2228 | }
|
2228 | 2229 | }
|
2229 | 2230 |
|
| 2231 | +// 123 -> "123". |
| 2232 | +// 1234 -> "1.23k". |
| 2233 | +// 123456 -> "123.46k". |
| 2234 | +// 1234567 -> "1.23M". |
| 2235 | +// 1234567890 -> "1.23G". |
| 2236 | +// 1234567890123 -> "1.23T". |
| 2237 | +static std::string humanizeNumber(uint64_t Number) { |
| 2238 | + static constexpr std::array<std::pair<uint64_t, char>, 4> Units = { |
| 2239 | + {{1'000'000'000'000UL, 'T'}, |
| 2240 | + {1'000'000'000UL, 'G'}, |
| 2241 | + {1'000'000UL, 'M'}, |
| 2242 | + {1'000UL, 'k'}}}; |
| 2243 | + |
| 2244 | + for (const auto &[UnitSize, UnitSign] : Units) { |
| 2245 | + if (Number >= UnitSize) { |
| 2246 | + return llvm::formatv("{0:F}{1}", Number / static_cast<double>(UnitSize), |
| 2247 | + UnitSign); |
| 2248 | + } |
| 2249 | + } |
| 2250 | + return std::to_string(Number); |
| 2251 | +} |
| 2252 | + |
2230 | 2253 | void SourceManager::noteSLocAddressSpaceUsage(
|
2231 | 2254 | DiagnosticsEngine &Diag, std::optional<unsigned> MaxNotes) const {
|
2232 | 2255 | struct Info {
|
@@ -2296,22 +2319,27 @@ void SourceManager::noteSLocAddressSpaceUsage(
|
2296 | 2319 | int UsagePercent = static_cast<int>(100.0 * double(LocalUsage + LoadedUsage) /
|
2297 | 2320 | MaxLoadedOffset);
|
2298 | 2321 | Diag.Report(SourceLocation(), diag::note_total_sloc_usage)
|
2299 |
| - << LocalUsage << LoadedUsage << (LocalUsage + LoadedUsage) << UsagePercent; |
| 2322 | + << LocalUsage << humanizeNumber(LocalUsage) << LoadedUsage |
| 2323 | + << humanizeNumber(LoadedUsage) << (LocalUsage + LoadedUsage) |
| 2324 | + << humanizeNumber(LocalUsage + LoadedUsage) << UsagePercent; |
2300 | 2325 |
|
2301 | 2326 | // Produce notes on sloc address space usage for each file with a high usage.
|
2302 | 2327 | uint64_t ReportedSize = 0;
|
2303 | 2328 | for (auto &[Entry, FileInfo] :
|
2304 | 2329 | llvm::make_range(SortedUsage.begin(), SortedEnd)) {
|
2305 | 2330 | Diag.Report(FileInfo.Loc, diag::note_file_sloc_usage)
|
2306 | 2331 | << FileInfo.Inclusions << FileInfo.DirectSize
|
2307 |
| - << (FileInfo.TotalSize - FileInfo.DirectSize); |
| 2332 | + << humanizeNumber(FileInfo.DirectSize) |
| 2333 | + << (FileInfo.TotalSize - FileInfo.DirectSize) |
| 2334 | + << humanizeNumber(FileInfo.TotalSize - FileInfo.DirectSize); |
2308 | 2335 | ReportedSize += FileInfo.TotalSize;
|
2309 | 2336 | }
|
2310 | 2337 |
|
2311 | 2338 | // Describe any remaining usage not reported in the per-file usage.
|
2312 | 2339 | if (ReportedSize != CountedSize) {
|
2313 | 2340 | Diag.Report(SourceLocation(), diag::note_file_misc_sloc_usage)
|
2314 |
| - << (SortedUsage.end() - SortedEnd) << CountedSize - ReportedSize; |
| 2341 | + << (SortedUsage.end() - SortedEnd) << CountedSize - ReportedSize |
| 2342 | + << humanizeNumber(CountedSize - ReportedSize); |
2315 | 2343 | }
|
2316 | 2344 | }
|
2317 | 2345 |
|
|
0 commit comments