From 42ef796e502bfc0214b240257b62fcb7dc4fedac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 13 Jan 2008 20:08:43 +0000 Subject: [PATCH] Added a bit more tracing output to the block allocations. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23496 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../file_systems/bfs/BlockAllocator.cpp | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index 32a8efea54..c0f70b53c4 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -77,6 +77,53 @@ class Free : public AbstractTraceEntry { block_run fRun; }; + +static uint32 +checksum(const uint8 *data, size_t size) +{ + const uint32 *data4 = (const uint32 *)data; + uint32 sum = 0; + while (size >= 4) { + sum += *data4; + data4++; + size -= 4; + } + return sum; +} + + +class Block : public AbstractTraceEntry { + public: + Block(const char *label, off_t blockNumber, const uint8 *data, + size_t size) + : + fBlock(blockNumber), + fData(data) + { + strlcpy(fLabel, label, sizeof(fLabel)); + fSum = checksum(data, size); + memcpy(fBytes, data, min_c(size, sizeof(fBytes))); + Initialized(); + } + + virtual void AddDump(char *buffer, size_t size) + { + uint32 length = snprintf(buffer, size, "%s: block %Ld (%p), sum %lu," + " bytes ", fLabel, fBlock, fData, fSum); + for (uint32 i = 0; length < size - 1 && i < sizeof(fBytes); i++) { + length += snprintf(buffer + length, size - length, "%02x", + fBytes[i]); + } + } + + private: + off_t fBlock; + const uint8 *fData; + uint32 fSum; + char fLabel[12]; + uint8 fBytes[32]; +}; + } // namespace BFSBlockTracing # define T(x) new(std::nothrow) BFSBlockTracing::x; @@ -109,6 +156,7 @@ class AllocationBlock : public CachedBlock { uint32 NumBlockBits() const { return fNumBits; } uint32 &Block(int32 index) { return ((uint32 *)fBlock)[index]; } + uint8 *Block() const { return (uint8 *)fBlock; } private: uint32 fNumBits; @@ -375,6 +423,7 @@ AllocationGroup::Free(Transaction &transaction, uint16 start, int32 length) if (cached.SetToWritable(transaction, *this, block) < B_OK) RETURN_ERROR(B_IO_ERROR); + T(Block("free-1", block, cached.Block(), volume->BlockSize())); uint16 freeLength = length; if (uint32(start + length) > cached.NumBlockBits()) freeLength = cached.NumBlockBits() - start; @@ -383,6 +432,7 @@ AllocationGroup::Free(Transaction &transaction, uint16 start, int32 length) length -= freeLength; start = 0; + T(Block("free-2", block, cached.Block(), volume->BlockSize())); block++; } return B_OK; @@ -632,6 +682,8 @@ BlockAllocator::AllocateBlocks(Transaction &transaction, int32 group, if (cached.SetTo(fGroups[group], block) < B_OK) RETURN_ERROR(B_ERROR); + T(Block("alloc-in", block, cached.Block(), fVolume->BlockSize())); + // find a block large enough to hold the allocation for (uint32 bit = start % cached.NumBlockBits(); bit < cached.NumBlockBits(); bit++) { @@ -680,6 +732,8 @@ BlockAllocator::AllocateBlocks(Transaction &transaction, int32 group, // fixed anyway. T(Allocate(run)); + T(Block("alloc-out", block, cached.Block(), + fVolume->BlockSize())); return B_OK; }