From b30384b477c04fc33e3ff6ae4cef17bb7e14a53e Mon Sep 17 00:00:00 2001 From: Slobodan Pavlic <71560161+guybrush77@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:11:28 -0500 Subject: [PATCH] Updated DumpDebug --- .clang-format | 1 - include/rapidobj/rapidobj.hpp | 90 ++++++++++++++++++++++------------- 2 files changed, 58 insertions(+), 33 deletions(-) diff --git a/.clang-format b/.clang-format index 86884bb..675f6a8 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,6 @@ AlignAfterOpenBracket: AlwaysBreak AlignConsecutiveAssignments: true AlignConsecutiveMacros: true -AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true AlignEscapedNewlines: DontAlign AlignTrailingComments: true diff --git a/include/rapidobj/rapidobj.hpp b/include/rapidobj/rapidobj.hpp index bd29a18..e6c489f 100755 --- a/include/rapidobj/rapidobj.hpp +++ b/include/rapidobj/rapidobj.hpp @@ -4,7 +4,7 @@ rapidobj - Fast Wavefront .obj file loader Licensed under the MIT License SPDX-License-Identifier: MIT -Copyright (c) 2022 Slobodan Pavlic +Copyright (c) 2024 Slobodan Pavlic Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the @@ -4434,7 +4434,8 @@ struct SharedContext final { struct Debug final { struct IO final { - std::vector n_requests{}; + std::vector num_requests{}; + std::vector num_bytes_read{}; std::vector submit_time; std::vector wait_time; } io; @@ -4824,12 +4825,14 @@ struct Reader { auto NumRequests() const noexcept { return m_num_requests; } auto SubmitTime() const noexcept { return m_submit_time; } auto WaitTime() const noexcept { return m_wait_time; } + auto BytesRead() const noexcept { return m_bytes_read; } auto Error() const noexcept { return m_error; } protected: int m_num_requests{}; std::chrono::nanoseconds m_submit_time{}; std::chrono::nanoseconds m_wait_time{}; + size_t m_bytes_read{}; std::error_code m_error{}; }; @@ -4916,13 +4919,21 @@ struct FileReader : Reader { auto t1 = std::chrono::steady_clock::now(); auto result = pread64(m_fd, m_buffer, m_size, m_offset); - auto error = result >= 0 ? std::error_code() : std::error_code(errno, std::system_category()); auto t2 = std::chrono::steady_clock::now(); m_wait_time += t2 - t1; - return error ? ReadResult{ 0, error } : ReadResult{ static_cast(result), error }; + if (result < 0) { + auto error = std::error_code(errno, std::system_category()); + return ReadResult{ 0, error }; + } + + auto bytes_read = static_cast(result); + + m_bytes_read += bytes_read; + + return ReadResult{ bytes_read, std::error_code() }; } private: @@ -5053,21 +5064,22 @@ struct FileReader : Reader { auto t1 = std::chrono::steady_clock::now(); auto bytes_read = DWORD{}; - auto error = std::error_code(); bool success = GetOverlappedResult(m_handle, &m_overlapped, &bytes_read, TRUE); + auto t2 = std::chrono::steady_clock::now(); + + m_wait_time += t2 - t1; + if (!success) { if (auto ec = GetLastError(); ec != ERROR_HANDLE_EOF) { - bytes_read = 0; - error = std::error_code(ec, std::system_category()); + auto error = std::error_code(ec, std::system_category()); + return ReadResult{ 0, error }; } } - auto t2 = std::chrono::steady_clock::now(); - - m_wait_time += t2 - t1; + m_bytes_read += bytes_read; - return { bytes_read, error }; + return { bytes_read, std::error_code() }; } private: @@ -5170,19 +5182,22 @@ struct FileReader : Reader { { auto t1 = std::chrono::steady_clock::now(); - auto n_bytes_read = pread(m_fd, m_buffer, m_size, m_offset); - auto error = std::error_code(); - - if (n_bytes_read == -1) { - n_bytes_read = 0; - error = std::error_code(errno, std::system_category()); - } + auto result = pread(m_fd, m_buffer, m_size, m_offset); auto t2 = std::chrono::steady_clock::now(); m_wait_time += t2 - t1; - return { static_cast(n_bytes_read), error }; + if (result < 0) { + auto error = std::error_code(errno, std::system_category()); + return ReadResult{ 0, error }; + } + + auto bytes_read = static_cast(result); + + m_bytes_read += bytes_read; + + return ReadResult{ bytes_read, std::error_code() }; } private: @@ -5236,6 +5251,8 @@ struct StreamReader : Reader { m_wait_time += t2 - t1; + m_bytes_read += result.bytes_read; + return result; } @@ -5361,14 +5378,16 @@ inline std::string ComputeDebugStats(const std::vector return text; } -inline std::string DumpDebug(const sys::File& file, const SharedContext& context) +inline std::string DumpDebug(const SharedContext& context) { auto text = std::string(); - auto population = std::vector(context.debug.io.n_requests.size()); + auto population = std::vector(context.debug.io.num_requests.size()); - for (size_t i = 0; i != context.debug.io.n_requests.size(); ++i) { - auto n = context.debug.io.n_requests[i]; + auto num_bytes_read = size_t{}; + + for (size_t i = 0; i != context.debug.io.num_requests.size(); ++i) { + auto n = context.debug.io.num_requests[i]; auto submit_ns = context.debug.io.submit_time[i]; auto wait_ns = context.debug.io.wait_time[i]; auto total_ns = submit_ns.count() + wait_ns.count(); @@ -5382,6 +5401,8 @@ inline std::string DumpDebug(const sys::File& file, const SharedContext& context population[i] = std::chrono::nanoseconds{ total_ns }; + num_bytes_read += context.debug.io.num_bytes_read[i]; + text.append(thread); text.append(": blk").append(requests); text.append(" read").append(submit); @@ -5395,7 +5416,7 @@ inline std::string DumpDebug(const sys::File& file, const SharedContext& context text.append(ComputeDebugStats(population)); text.push_back('\n'); - for (size_t i = 0; i != context.debug.io.n_requests.size(); ++i) { + for (size_t i = 0; i != context.debug.io.num_requests.size(); ++i) { auto parse_ns = context.debug.parse.time[i]; auto io_ns = context.debug.io.submit_time[i] + context.debug.io.wait_time[i]; auto io_percentage = static_cast(0.5f + 100.0f * io_ns.count() / parse_ns.count()); @@ -5417,7 +5438,7 @@ inline std::string DumpDebug(const sys::File& file, const SharedContext& context auto total = parse_total + merge_total; auto parse_percentage = static_cast(0.5f + 100.0f * parse_total.count() / total.count()); auto merge_percentage = 100 - parse_percentage; - auto bytes_per_second = file.size() / (parse_total.count() / 1000'000'000.0); + auto bytes_per_second = num_bytes_read / (parse_total.count() / 1000'000'000.0); text.append("Parse Time: "); text.append(ToString(parse_total, 10)); @@ -6153,7 +6174,8 @@ inline void DispatchMergeTasks(const MergeTasks& tasks, std::shared_ptrmerging.mutex); if (context->merging.error == rapidobj_errc::Success) { context->merging.error = rc; @@ -7027,7 +7049,8 @@ inline void ProcessBlocks( auto parse_time = t2 - t1; - context->debug.io.n_requests[thread_index] = reader->NumRequests(); + context->debug.io.num_requests[thread_index] = reader->NumRequests(); + context->debug.io.num_bytes_read[thread_index] = reader->BytesRead(); context->debug.io.submit_time[thread_index] = reader->SubmitTime(); context->debug.io.wait_time[thread_index] = reader->WaitTime(); context->debug.parse.time[thread_index] = parse_time; @@ -7040,7 +7063,8 @@ inline void ParseFileSequential(sys::File* file, std::vector* chunks, std chunks->resize(1); - context->debug.io.n_requests.resize(1); + context->debug.io.num_requests.resize(1); + context->debug.io.num_bytes_read.resize(1); context->debug.io.submit_time.resize(1); context->debug.io.wait_time.resize(1); context->debug.parse.time.resize(1); @@ -7088,7 +7112,8 @@ inline void ParseFileParallel(sys::File* file, std::vector* chunks, std:: context->thread.concurrency = num_threads; context->parsing.thread_count = num_tasks; - context->debug.io.n_requests.resize(num_threads); + context->debug.io.num_requests.resize(num_threads); + context->debug.io.num_bytes_read.resize(num_threads); context->debug.io.submit_time.resize(num_threads); context->debug.io.wait_time.resize(num_threads); context->debug.parse.time.resize(num_threads); @@ -7179,7 +7204,7 @@ inline Result ParseFile(const std::filesystem::path& filepath, const MaterialLib context->debug.merge.total_time = t2 - t1; - // std::cout << DumpDebug(file, *context); + // std::cout << DumpDebug(*context); auto memory = size_t{ 0 }; @@ -7231,7 +7256,8 @@ inline Result ParseStream(std::istream& is, const MaterialLibrary& material_libr context->thread.concurrency = 1; context->parsing.thread_count = 1; - context->debug.io.n_requests.resize(1); + context->debug.io.num_requests.resize(1); + context->debug.io.num_bytes_read.resize(1); context->debug.io.submit_time.resize(1); context->debug.io.wait_time.resize(1); context->debug.parse.time.resize(1); @@ -7256,7 +7282,7 @@ inline Result ParseStream(std::istream& is, const MaterialLibrary& material_libr context->debug.merge.total_time = t2 - t1; - // std::cout << DumpDebug(file, *context); + // std::cout << DumpDebug(*context); // Free memory in a different thread if (SizeInBytes(chunks.front()) > kMemoryRecyclingSize) {