/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "AssetMemoryAnalyzer_precompiled.h" #include "ExportCSV.h" #include "AssetMemoryAnalyzer.h" #include "AssetMemoryAnalyzerSystemComponent.h" #include "FormatUtils.h" #include namespace AssetMemoryAnalyzer { ExportCSV::ExportCSV() { } ExportCSV::~ExportCSV() { } void ExportCSV::Init(AssetMemoryAnalyzerSystemComponent* owner) { m_owner = owner; } void ExportCSV::OutputCSV(const char* path) { using namespace Data; AZStd::shared_ptr analysis = m_owner->GetAnalysis(); if (!analysis) { return; } auto fs = AZ::IO::FileIOBase::GetDirectInstance(); AZ::IO::HandleType hdl; if (!fs->Open(path, AZ::IO::OpenMode::ModeWrite, hdl)) { AZ_Assert(false, "Unable to open file for writing: %s", path); } const AZStd::string header("Label,Heap Count,Heap kb,VRAM Count,VRAM kb\n"); fs->Write(hdl, header.c_str(), header.length()); char lineBuffer[4096]; const auto& rootAsset = analysis->GetRootAsset(); size_t length = snprintf(lineBuffer, sizeof(lineBuffer), ",%d,%0.2f,%d,%0.2f\n", rootAsset.m_localSummary[(int)AllocationCategories::HEAP].m_allocationCount, rootAsset.m_localSummary[(int)AllocationCategories::HEAP].m_allocatedMemory / 1024.0f, rootAsset.m_localSummary[(int)AllocationCategories::VRAM].m_allocationCount, rootAsset.m_localSummary[(int)AllocationCategories::VRAM].m_allocatedMemory / 1024.0f ); fs->Write(hdl, lineBuffer, length); for (const auto& child : analysis->GetRootAsset().m_childAssets) { length = snprintf(lineBuffer, sizeof(lineBuffer), "%s,%d,%0.2f,%d,%0.2f\n", child.m_id, child.m_totalSummary[(int)AllocationCategories::HEAP].m_allocationCount, child.m_totalSummary[(int)AllocationCategories::HEAP].m_allocatedMemory / 1024.0f, child.m_totalSummary[(int)AllocationCategories::VRAM].m_allocationCount, child.m_totalSummary[(int)AllocationCategories::VRAM].m_allocatedMemory / 1024.0f ); fs->Write(hdl, lineBuffer, length); } fs->Close(hdl); AZ_Printf("Debug", "Exported asset allocation list to %s", path); } }