Files
RedBear-OS/local/recipes/dev/libclc/source/llvm/lib/ProfileData/MemProfSummary.cpp
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

75 lines
3.2 KiB
C++

//=-- MemProfSummary.cpp - MemProf summary support ---------------=//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file contains MemProf summary support.
//
//===----------------------------------------------------------------------===//
#include "llvm/ProfileData/MemProfSummary.h"
using namespace llvm;
using namespace llvm::memprof;
void MemProfSummary::printSummaryYaml(raw_ostream &OS) const {
// For now emit as YAML comments, since they aren't read on input.
OS << "---\n";
OS << "# MemProfSummary:\n";
OS << "# Total contexts: " << NumContexts << "\n";
OS << "# Total cold contexts: " << NumColdContexts << "\n";
OS << "# Total hot contexts: " << NumHotContexts << "\n";
OS << "# Maximum cold context total size: " << MaxColdTotalSize << "\n";
OS << "# Maximum warm context total size: " << MaxWarmTotalSize << "\n";
OS << "# Maximum hot context total size: " << MaxHotTotalSize << "\n";
}
void MemProfSummary::write(ProfOStream &OS) const {
// Write the current number of fields first, which helps enable backwards and
// forwards compatibility (see comment in header).
OS.write32(memprof::MemProfSummary::getNumSummaryFields());
auto StartPos = OS.tell();
(void)StartPos;
OS.write(NumContexts);
OS.write(NumColdContexts);
OS.write(NumHotContexts);
OS.write(MaxColdTotalSize);
OS.write(MaxWarmTotalSize);
OS.write(MaxHotTotalSize);
// Sanity check that the number of fields was kept in sync with actual fields.
assert((OS.tell() - StartPos) / 8 == MemProfSummary::getNumSummaryFields());
}
std::unique_ptr<MemProfSummary>
MemProfSummary::deserialize(const unsigned char *&Ptr) {
auto NumSummaryFields =
support::endian::readNext<uint32_t, llvm::endianness::little>(Ptr);
// The initial version of the summary contains 6 fields. To support backwards
// compatibility with older profiles, if new summary fields are added (until a
// version bump) this code will need to check NumSummaryFields against the
// current value of MemProfSummary::getNumSummaryFields(). If NumSummaryFields
// is lower then default values will need to be filled in for the newer fields
// instead of trying to read them from the profile.
//
// For now, assert that the profile contains at least as many fields as
// expected by the code.
assert(NumSummaryFields >= MemProfSummary::getNumSummaryFields());
auto MemProfSum = std::make_unique<MemProfSummary>(
support::endian::read<uint64_t, llvm::endianness::little>(Ptr),
support::endian::read<uint64_t, llvm::endianness::little>(Ptr + 8),
support::endian::read<uint64_t, llvm::endianness::little>(Ptr + 16),
support::endian::read<uint64_t, llvm::endianness::little>(Ptr + 24),
support::endian::read<uint64_t, llvm::endianness::little>(Ptr + 32),
support::endian::read<uint64_t, llvm::endianness::little>(Ptr + 40));
// Enable forwards compatibility by skipping past any additional fields in the
// profile's summary.
Ptr += NumSummaryFields * sizeof(uint64_t);
return MemProfSum;
}