root/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.cpp
/*
 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
 * All rights reserved. Distributed under the terms of the MIT license.
 */
#include "AllocationInfo.h"

#include "DebugSupport.h"

#include "Attribute.h"
#include "Directory.h"
#include "Entry.h"
#include "File.h"
#include "SymLink.h"


AllocationInfo::AllocationInfo()
        : fNodeTableArraySize(0),
          fNodeTableVectorSize(0),
          fNodeTableElementCount(0),
          fDirectoryEntryTableArraySize(0),
          fDirectoryEntryTableVectorSize(0),
          fDirectoryEntryTableElementCount(0),

          fAttributeCount(0),
          fAttributeSize(0),
          fDirectoryCount(0),
          fEntryCount(0),
          fFileCount(0),
          fFileSize(0),
          fSymLinkCount(0),
          fSymLinkSize(0),

          fListCount(0),
          fListSize(0),
          fOtherCount(0),
          fOtherSize(0),
          fStringCount(0),
          fStringSize(0)
{
}


AllocationInfo::~AllocationInfo()
{
}


void
AllocationInfo::AddNodeTableAllocation(size_t arraySize, size_t vectorSize,
        size_t elementSize, size_t elementCount)
{
        fNodeTableArraySize += arraySize;
        fNodeTableVectorSize += vectorSize * elementSize;
        fNodeTableElementCount += elementCount;
}


void
AllocationInfo::AddDirectoryEntryTableAllocation(size_t arraySize,
        size_t vectorSize, size_t elementSize, size_t elementCount)
{
        fDirectoryEntryTableArraySize += arraySize;
        fDirectoryEntryTableVectorSize += vectorSize * elementSize;
        fDirectoryEntryTableElementCount += elementCount;
}


void
AllocationInfo::AddAttributeAllocation(size_t size)
{
        fAttributeCount++;
        fAttributeSize += size;
}


void
AllocationInfo::AddDirectoryAllocation()
{
        fDirectoryCount++;
}


void
AllocationInfo::AddEntryAllocation()
{
        fEntryCount++;
}


void
AllocationInfo::AddFileAllocation(size_t size)
{
        fFileCount++;
        fFileSize += size;
}


void
AllocationInfo::AddSymLinkAllocation(size_t size)
{
        fSymLinkCount++;
        fSymLinkSize += size;
}


void
AllocationInfo::AddListAllocation(size_t capacity, size_t elementSize)
{
        fListCount += 1;
        fListSize += capacity * elementSize;
}


void
AllocationInfo::AddOtherAllocation(size_t size, size_t count)
{
        fOtherCount += count;
        fOtherSize += size * count;
}


void
AllocationInfo::AddStringAllocation(size_t size)
{
        fStringCount++;
        fStringSize += size;
}


void
AllocationInfo::Dump() const
{
        size_t heapCount = 0;
        size_t heapSize = 0;
        size_t areaCount = 0;
        size_t areaSize = 0;

        PRINT("  node table:\n");
        PRINT("    array size:  %9lu\n", fNodeTableArraySize);
        PRINT("    vector size: %9lu\n", fNodeTableVectorSize);
        PRINT("    elements:    %9lu\n", fNodeTableElementCount);
        areaCount += 2;
        areaSize += fNodeTableArraySize * sizeof(int32) + fNodeTableVectorSize;

        PRINT("  entry table:\n");
        PRINT("    array size:  %9lu\n", fDirectoryEntryTableArraySize);
        PRINT("    vector size: %9lu\n", fDirectoryEntryTableVectorSize);
        PRINT("    elements:    %9lu\n", fDirectoryEntryTableElementCount);
        areaCount += 2;
        areaSize += fDirectoryEntryTableArraySize * sizeof(int32)
                                + fDirectoryEntryTableVectorSize;

        PRINT("  attributes:  %9lu, size: %9lu\n", fAttributeCount, fAttributeSize);
        heapCount += fAttributeCount;
        heapSize += fAttributeCount * sizeof(Attribute);

        PRINT("  directories: %9lu\n", fDirectoryCount);
        heapCount += fDirectoryCount;
        heapSize += fDirectoryCount * sizeof(Directory);

        PRINT("  entries:     %9lu\n", fEntryCount);
        heapCount += fEntryCount;
        heapSize += fEntryCount * sizeof(Entry);

        PRINT("  files:       %9lu, size: %9lu\n", fFileCount, fFileSize);
        heapCount += fFileCount;
        heapSize += fFileCount * sizeof(File);

        PRINT("  symlinks:    %9lu, size: %9lu\n", fSymLinkCount, fSymLinkSize);
        heapCount += fSymLinkCount;
        heapSize += fSymLinkCount * sizeof(SymLink);

        PRINT("  areas:       %9lu, size: %9lu\n", fAreaCount, fAreaSize);

        PRINT("  lists:       %9lu, size: %9lu\n", fListCount, fListSize);
        heapCount += fListCount;
        heapSize += fListSize;

        PRINT("  other:       %9lu, size: %9lu\n", fOtherCount, fOtherSize);
        heapCount += fOtherCount;
        heapSize += fOtherSize;

        PRINT("  strings:     %9lu, size: %9lu\n", fStringCount, fStringSize);
        heapCount += fStringCount;
        heapSize += fStringSize;

        PRINT("heap:  %9lu allocations, size: %9lu\n", heapCount, heapSize);
}