From 398c23f4071bfd2836fc0758f0f505bdb02db996 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Thu, 19 Sep 2024 16:07:55 +0000 Subject: [PATCH 01/47] my changes for old interface --- src/clp_ffi_js/ir/LogViewerEvent.hpp | 61 +++++++++++++ src/clp_ffi_js/ir/StreamReader.cpp | 125 +++++++++++++++++++++------ src/clp_ffi_js/ir/StreamReader.hpp | 21 ++++- 3 files changed, 178 insertions(+), 29 deletions(-) create mode 100644 src/clp_ffi_js/ir/LogViewerEvent.hpp diff --git a/src/clp_ffi_js/ir/LogViewerEvent.hpp b/src/clp_ffi_js/ir/LogViewerEvent.hpp new file mode 100644 index 00000000..4a154e7d --- /dev/null +++ b/src/clp_ffi_js/ir/LogViewerEvent.hpp @@ -0,0 +1,61 @@ +#ifndef CLP_IR_LOG_VIEWER_EVENT_HPP +#define CLP_IR_LOG_VIEWER_EVENT_HPP + +#include +#include +#include +#include + +namespace clp::ffi::js { + +/** + * A class representing a log event with an additional log level field. + * @tparam encoded_variable_t The type of encoded variables in the event + */ +template +class LogViewerEvent : public ir::LogEvent { +public: + // Constructors + LogViewerEvent( + ir::epoch_time_ms_t timestamp, + UtcOffset utc_offset, + ir::EncodedTextAst message, + size_t log_level // Add the log level parameter + ) + : ir::LogEvent(timestamp, utc_offset, std::move(message)), + m_log_level{log_level} {} + + // Methods + [[nodiscard]] auto get_log_level() const -> size_t; + + // Static method to create LogViewerEvent from LogEvent + static auto from_log_event( + const ir::LogEvent& log_event, + size_t log_level + ) -> LogViewerEvent; + +private: + size_t m_log_level; +}; + +template +auto LogViewerEvent::get_log_level() const -> size_t { + return m_log_level; +} + +template +auto LogViewerEvent::from_log_event( + const ir::LogEvent& log_event, + size_t log_level +) -> LogViewerEvent { + return LogViewerEvent( + log_event.get_timestamp(), + log_event.get_utc_offset(), + log_event.get_message(), + log_level + ); +} + +} // namespace clp::ffi:js + +#endif // CLP_IR_LOG_VIEWER_EVENT_HPP \ No newline at end of file diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index b5682a69..8d213e7c 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +27,8 @@ #include #include #include +#include + using namespace std::literals::string_literals; using clp::ir::four_byte_encoded_variable_t; @@ -115,7 +117,32 @@ auto StreamReader::deserialize_range(size_t begin_idx, size_t end_idx) -> size_t while (true) { auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; if (false == result.has_error()) { - m_encoded_log_events.emplace_back(std::move(result.value())); + + const auto log_event = result.value(); + const auto message = log_event.get_message(); + + std::string logtype; + constexpr size_t cDefaultReservedMessageLength{512}; + logtype.reserve(cDefaultReservedMessageLength); + logtype = message.get_logtype(); + + + constexpr size_t cLogLevelPositionInMessages{1}; + size_t log_level{cLogLevelNone}; + // NOLINTNEXTLINE(readability-qualified-auto) + auto const log_level_name_it{std::find_if( + cLogLevelNames.begin() + cValidLogLevelsBeginIdx, + cLogLevelNames.end(), + [&](std::string_view level) { + return logtype.substr(cLogLevelPositionInMessages).starts_with(level); + } + )}; + if (log_level_name_it != cLogLevelNames.end()) { + log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); + } + const auto log_viewer_event = clp::ffi::js::LogViewerEvent(log_event.get_timestamp(), log_event.get_utc_offset(), log_event.get_message(),log_level); + + m_encoded_log_events.emplace_back(std::move(log_viewer_event)); continue; } auto const error{result.error()}; @@ -135,27 +162,24 @@ auto StreamReader::deserialize_range(size_t begin_idx, size_t end_idx) -> size_t } m_stream_reader_data_context.reset(nullptr); } - + m_filtered_log_event_indices = clp_ffi_js::ir::StreamReader::create_indices_vector(m_encoded_log_events.size()); return m_encoded_log_events.size(); } auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType { - if (m_encoded_log_events.size() < end_idx || begin_idx >= end_idx) { + if (m_filtered_log_event_indices.size() < end_idx || 0 > begin_idx) { return DecodedResultsTsType(emscripten::val::null()); } - - std::span const log_events_span{ - m_encoded_log_events.begin() - + static_cast(begin_idx), - m_encoded_log_events.begin() - + static_cast(end_idx) - }; std::string message; constexpr size_t cDefaultReservedMessageLength{512}; message.reserve(cDefaultReservedMessageLength); size_t log_num{begin_idx + 1}; auto const results{emscripten::val::array()}; - for (auto const& log_event : log_events_span) { + + for (size_t filtered_log_event_idx = begin_idx; filtered_log_event_idx < end_idx; ++filtered_log_event_idx) { + // Get the log event index from filtered indices + size_t log_event_idx = m_filtered_log_event_indices[filtered_log_event_idx]; + const auto& log_event = m_encoded_log_events[log_event_idx]; message.clear(); auto const parsed{log_event.get_message().decode_and_unparse()}; @@ -165,20 +189,6 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> Decod } message.append(parsed.value()); - constexpr size_t cLogLevelPositionInMessages{1}; - size_t log_level{cLogLevelNone}; - // NOLINTNEXTLINE(readability-qualified-auto) - auto const log_level_name_it{std::find_if( - cLogLevelNames.begin() + cValidLogLevelsBeginIdx, - cLogLevelNames.end(), - [&](std::string_view level) { - return message.substr(cLogLevelPositionInMessages).starts_with(level); - } - )}; - if (log_level_name_it != cLogLevelNames.end()) { - log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); - } - m_ts_pattern.insert_formatted_timestamp(log_event.get_timestamp(), message); EM_ASM( @@ -186,7 +196,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> Decod results.as_handle(), message.c_str(), log_event.get_timestamp(), - log_level, + log_event.get_log_level(), log_num ); ++log_num; @@ -195,6 +205,55 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> Decod return DecodedResultsTsType(results); } +void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { + // Clear the previous filtered log indices + m_filtered_log_event_indices.clear(); + + // Check if the filter is empty + if (logLevelFilter.isNull() || logLevelFilter["length"].as() == 0) { + m_filtered_log_event_indices = create_indices_vector(m_encoded_log_events.size()); + return; + } + + // Convert JavaScript array to C++ vector + std::vector filter_levels; + unsigned int length = logLevelFilter["length"].as(); + filter_levels.reserve(length); + for (unsigned int i = 0; i < length; ++i) { + filter_levels.push_back(logLevelFilter[i].as()); + } + + // Filter log events based on the provided log levels + for (size_t index = 0; index < m_encoded_log_events.size(); ++index) { + const auto& logEvent = m_encoded_log_events[index]; + if (std::find(filter_levels.begin(), filter_levels.end(), logEvent.get_log_level()) != filter_levels.end()) { + m_filtered_log_event_indices.push_back(index); + } + } +} + + auto StreamReader::get_filtered_log_indices() const -> FilterIndicesType { + // Convert C++ vector to JavaScript array using EM_ASM + emscripten::val js_array = emscripten::val::array(); + for (size_t index : m_filtered_log_event_indices) { + EM_ASM_( + { + Emval.toValue($0).push($1); + }, + js_array.as_handle(), + index + ); + } + return FilterIndicesType(js_array); + } + + +auto StreamReader::create_indices_vector(int length) -> std::vector { + std::vector indices(length); + std::iota(indices.begin(), indices.end(), 0); // Fill with 0, 1, 2, ... + return indices; +} + StreamReader::StreamReader( StreamReaderDataContext&& stream_reader_data_context ) @@ -205,12 +264,20 @@ StreamReader::StreamReader( m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} } // namespace clp_ffi_js::ir + + namespace { EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { emscripten::register_type("Uint8Array"); emscripten::register_type( "Array<[string, number, number, number]>" ); + emscripten::register_type( + "Array<[number]>" + ); + + emscripten::register_vector("VectorSizeT"); + emscripten::class_("ClpIrStreamReader") .constructor( &clp_ffi_js::ir::StreamReader::create, @@ -221,6 +288,8 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { &clp_ffi_js::ir::StreamReader::get_num_events_buffered ) .function("deserializeRange", &clp_ffi_js::ir::StreamReader::deserialize_range) - .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range); + .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) + .function("filter_logs", &clp_ffi_js::ir::StreamReader::filter_logs) + .function("get_filtered_log_indices", &clp_ffi_js::ir::StreamReader::get_filtered_log_indices); } } // namespace diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 15feda71..ddf3706d 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -12,10 +12,12 @@ #include #include +#include namespace clp_ffi_js::ir { EMSCRIPTEN_DECLARE_VAL_TYPE(DataArrayTsType); EMSCRIPTEN_DECLARE_VAL_TYPE(DecodedResultsTsType); +EMSCRIPTEN_DECLARE_VAL_TYPE(FilterIndicesType); /** * Class to deserialize and decode Zstandard-compressed CLP IR streams as well as format decoded @@ -49,6 +51,11 @@ class StreamReader { */ [[nodiscard]] auto get_num_events_buffered() const -> size_t; + /** + * @return The number of events buffered. + */ + [[nodiscard]] auto get_filtered_log_indices() const -> FilterIndicesType; + /** * Deserializes and buffers log events in the range `[beginIdx, endIdx)`. After the stream has * been exhausted, it will be deallocated. @@ -77,13 +84,25 @@ class StreamReader { */ [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType; + /** + * Creates an array containing indexes of logs which match the user selected levels. The + * previous array is removed and a new one is created on each call. + * + * @param logLevelFilter Array of selected log levels + */ + void filter_logs(const emscripten::val& logLevelFilter); + + //member function to create a vector of indices + [[nodiscard]] static auto create_indices_vector(int length) -> std::vector; + private: // Constructor explicit StreamReader(StreamReaderDataContext&& stream_reader_data_context); // Variables - std::vector> m_encoded_log_events; + std::vector> m_encoded_log_events; + std::vector m_filtered_log_event_indices; std::unique_ptr> m_stream_reader_data_context; clp::TimestampPattern m_ts_pattern; From 2292781e7a176175d7fee42de0b51b029aa6142f Mon Sep 17 00:00:00 2001 From: David Marcovitch Date: Thu, 19 Sep 2024 12:54:23 -0400 Subject: [PATCH 02/47] some work on changing to new interface, not yet complete --- src/clp_ffi_js/ir/StreamReader.cpp | 31 +++++++++++++++--------------- src/clp_ffi_js/ir/StreamReader.hpp | 29 +++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 8d213e7c..8a56a970 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -210,8 +210,8 @@ void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { m_filtered_log_event_indices.clear(); // Check if the filter is empty - if (logLevelFilter.isNull() || logLevelFilter["length"].as() == 0) { - m_filtered_log_event_indices = create_indices_vector(m_encoded_log_events.size()); + if (logLevelFilter.isNull()) { + m_is_filtered = false; return; } @@ -232,20 +232,20 @@ void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { } } - auto StreamReader::get_filtered_log_indices() const -> FilterIndicesType { - // Convert C++ vector to JavaScript array using EM_ASM - emscripten::val js_array = emscripten::val::array(); - for (size_t index : m_filtered_log_event_indices) { - EM_ASM_( - { - Emval.toValue($0).push($1); - }, - js_array.as_handle(), - index - ); - } - return FilterIndicesType(js_array); +auto StreamReader::get_filtered_log_indices() const -> FilterIndicesType { + // Convert C++ vector to JavaScript array using EM_ASM + emscripten::val js_array = emscripten::val::array(); + for (size_t index : m_filtered_log_event_indices) { + EM_ASM_( + { + Emval.toValue($0).push($1); + }, + js_array.as_handle(), + index + ); } + return FilterIndicesType(js_array); +} auto StreamReader::create_indices_vector(int length) -> std::vector { @@ -262,6 +262,7 @@ StreamReader::StreamReader( std::move(stream_reader_data_context) )}, m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} + m_is_filtered = false; } // namespace clp_ffi_js::ir diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index ddf3706d..33363b35 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -70,7 +70,28 @@ class StreamReader { [[nodiscard]] auto deserialize_range(size_t begin_idx, size_t end_idx) -> size_t; /** - * Decodes the deserialized log events in the range `[beginIdx, endIdx)`. + * Decodes filtered deserialized log events (i.e. only includes events are included in current + * filter) in the range `[beginIdx, endIdx)`. + * + * @param begin_idx + * @param end_idx + * @return Same as decode_any_range() return values. + */ + [[nodiscard]] auto decode_filtered_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType; + + /** + * Decodes all deserialized log events in the range `[beginIdx, endIdx)` irrespective of + * filter applied. + * + * @param begin_idx + * @param end_idx + * @return Same as decode_any_range() return values. + */ + [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType; + + /** + * Decodes the deserialized log events in the range `[beginIdx, endIdx)` from the + * filtered log events array or unfiltered based on the value of useFilter. * * @param begin_idx * @param end_idx @@ -82,7 +103,7 @@ class StreamReader { * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number * of log events in the file). */ - [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType; + [[nodiscard]] auto decode_any_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType; /** * Creates an array containing indexes of logs which match the user selected levels. The @@ -92,9 +113,6 @@ class StreamReader { */ void filter_logs(const emscripten::val& logLevelFilter); - //member function to create a vector of indices - [[nodiscard]] static auto create_indices_vector(int length) -> std::vector; - private: // Constructor explicit StreamReader(StreamReaderDataContext&& @@ -106,6 +124,7 @@ class StreamReader { std::unique_ptr> m_stream_reader_data_context; clp::TimestampPattern m_ts_pattern; + bool m_is_filtered; }; } // namespace clp_ffi_js::ir From f69ee3150e746aff3cbaa534e59f7fe3085eeebe Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 02:22:41 +0000 Subject: [PATCH 03/47] saving changes --- src/clp_ffi_js/ir/StreamReader.cpp | 51 +++++++++++++++++++----------- src/clp_ffi_js/ir/StreamReader.hpp | 3 +- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 8a56a970..bb9f39a2 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -162,12 +162,20 @@ auto StreamReader::deserialize_range(size_t begin_idx, size_t end_idx) -> size_t } m_stream_reader_data_context.reset(nullptr); } - m_filtered_log_event_indices = clp_ffi_js::ir::StreamReader::create_indices_vector(m_encoded_log_events.size()); + m_is_filtered = false; return m_encoded_log_events.size(); } -auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType { - if (m_filtered_log_event_indices.size() < end_idx || 0 > begin_idx) { +auto StreamReader::decode_any_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType { + + size_t length; + if (use_filter) { + length = m_filtered_log_event_indices.size(); + } else { + length = m_encoded_log_events.size(); + } + + if (length < end_idx || 0 > begin_idx) { return DecodedResultsTsType(emscripten::val::null()); } std::string message; @@ -176,10 +184,15 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> Decod size_t log_num{begin_idx + 1}; auto const results{emscripten::val::array()}; - for (size_t filtered_log_event_idx = begin_idx; filtered_log_event_idx < end_idx; ++filtered_log_event_idx) { + for (size_t log_event_idx = begin_idx; log_event_idx < end_idx; ++log_event_idx) { // Get the log event index from filtered indices - size_t log_event_idx = m_filtered_log_event_indices[filtered_log_event_idx]; - const auto& log_event = m_encoded_log_events[log_event_idx]; + size_t filtered_log_event_idx; + if (use_filter) { + filtered_log_event_idx = m_filtered_log_event_indices[log_event_idx]; + } else { + filtered_log_event_idx = log_event_idx; + } + const auto& log_event = m_encoded_log_events[filtered_log_event_idx]; message.clear(); auto const parsed{log_event.get_message().decode_and_unparse()}; @@ -197,14 +210,22 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> Decod message.c_str(), log_event.get_timestamp(), log_event.get_log_level(), - log_num + filtered_log_event_idx +1 ); - ++log_num; + } return DecodedResultsTsType(results); } +auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType { + return decode_any_range(begin_idx, end_idx, false); +} + +auto StreamReader::decode_filtered_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType { + return decode_any_range(begin_idx, end_idx, m_is_filtered); +} + void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { // Clear the previous filtered log indices m_filtered_log_event_indices.clear(); @@ -230,6 +251,7 @@ void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { m_filtered_log_event_indices.push_back(index); } } + m_is_filtered = true; } auto StreamReader::get_filtered_log_indices() const -> FilterIndicesType { @@ -247,13 +269,6 @@ auto StreamReader::get_filtered_log_indices() const -> FilterIndicesType { return FilterIndicesType(js_array); } - -auto StreamReader::create_indices_vector(int length) -> std::vector { - std::vector indices(length); - std::iota(indices.begin(), indices.end(), 0); // Fill with 0, 1, 2, ... - return indices; -} - StreamReader::StreamReader( StreamReaderDataContext&& stream_reader_data_context ) @@ -262,7 +277,6 @@ StreamReader::StreamReader( std::move(stream_reader_data_context) )}, m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} - m_is_filtered = false; } // namespace clp_ffi_js::ir @@ -274,11 +288,9 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { "Array<[string, number, number, number]>" ); emscripten::register_type( - "Array<[number]>" + "Array" ); - emscripten::register_vector("VectorSizeT"); - emscripten::class_("ClpIrStreamReader") .constructor( &clp_ffi_js::ir::StreamReader::create, @@ -290,6 +302,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { ) .function("deserializeRange", &clp_ffi_js::ir::StreamReader::deserialize_range) .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) + .function("decodeFilteredRange", &clp_ffi_js::ir::StreamReader::decode_filtered_range) .function("filter_logs", &clp_ffi_js::ir::StreamReader::filter_logs) .function("get_filtered_log_indices", &clp_ffi_js::ir::StreamReader::get_filtered_log_indices); } diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 33363b35..381d0e97 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -95,6 +95,7 @@ class StreamReader { * * @param begin_idx * @param end_idx + * @param use_filter Whether or not to use filtered log event array. * @return An array where each element is a decoded log event represented by an array of: * - The log event's message * - The log event's timestamp as milliseconds since the Unix epoch @@ -103,7 +104,7 @@ class StreamReader { * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number * of log events in the file). */ - [[nodiscard]] auto decode_any_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType; + [[nodiscard]] auto decode_any_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; /** * Creates an array containing indexes of logs which match the user selected levels. The From 8749844274c8773c7d1fe1304a292622219ce926 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 04:04:09 +0000 Subject: [PATCH 04/47] latest --- src/clp_ffi_js/ir/LogViewerEvent.hpp | 41 +++++-------------- src/clp_ffi_js/ir/StreamReader.cpp | 36 ++++++++-------- src/clp_ffi_js/ir/StreamReader.hpp | 29 ++----------- src/clp_ffi_js/ir/StreamReaderDataContext.hpp | 2 + 4 files changed, 32 insertions(+), 76 deletions(-) diff --git a/src/clp_ffi_js/ir/LogViewerEvent.hpp b/src/clp_ffi_js/ir/LogViewerEvent.hpp index 4a154e7d..1f1ce896 100644 --- a/src/clp_ffi_js/ir/LogViewerEvent.hpp +++ b/src/clp_ffi_js/ir/LogViewerEvent.hpp @@ -2,38 +2,30 @@ #define CLP_IR_LOG_VIEWER_EVENT_HPP #include -#include -#include #include -namespace clp::ffi::js { +namespace clp_ffi_js::ir { /** - * A class representing a log event with an additional log level field. + * A class derived from LogEvent with an additional member for log level. * @tparam encoded_variable_t The type of encoded variables in the event */ template -class LogViewerEvent : public ir::LogEvent { +class LogViewerEvent : public clp::ir::LogEvent { public: // Constructors LogViewerEvent( - ir::epoch_time_ms_t timestamp, - UtcOffset utc_offset, - ir::EncodedTextAst message, - size_t log_level // Add the log level parameter + clp::ir::epoch_time_ms_t timestamp, + clp::UtcOffset utc_offset, + clp::ir::EncodedTextAst message, + size_t log_level ) - : ir::LogEvent(timestamp, utc_offset, std::move(message)), + : clp::ir::LogEvent(timestamp, utc_offset, std::move(message)), m_log_level{log_level} {} // Methods [[nodiscard]] auto get_log_level() const -> size_t; - // Static method to create LogViewerEvent from LogEvent - static auto from_log_event( - const ir::LogEvent& log_event, - size_t log_level - ) -> LogViewerEvent; - private: size_t m_log_level; }; @@ -43,19 +35,6 @@ auto LogViewerEvent::get_log_level() const -> size_t { return m_log_level; } -template -auto LogViewerEvent::from_log_event( - const ir::LogEvent& log_event, - size_t log_level -) -> LogViewerEvent { - return LogViewerEvent( - log_event.get_timestamp(), - log_event.get_utc_offset(), - log_event.get_message(), - log_level - ); -} - -} // namespace clp::ffi:js +} // namespace clp_ffi_js::ir -#endif // CLP_IR_LOG_VIEWER_EVENT_HPP \ No newline at end of file +#endif // CLP_IR_LOG_VIEWER_EVENT_HPP diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index bb9f39a2..ce6c0331 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -26,9 +26,8 @@ #include #include -#include #include - +#include using namespace std::literals::string_literals; using clp::ir::four_byte_encoded_variable_t; @@ -102,6 +101,7 @@ auto StreamReader::get_num_events_buffered() const -> size_t { } auto StreamReader::deserialize_range(size_t begin_idx, size_t end_idx) -> size_t { + m_is_filtered = false; constexpr size_t cFullRangeEndIdx{0}; if (0 != begin_idx || cFullRangeEndIdx != end_idx) { throw ClpFfiJsException{ @@ -126,7 +126,6 @@ auto StreamReader::deserialize_range(size_t begin_idx, size_t end_idx) -> size_t logtype.reserve(cDefaultReservedMessageLength); logtype = message.get_logtype(); - constexpr size_t cLogLevelPositionInMessages{1}; size_t log_level{cLogLevelNone}; // NOLINTNEXTLINE(readability-qualified-auto) @@ -140,7 +139,8 @@ auto StreamReader::deserialize_range(size_t begin_idx, size_t end_idx) -> size_t if (log_level_name_it != cLogLevelNames.end()) { log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); } - const auto log_viewer_event = clp::ffi::js::LogViewerEvent(log_event.get_timestamp(), log_event.get_utc_offset(), log_event.get_message(),log_level); + + const auto log_viewer_event = LogViewerEvent(log_event.get_timestamp(), log_event.get_utc_offset(), message, log_level); m_encoded_log_events.emplace_back(std::move(log_viewer_event)); continue; @@ -162,11 +162,10 @@ auto StreamReader::deserialize_range(size_t begin_idx, size_t end_idx) -> size_t } m_stream_reader_data_context.reset(nullptr); } - m_is_filtered = false; return m_encoded_log_events.size(); } -auto StreamReader::decode_any_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType { +auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType { size_t length; if (use_filter) { @@ -218,14 +217,6 @@ auto StreamReader::decode_any_range(size_t begin_idx, size_t end_idx, bool use_f return DecodedResultsTsType(results); } -auto StreamReader::decode_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType { - return decode_any_range(begin_idx, end_idx, false); -} - -auto StreamReader::decode_filtered_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType { - return decode_any_range(begin_idx, end_idx, m_is_filtered); -} - void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { // Clear the previous filtered log indices m_filtered_log_event_indices.clear(); @@ -255,18 +246,21 @@ void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { } auto StreamReader::get_filtered_log_indices() const -> FilterIndicesType { - // Convert C++ vector to JavaScript array using EM_ASM - emscripten::val js_array = emscripten::val::array(); + if (false == m_is_filtered) { + return FilterIndicesType(emscripten::val::null()); + } + + emscripten::val results = emscripten::val::array(); for (size_t index : m_filtered_log_event_indices) { EM_ASM_( { Emval.toValue($0).push($1); }, - js_array.as_handle(), + results.as_handle(), index ); } - return FilterIndicesType(js_array); + return FilterIndicesType(results); } StreamReader::StreamReader( @@ -276,7 +270,10 @@ StreamReader::StreamReader( StreamReaderDataContext>( std::move(stream_reader_data_context) )}, - m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} + m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()}, + m_encoded_log_events(), + m_filtered_log_event_indices(), + m_is_filtered(false) {} } // namespace clp_ffi_js::ir @@ -302,7 +299,6 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { ) .function("deserializeRange", &clp_ffi_js::ir::StreamReader::deserialize_range) .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) - .function("decodeFilteredRange", &clp_ffi_js::ir::StreamReader::decode_filtered_range) .function("filter_logs", &clp_ffi_js::ir::StreamReader::filter_logs) .function("get_filtered_log_indices", &clp_ffi_js::ir::StreamReader::get_filtered_log_indices); } diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 381d0e97..97268c72 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -69,26 +69,6 @@ class StreamReader { */ [[nodiscard]] auto deserialize_range(size_t begin_idx, size_t end_idx) -> size_t; - /** - * Decodes filtered deserialized log events (i.e. only includes events are included in current - * filter) in the range `[beginIdx, endIdx)`. - * - * @param begin_idx - * @param end_idx - * @return Same as decode_any_range() return values. - */ - [[nodiscard]] auto decode_filtered_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType; - - /** - * Decodes all deserialized log events in the range `[beginIdx, endIdx)` irrespective of - * filter applied. - * - * @param begin_idx - * @param end_idx - * @return Same as decode_any_range() return values. - */ - [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx) const -> DecodedResultsTsType; - /** * Decodes the deserialized log events in the range `[beginIdx, endIdx)` from the * filtered log events array or unfiltered based on the value of useFilter. @@ -104,8 +84,7 @@ class StreamReader { * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number * of log events in the file). */ - [[nodiscard]] auto decode_any_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; - + [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; /** * Creates an array containing indexes of logs which match the user selected levels. The * previous array is removed and a new one is created on each call. @@ -120,11 +99,11 @@ class StreamReader { stream_reader_data_context); // Variables - std::vector> m_encoded_log_events; - std::vector m_filtered_log_event_indices; std::unique_ptr> - m_stream_reader_data_context; + m_stream_reader_data_context; clp::TimestampPattern m_ts_pattern; + std::vector> m_encoded_log_events; + std::vector m_filtered_log_event_indices; bool m_is_filtered; }; } // namespace clp_ffi_js::ir diff --git a/src/clp_ffi_js/ir/StreamReaderDataContext.hpp b/src/clp_ffi_js/ir/StreamReaderDataContext.hpp index 091b0b05..d9e3a010 100644 --- a/src/clp_ffi_js/ir/StreamReaderDataContext.hpp +++ b/src/clp_ffi_js/ir/StreamReaderDataContext.hpp @@ -19,6 +19,8 @@ namespace clp_ffi_js::ir { template class StreamReaderDataContext { public: + using EncodedVariableType = encoded_variable_t; + // Constructors StreamReaderDataContext( clp::Array&& data_buffer, From 782dd13780fff6c5c7e7c6a8d4581f0853a8ff2a Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 04:20:46 +0000 Subject: [PATCH 05/47] latest --- src/clp_ffi_js/ir/StreamReader.cpp | 39 +++++++++---------- src/clp_ffi_js/ir/StreamReader.hpp | 18 ++++----- src/clp_ffi_js/ir/StreamReaderDataContext.hpp | 1 - 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index ce6c0331..15f15903 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -169,7 +169,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte size_t length; if (use_filter) { - length = m_filtered_log_event_indices.size(); + length = m_filtered_log_event_map.size(); } else { length = m_encoded_log_events.size(); } @@ -180,18 +180,16 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte std::string message; constexpr size_t cDefaultReservedMessageLength{512}; message.reserve(cDefaultReservedMessageLength); - size_t log_num{begin_idx + 1}; auto const results{emscripten::val::array()}; - for (size_t log_event_idx = begin_idx; log_event_idx < end_idx; ++log_event_idx) { - // Get the log event index from filtered indices - size_t filtered_log_event_idx; + for (size_t i = begin_idx; i < end_idx; ++i) { + size_t log_event_idx; if (use_filter) { - filtered_log_event_idx = m_filtered_log_event_indices[log_event_idx]; + log_event_idx = m_filtered_log_event_map[i]; } else { - filtered_log_event_idx = log_event_idx; + log_event_idx = i; } - const auto& log_event = m_encoded_log_events[filtered_log_event_idx]; + const auto& log_event = m_encoded_log_events[log_event_idx]; message.clear(); auto const parsed{log_event.get_message().decode_and_unparse()}; @@ -209,7 +207,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte message.c_str(), log_event.get_timestamp(), log_event.get_log_level(), - filtered_log_event_idx +1 + log_event_idx +1 ); } @@ -217,9 +215,8 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte return DecodedResultsTsType(results); } -void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { - // Clear the previous filtered log indices - m_filtered_log_event_indices.clear(); +void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { + m_filtered_log_event_map.clear(); // Check if the filter is empty if (logLevelFilter.isNull()) { @@ -239,19 +236,19 @@ void StreamReader::filter_logs(const emscripten::val& logLevelFilter) { for (size_t index = 0; index < m_encoded_log_events.size(); ++index) { const auto& logEvent = m_encoded_log_events[index]; if (std::find(filter_levels.begin(), filter_levels.end(), logEvent.get_log_level()) != filter_levels.end()) { - m_filtered_log_event_indices.push_back(index); + m_filtered_log_event_map.push_back(index); } } m_is_filtered = true; } -auto StreamReader::get_filtered_log_indices() const -> FilterIndicesType { +auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapType { if (false == m_is_filtered) { - return FilterIndicesType(emscripten::val::null()); + return FilteredLogEventMapType(emscripten::val::null()); } emscripten::val results = emscripten::val::array(); - for (size_t index : m_filtered_log_event_indices) { + for (size_t index : m_filtered_log_event_map) { EM_ASM_( { Emval.toValue($0).push($1); @@ -260,7 +257,7 @@ auto StreamReader::get_filtered_log_indices() const -> FilterIndicesType { index ); } - return FilterIndicesType(results); + return FilteredLogEventMapType(results); } StreamReader::StreamReader( @@ -272,7 +269,7 @@ StreamReader::StreamReader( )}, m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()}, m_encoded_log_events(), - m_filtered_log_event_indices(), + m_filtered_log_event_map(), m_is_filtered(false) {} } // namespace clp_ffi_js::ir @@ -284,7 +281,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { emscripten::register_type( "Array<[string, number, number, number]>" ); - emscripten::register_type( + emscripten::register_type( "Array" ); @@ -299,7 +296,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { ) .function("deserializeRange", &clp_ffi_js::ir::StreamReader::deserialize_range) .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) - .function("filter_logs", &clp_ffi_js::ir::StreamReader::filter_logs) - .function("get_filtered_log_indices", &clp_ffi_js::ir::StreamReader::get_filtered_log_indices); + .function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events) + .function("getFilteredLogEventMap", &clp_ffi_js::ir::StreamReader::get_filtered_log_event_map); } } // namespace diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 97268c72..65b29459 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -17,7 +17,7 @@ namespace clp_ffi_js::ir { EMSCRIPTEN_DECLARE_VAL_TYPE(DataArrayTsType); EMSCRIPTEN_DECLARE_VAL_TYPE(DecodedResultsTsType); -EMSCRIPTEN_DECLARE_VAL_TYPE(FilterIndicesType); +EMSCRIPTEN_DECLARE_VAL_TYPE(FilteredLogEventMapType); /** * Class to deserialize and decode Zstandard-compressed CLP IR streams as well as format decoded @@ -54,7 +54,7 @@ class StreamReader { /** * @return The number of events buffered. */ - [[nodiscard]] auto get_filtered_log_indices() const -> FilterIndicesType; + [[nodiscard]] auto get_filtered_log_event_map() const -> FilteredLogEventMapType; /** * Deserializes and buffers log events in the range `[beginIdx, endIdx)`. After the stream has @@ -70,19 +70,19 @@ class StreamReader { [[nodiscard]] auto deserialize_range(size_t begin_idx, size_t end_idx) -> size_t; /** - * Decodes the deserialized log events in the range `[beginIdx, endIdx)` from the - * filtered log events array or unfiltered based on the value of useFilter. + * Decodes log events in the range `[beginIdx, endIdx)` of the filtered or unfiltered + * (depending on the value of `useFilter`) log events collection. * * @param begin_idx * @param end_idx - * @param use_filter Whether or not to use filtered log event array. + * @param use_filter Whether to decode from the filtered or unfiltered log events collection. * @return An array where each element is a decoded log event represented by an array of: * - The log event's message * - The log event's timestamp as milliseconds since the Unix epoch * - The log event's log level as an integer that indexes into `cLogLevelNames` * - The log event's number (1-indexed) in the stream - * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number - * of log events in the file). + * @return The decoded log events on success or null if any log event in the range doesn't exist + * (e.g., the range exceeds the number of log events in the file). */ [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; /** @@ -91,7 +91,7 @@ class StreamReader { * * @param logLevelFilter Array of selected log levels */ - void filter_logs(const emscripten::val& logLevelFilter); + void filter_log_events(const emscripten::val& logLevelFilter); private: // Constructor @@ -103,7 +103,7 @@ class StreamReader { m_stream_reader_data_context; clp::TimestampPattern m_ts_pattern; std::vector> m_encoded_log_events; - std::vector m_filtered_log_event_indices; + std::vector m_filtered_log_event_map; bool m_is_filtered; }; } // namespace clp_ffi_js::ir diff --git a/src/clp_ffi_js/ir/StreamReaderDataContext.hpp b/src/clp_ffi_js/ir/StreamReaderDataContext.hpp index d9e3a010..3ad4e9ec 100644 --- a/src/clp_ffi_js/ir/StreamReaderDataContext.hpp +++ b/src/clp_ffi_js/ir/StreamReaderDataContext.hpp @@ -19,7 +19,6 @@ namespace clp_ffi_js::ir { template class StreamReaderDataContext { public: - using EncodedVariableType = encoded_variable_t; // Constructors StreamReaderDataContext( From 856ce4ae5c002dd079511b4067699c84c35db945 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 04:25:12 +0000 Subject: [PATCH 06/47] small nit --- src/clp_ffi_js/ir/StreamReader.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 65b29459..f214b365 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -81,8 +81,8 @@ class StreamReader { * - The log event's timestamp as milliseconds since the Unix epoch * - The log event's log level as an integer that indexes into `cLogLevelNames` * - The log event's number (1-indexed) in the stream - * @return The decoded log events on success or null if any log event in the range doesn't exist - * (e.g., the range exceeds the number of log events in the file). + * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number + * of log events in the file). */ [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; /** From 2937d8fa7496206656a1758409bd5d65e90466c4 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 16:29:11 +0000 Subject: [PATCH 07/47] junhao review --- src/clp_ffi_js/ir/StreamReader.cpp | 34 ++++-------------------------- src/clp_ffi_js/ir/StreamReader.hpp | 2 +- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 15f15903..93744d1d 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -100,17 +100,7 @@ auto StreamReader::get_num_events_buffered() const -> size_t { return m_encoded_log_events.size(); } -auto StreamReader::deserialize_range(size_t begin_idx, size_t end_idx) -> size_t { - m_is_filtered = false; - constexpr size_t cFullRangeEndIdx{0}; - if (0 != begin_idx || cFullRangeEndIdx != end_idx) { - throw ClpFfiJsException{ - clp::ErrorCode::ErrorCode_Unsupported, - __FILENAME__, - __LINE__, - "Partial range deserialization is not yet supported." - }; - } +auto StreamReader::build() -> size_t { if (nullptr != m_stream_reader_data_context) { constexpr size_t cDefaultNumReservedLogEvents{500'000}; m_encoded_log_events.reserve(cDefaultNumReservedLogEvents); @@ -224,13 +214,7 @@ void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { return; } - // Convert JavaScript array to C++ vector - std::vector filter_levels; - unsigned int length = logLevelFilter["length"].as(); - filter_levels.reserve(length); - for (unsigned int i = 0; i < length; ++i) { - filter_levels.push_back(logLevelFilter[i].as()); - } + std::vector filter_levels = emscripten::vecFromJSArray(logLevelFilter); // Filter log events based on the provided log levels for (size_t index = 0; index < m_encoded_log_events.size(); ++index) { @@ -247,17 +231,7 @@ auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapTyp return FilteredLogEventMapType(emscripten::val::null()); } - emscripten::val results = emscripten::val::array(); - for (size_t index : m_filtered_log_event_map) { - EM_ASM_( - { - Emval.toValue($0).push($1); - }, - results.as_handle(), - index - ); - } - return FilteredLogEventMapType(results); + return FilteredLogEventMapType(emscripten::val::array(m_filtered_log_event_map)); } StreamReader::StreamReader( @@ -294,7 +268,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { "getNumEventsBuffered", &clp_ffi_js::ir::StreamReader::get_num_events_buffered ) - .function("deserializeRange", &clp_ffi_js::ir::StreamReader::deserialize_range) + .function("build", &clp_ffi_js::ir::StreamReader::build) .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) .function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events) .function("getFilteredLogEventMap", &clp_ffi_js::ir::StreamReader::get_filtered_log_event_map); diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index f214b365..29b95e8f 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -67,7 +67,7 @@ class StreamReader { * @param end_idx * @return The number of successfully deserialized ("valid") log events. */ - [[nodiscard]] auto deserialize_range(size_t begin_idx, size_t end_idx) -> size_t; + [[nodiscard]] auto build() -> size_t; /** * Decodes log events in the range `[beginIdx, endIdx)` of the filtered or unfiltered From 95379d6f32d5a4cb34abe0e9d7d93f921ce18561 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 17:40:41 +0000 Subject: [PATCH 08/47] use std optional --- src/clp_ffi_js/ir/LogViewerEvent.hpp | 6 +++--- src/clp_ffi_js/ir/StreamReader.cpp | 26 ++++++++++++-------------- src/clp_ffi_js/ir/StreamReader.hpp | 24 +++++++++++++----------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/clp_ffi_js/ir/LogViewerEvent.hpp b/src/clp_ffi_js/ir/LogViewerEvent.hpp index 1f1ce896..f86d947d 100644 --- a/src/clp_ffi_js/ir/LogViewerEvent.hpp +++ b/src/clp_ffi_js/ir/LogViewerEvent.hpp @@ -1,5 +1,5 @@ -#ifndef CLP_IR_LOG_VIEWER_EVENT_HPP -#define CLP_IR_LOG_VIEWER_EVENT_HPP +#ifndef CLP_FFI_JS_IR_LOG_VIEWER_EVENT_HPP +#define CLP_FFI_JS_IR_LOG_VIEWER_EVENT_HPP #include #include @@ -37,4 +37,4 @@ auto LogViewerEvent::get_log_level() const -> size_t { } // namespace clp_ffi_js::ir -#endif // CLP_IR_LOG_VIEWER_EVENT_HPP +#endif // CLP_FFI_JS_IR_LOG_VIEWER_EVENT_HPP diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 93744d1d..5d5dd73d 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -157,9 +156,13 @@ auto StreamReader::build() -> size_t { auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType { + if (use_filter && !m_filtered_log_event_map) { + return DecodedResultsTsType(emscripten::val::null()); + } + size_t length; if (use_filter) { - length = m_filtered_log_event_map.size(); + length = m_filtered_log_event_map->size(); } else { length = m_encoded_log_events.size(); } @@ -175,7 +178,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte for (size_t i = begin_idx; i < end_idx; ++i) { size_t log_event_idx; if (use_filter) { - log_event_idx = m_filtered_log_event_map[i]; + log_event_idx = m_filtered_log_event_map->at(i); } else { log_event_idx = i; } @@ -206,32 +209,28 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte } void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { - m_filtered_log_event_map.clear(); - - // Check if the filter is empty if (logLevelFilter.isNull()) { - m_is_filtered = false; + m_filtered_log_event_map.reset(); return; } + m_filtered_log_event_map = std::vector(); std::vector filter_levels = emscripten::vecFromJSArray(logLevelFilter); - // Filter log events based on the provided log levels for (size_t index = 0; index < m_encoded_log_events.size(); ++index) { const auto& logEvent = m_encoded_log_events[index]; if (std::find(filter_levels.begin(), filter_levels.end(), logEvent.get_log_level()) != filter_levels.end()) { - m_filtered_log_event_map.push_back(index); + m_filtered_log_event_map->push_back(index); } } - m_is_filtered = true; } auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapType { - if (false == m_is_filtered) { + if (m_filtered_log_event_map) { return FilteredLogEventMapType(emscripten::val::null()); } - return FilteredLogEventMapType(emscripten::val::array(m_filtered_log_event_map)); + return FilteredLogEventMapType(emscripten::val::array(m_filtered_log_event_map.value())); } StreamReader::StreamReader( @@ -243,8 +242,7 @@ StreamReader::StreamReader( )}, m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()}, m_encoded_log_events(), - m_filtered_log_event_map(), - m_is_filtered(false) {} + m_filtered_log_event_map(std::nullopt) {} } // namespace clp_ffi_js::ir diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 29b95e8f..cfd4a8ed 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -51,11 +52,19 @@ class StreamReader { */ [[nodiscard]] auto get_num_events_buffered() const -> size_t; - /** - * @return The number of events buffered. + /** + * @return The filtered log events map. */ [[nodiscard]] auto get_filtered_log_event_map() const -> FilteredLogEventMapType; + /** + * Filters log events and generates `m_filtered_log_event_map`. If `logLevelFilter` is `null`, + * `m_is_filtered` will be set to `false`. + * + * @param logLevelFilter Array of selected log levels + */ + void filter_log_events(const emscripten::val& logLevelFilter); + /** * Deserializes and buffers log events in the range `[beginIdx, endIdx)`. After the stream has * been exhausted, it will be deallocated. @@ -85,13 +94,7 @@ class StreamReader { * of log events in the file). */ [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; - /** - * Creates an array containing indexes of logs which match the user selected levels. The - * previous array is removed and a new one is created on each call. - * - * @param logLevelFilter Array of selected log levels - */ - void filter_log_events(const emscripten::val& logLevelFilter); + private: // Constructor @@ -103,8 +106,7 @@ class StreamReader { m_stream_reader_data_context; clp::TimestampPattern m_ts_pattern; std::vector> m_encoded_log_events; - std::vector m_filtered_log_event_map; - bool m_is_filtered; + std::optional> m_filtered_log_event_map; }; } // namespace clp_ffi_js::ir From 773020f06ff4bac302a1de9108d910ddf0190e15 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 17:47:26 +0000 Subject: [PATCH 09/47] more changes --- src/clp_ffi_js/ir/StreamReader.cpp | 16 ++++++++-------- src/clp_ffi_js/ir/StreamReader.hpp | 13 ++++--------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 5d5dd73d..74069c3d 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -99,6 +99,14 @@ auto StreamReader::get_num_events_buffered() const -> size_t { return m_encoded_log_events.size(); } +auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapType { + if (m_filtered_log_event_map) { + return FilteredLogEventMapType(emscripten::val::null()); + } + + return FilteredLogEventMapType(emscripten::val::array(m_filtered_log_event_map.value())); +} + auto StreamReader::build() -> size_t { if (nullptr != m_stream_reader_data_context) { constexpr size_t cDefaultNumReservedLogEvents{500'000}; @@ -225,14 +233,6 @@ void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { } } -auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapType { - if (m_filtered_log_event_map) { - return FilteredLogEventMapType(emscripten::val::null()); - } - - return FilteredLogEventMapType(emscripten::val::array(m_filtered_log_event_map.value())); -} - StreamReader::StreamReader( StreamReaderDataContext&& stream_reader_data_context ) diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index cfd4a8ed..0f6bb170 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -59,21 +59,16 @@ class StreamReader { /** * Filters log events and generates `m_filtered_log_event_map`. If `logLevelFilter` is `null`, - * `m_is_filtered` will be set to `false`. + * `m_filtered_log_event_map` will be set to `std::nullopt`. * * @param logLevelFilter Array of selected log levels */ void filter_log_events(const emscripten::val& logLevelFilter); /** - * Deserializes and buffers log events in the range `[beginIdx, endIdx)`. After the stream has - * been exhausted, it will be deallocated. + * Deserializes all log events in the file. After the stream has been exhausted, it will be + * deallocated. * - * NOTE: Currently, this class only supports deserializing the full range of log events in the - * stream. - * - * @param begin_idx - * @param end_idx * @return The number of successfully deserialized ("valid") log events. */ [[nodiscard]] auto build() -> size_t; @@ -91,7 +86,7 @@ class StreamReader { * - The log event's log level as an integer that indexes into `cLogLevelNames` * - The log event's number (1-indexed) in the stream * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number - * of log events in the file). + * of log events in collection) */ [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; From b965d98231e56ac0ae5a6ec64a3d486bc5e31145 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 18:09:24 +0000 Subject: [PATCH 10/47] more changes --- src/clp_ffi_js/ir/StreamReader.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 74069c3d..9442a503 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -100,7 +101,7 @@ auto StreamReader::get_num_events_buffered() const -> size_t { } auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapType { - if (m_filtered_log_event_map) { + if (std::nullopt == m_filtered_log_event_map) { return FilteredLogEventMapType(emscripten::val::null()); } @@ -111,19 +112,25 @@ auto StreamReader::build() -> size_t { if (nullptr != m_stream_reader_data_context) { constexpr size_t cDefaultNumReservedLogEvents{500'000}; m_encoded_log_events.reserve(cDefaultNumReservedLogEvents); + + std::string logtype; + constexpr size_t cDefaultReservedMessageLength{512}; + logtype.reserve(cDefaultReservedMessageLength); while (true) { auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; if (false == result.has_error()) { - const auto log_event = result.value(); - const auto message = log_event.get_message(); + const clp::ir::LogEvent log_event = result.value(); + const clp::ir::EncodedTextAst message = log_event.get_message(); - std::string logtype; - constexpr size_t cDefaultReservedMessageLength{512}; - logtype.reserve(cDefaultReservedMessageLength); + logtype.clear(); logtype = message.get_logtype(); constexpr size_t cLogLevelPositionInMessages{1}; + if (logtype.length() < cLogLevelPositionInMessages) { + SPDLOG_ERROR("Failed to extract log type for log level parsing."); break; + } + size_t log_level{cLogLevelNone}; // NOLINTNEXTLINE(readability-qualified-auto) auto const log_level_name_it{std::find_if( From 5b31d0112b4343a17b2d8e9b45eff293c923ceca Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 18:18:56 +0000 Subject: [PATCH 11/47] small change --- src/clp_ffi_js/ir/StreamReader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 9442a503..2ea03e7c 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -120,8 +120,8 @@ auto StreamReader::build() -> size_t { auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; if (false == result.has_error()) { - const clp::ir::LogEvent log_event = result.value(); - const clp::ir::EncodedTextAst message = log_event.get_message(); + const auto log_event = result.value(); + const auto message = log_event.get_message(); logtype.clear(); logtype = message.get_logtype(); From fbb3f7b35a75212cdc39e366067bce37db78304d Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 18:38:44 +0000 Subject: [PATCH 12/47] more changes --- src/clp_ffi_js/ir/StreamReader.cpp | 15 ++++++--------- src/clp_ffi_js/ir/StreamReader.hpp | 2 +- src/clp_ffi_js/ir/StreamReaderDataContext.hpp | 1 - 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 2ea03e7c..db75a22a 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -3,9 +3,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -171,7 +171,7 @@ auto StreamReader::build() -> size_t { auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType { - if (use_filter && !m_filtered_log_event_map) { + if (use_filter && (std::nullopt == m_filtered_log_event_map)) { return DecodedResultsTsType(emscripten::val::null()); } @@ -217,7 +217,6 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte log_event.get_log_level(), log_event_idx +1 ); - } return DecodedResultsTsType(results); @@ -229,7 +228,7 @@ void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { return; } - m_filtered_log_event_map = std::vector(); + m_filtered_log_event_map.emplace(); std::vector filter_levels = emscripten::vecFromJSArray(logLevelFilter); // Filter log events based on the provided log levels for (size_t index = 0; index < m_encoded_log_events.size(); ++index) { @@ -252,8 +251,6 @@ StreamReader::StreamReader( m_filtered_log_event_map(std::nullopt) {} } // namespace clp_ffi_js::ir - - namespace { EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { emscripten::register_type("Uint8Array"); @@ -261,7 +258,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { "Array<[string, number, number, number]>" ); emscripten::register_type( - "Array" + "number[] ); emscripten::class_("ClpIrStreamReader") @@ -273,9 +270,9 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { "getNumEventsBuffered", &clp_ffi_js::ir::StreamReader::get_num_events_buffered ) + .function("getFilteredLogEventMap", &clp_ffi_js::ir::StreamReader::get_filtered_log_event_map) .function("build", &clp_ffi_js::ir::StreamReader::build) .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) - .function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events) - .function("getFilteredLogEventMap", &clp_ffi_js::ir::StreamReader::get_filtered_log_event_map); + .function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events); } } // namespace diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 0f6bb170..1933314e 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -98,7 +98,7 @@ class StreamReader { // Variables std::unique_ptr> - m_stream_reader_data_context; + m_stream_reader_data_context; clp::TimestampPattern m_ts_pattern; std::vector> m_encoded_log_events; std::optional> m_filtered_log_event_map; diff --git a/src/clp_ffi_js/ir/StreamReaderDataContext.hpp b/src/clp_ffi_js/ir/StreamReaderDataContext.hpp index 3ad4e9ec..091b0b05 100644 --- a/src/clp_ffi_js/ir/StreamReaderDataContext.hpp +++ b/src/clp_ffi_js/ir/StreamReaderDataContext.hpp @@ -19,7 +19,6 @@ namespace clp_ffi_js::ir { template class StreamReaderDataContext { public: - // Constructors StreamReaderDataContext( clp::Array&& data_buffer, From 30e76a0222578411b36592b84a2012f9a5e92844 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 18:43:18 +0000 Subject: [PATCH 13/47] small changes --- src/clp_ffi_js/ir/StreamReader.cpp | 8 ++++---- src/clp_ffi_js/ir/StreamReader.hpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index db75a22a..74682d3a 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -246,9 +246,9 @@ StreamReader::StreamReader( StreamReaderDataContext>( std::move(stream_reader_data_context) )}, - m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()}, - m_encoded_log_events(), - m_filtered_log_event_map(std::nullopt) {} + m_encoded_log_events(), + m_filtered_log_event_map(std::nullopt), + m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} } // namespace clp_ffi_js::ir namespace { @@ -258,7 +258,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { "Array<[string, number, number, number]>" ); emscripten::register_type( - "number[] + "number[]" ); emscripten::class_("ClpIrStreamReader") diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 1933314e..6868d532 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -97,11 +97,11 @@ class StreamReader { stream_reader_data_context); // Variables - std::unique_ptr> - m_stream_reader_data_context; - clp::TimestampPattern m_ts_pattern; std::vector> m_encoded_log_events; + std::unique_ptr> + m_stream_reader_data_context; std::optional> m_filtered_log_event_map; + clp::TimestampPattern m_ts_pattern; }; } // namespace clp_ffi_js::ir From d878399fd5e2b7900e19d4381ef862f8f6439ebf Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 18:46:22 +0000 Subject: [PATCH 14/47] junhao review --- src/clp_ffi_js/ir/StreamReader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 74682d3a..69a9e7ff 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -246,8 +246,6 @@ StreamReader::StreamReader( StreamReaderDataContext>( std::move(stream_reader_data_context) )}, - m_encoded_log_events(), - m_filtered_log_event_map(std::nullopt), m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} } // namespace clp_ffi_js::ir From d2e3d1dc066d5f805d0e88e1d522ad85c18a4e82 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 2 Oct 2024 18:59:40 +0000 Subject: [PATCH 15/47] more changes --- src/clp_ffi_js/ir/LogViewerEvent.hpp | 1 - src/clp_ffi_js/ir/StreamReader.cpp | 11 ++++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/clp_ffi_js/ir/LogViewerEvent.hpp b/src/clp_ffi_js/ir/LogViewerEvent.hpp index f86d947d..1eefe002 100644 --- a/src/clp_ffi_js/ir/LogViewerEvent.hpp +++ b/src/clp_ffi_js/ir/LogViewerEvent.hpp @@ -34,7 +34,6 @@ template auto LogViewerEvent::get_log_level() const -> size_t { return m_log_level; } - } // namespace clp_ffi_js::ir #endif // CLP_FFI_JS_IR_LOG_VIEWER_EVENT_HPP diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 69a9e7ff..439654b7 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -144,7 +144,12 @@ auto StreamReader::build() -> size_t { log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); } - const auto log_viewer_event = LogViewerEvent(log_event.get_timestamp(), log_event.get_utc_offset(), message, log_level); + const auto log_viewer_event = LogViewerEvent( + log_event.get_timestamp(), + log_event.get_utc_offset(), + message, + log_level + ); m_encoded_log_events.emplace_back(std::move(log_viewer_event)); continue; @@ -230,7 +235,7 @@ void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { m_filtered_log_event_map.emplace(); std::vector filter_levels = emscripten::vecFromJSArray(logLevelFilter); - // Filter log events based on the provided log levels + for (size_t index = 0; index < m_encoded_log_events.size(); ++index) { const auto& logEvent = m_encoded_log_events[index]; if (std::find(filter_levels.begin(), filter_levels.end(), logEvent.get_log_level()) != filter_levels.end()) { @@ -246,7 +251,7 @@ StreamReader::StreamReader( StreamReaderDataContext>( std::move(stream_reader_data_context) )}, - m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} + m_ts_pattern{m_stream_reader_data_context->get_deserializer().get_timestamp_pattern()} {} } // namespace clp_ffi_js::ir namespace { From b1f1afddf2a6ad3a8a3af4eb8dc69e1a7cbfda61 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 16:48:03 +0000 Subject: [PATCH 16/47] change log viewer event name --- .../ir/{LogViewerEvent.hpp => LogEventWithLevel.hpp} | 12 ++++++------ src/clp_ffi_js/ir/StreamReader.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) rename src/clp_ffi_js/ir/{LogViewerEvent.hpp => LogEventWithLevel.hpp} (72%) diff --git a/src/clp_ffi_js/ir/LogViewerEvent.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp similarity index 72% rename from src/clp_ffi_js/ir/LogViewerEvent.hpp rename to src/clp_ffi_js/ir/LogEventWithLevel.hpp index 1eefe002..23913870 100644 --- a/src/clp_ffi_js/ir/LogViewerEvent.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -1,5 +1,5 @@ -#ifndef CLP_FFI_JS_IR_LOG_VIEWER_EVENT_HPP -#define CLP_FFI_JS_IR_LOG_VIEWER_EVENT_HPP +#ifndef CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP +#define CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP #include #include @@ -11,10 +11,10 @@ namespace clp_ffi_js::ir { * @tparam encoded_variable_t The type of encoded variables in the event */ template -class LogViewerEvent : public clp::ir::LogEvent { +class LogEventWithLevel : public clp::ir::LogEvent { public: // Constructors - LogViewerEvent( + LogEventWithLevel( clp::ir::epoch_time_ms_t timestamp, clp::UtcOffset utc_offset, clp::ir::EncodedTextAst message, @@ -31,9 +31,9 @@ class LogViewerEvent : public clp::ir::LogEvent { }; template -auto LogViewerEvent::get_log_level() const -> size_t { +auto LogEventWithLevel::get_log_level() const -> size_t { return m_log_level; } } // namespace clp_ffi_js::ir -#endif // CLP_FFI_JS_IR_LOG_VIEWER_EVENT_HPP +#endif // CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 439654b7..11348409 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include using namespace std::literals::string_literals; @@ -144,7 +144,7 @@ auto StreamReader::build() -> size_t { log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); } - const auto log_viewer_event = LogViewerEvent( + const auto log_viewer_event = LogEventWithLevel( log_event.get_timestamp(), log_event.get_utc_offset(), message, From 0b3dd233d90f5c54e5bb23b9737c7aa7fdaa7a9f Mon Sep 17 00:00:00 2001 From: davemarco <83603688+davemarco@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:56:42 -0400 Subject: [PATCH 17/47] Apply suggestions from code review Co-authored-by: Junhao Liao --- src/clp_ffi_js/ir/StreamReader.cpp | 10 +++++----- src/clp_ffi_js/ir/StreamReader.hpp | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 11348409..4fb06b57 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -128,7 +128,8 @@ auto StreamReader::build() -> size_t { constexpr size_t cLogLevelPositionInMessages{1}; if (logtype.length() < cLogLevelPositionInMessages) { - SPDLOG_ERROR("Failed to extract log type for log level parsing."); break; + SPDLOG_WARN("Message is too short to extract log level."); + break; } size_t log_level{cLogLevelNone}; @@ -236,10 +237,9 @@ void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { m_filtered_log_event_map.emplace(); std::vector filter_levels = emscripten::vecFromJSArray(logLevelFilter); - for (size_t index = 0; index < m_encoded_log_events.size(); ++index) { - const auto& logEvent = m_encoded_log_events[index]; - if (std::find(filter_levels.begin(), filter_levels.end(), logEvent.get_log_level()) != filter_levels.end()) { - m_filtered_log_event_map->push_back(index); + for (const auto& [logEventIdx, logEvent] : std::views::enumerate(m_encoded_log_events)) { + if (std::ranges::find(filter_levels, logEvent.get_log_level()) != filter_levels.end()) { + m_filtered_log_event_map->push_back(logEventIdx); } } } diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 6868d532..c636e705 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -58,8 +58,7 @@ class StreamReader { [[nodiscard]] auto get_filtered_log_event_map() const -> FilteredLogEventMapType; /** - * Filters log events and generates `m_filtered_log_event_map`. If `logLevelFilter` is `null`, - * `m_filtered_log_event_map` will be set to `std::nullopt`. + * Generates a filtered collection from all log events. * * @param logLevelFilter Array of selected log levels */ @@ -79,14 +78,14 @@ class StreamReader { * * @param begin_idx * @param end_idx - * @param use_filter Whether to decode from the filtered or unfiltered log events collection. + * @param use_filter If true, decode from the filtered log events collection; otherwise, decode from the unfiltered one. * @return An array where each element is a decoded log event represented by an array of: * - The log event's message * - The log event's timestamp as milliseconds since the Unix epoch * - The log event's log level as an integer that indexes into `cLogLevelNames` * - The log event's number (1-indexed) in the stream * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number - * of log events in collection) + * of log events in the collection). */ [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; From c3d13bef4ef3d17595ec46ce145caea7efd673e3 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 17:20:50 +0000 Subject: [PATCH 18/47] run linter --- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 5 ++-- src/clp_ffi_js/ir/StreamReader.cpp | 38 ++++++++++++------------- src/clp_ffi_js/ir/StreamReader.hpp | 13 +++++---- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index 23913870..75d324e3 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -1,9 +1,10 @@ #ifndef CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP #define CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP -#include #include +#include + namespace clp_ffi_js::ir { /** @@ -36,4 +37,4 @@ auto LogEventWithLevel::get_log_level() const -> size_t { } } // namespace clp_ffi_js::ir -#endif // CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP +#endif // CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 4fb06b57..5d49ccb8 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -100,7 +100,7 @@ auto StreamReader::get_num_events_buffered() const -> size_t { return m_encoded_log_events.size(); } -auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapType { +auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapType { if (std::nullopt == m_filtered_log_event_map) { return FilteredLogEventMapType(emscripten::val::null()); } @@ -119,9 +119,8 @@ auto StreamReader::build() -> size_t { while (true) { auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; if (false == result.has_error()) { - - const auto log_event = result.value(); - const auto message = log_event.get_message(); + auto const log_event = result.value(); + auto const message = log_event.get_message(); logtype.clear(); logtype = message.get_logtype(); @@ -145,11 +144,11 @@ auto StreamReader::build() -> size_t { log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); } - const auto log_viewer_event = LogEventWithLevel( - log_event.get_timestamp(), - log_event.get_utc_offset(), - message, - log_level + auto const log_viewer_event = LogEventWithLevel( + log_event.get_timestamp(), + log_event.get_utc_offset(), + message, + log_level ); m_encoded_log_events.emplace_back(std::move(log_viewer_event)); @@ -175,8 +174,8 @@ auto StreamReader::build() -> size_t { return m_encoded_log_events.size(); } -auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType { - +auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const + -> DecodedResultsTsType { if (use_filter && (std::nullopt == m_filtered_log_event_map)) { return DecodedResultsTsType(emscripten::val::null()); } @@ -203,7 +202,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte } else { log_event_idx = i; } - const auto& log_event = m_encoded_log_events[log_event_idx]; + auto const& log_event = m_encoded_log_events[log_event_idx]; message.clear(); auto const parsed{log_event.get_message().decode_and_unparse()}; @@ -221,14 +220,14 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte message.c_str(), log_event.get_timestamp(), log_event.get_log_level(), - log_event_idx +1 + log_event_idx + 1 ); } return DecodedResultsTsType(results); } -void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { +void StreamReader::filter_log_events(emscripten::val const& logLevelFilter) { if (logLevelFilter.isNull()) { m_filtered_log_event_map.reset(); return; @@ -237,7 +236,7 @@ void StreamReader::filter_log_events(const emscripten::val& logLevelFilter) { m_filtered_log_event_map.emplace(); std::vector filter_levels = emscripten::vecFromJSArray(logLevelFilter); - for (const auto& [logEventIdx, logEvent] : std::views::enumerate(m_encoded_log_events)) { + for (auto const& [logEventIdx, logEvent] : std::views::enumerate(m_encoded_log_events)) { if (std::ranges::find(filter_levels, logEvent.get_log_level()) != filter_levels.end()) { m_filtered_log_event_map->push_back(logEventIdx); } @@ -260,9 +259,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { emscripten::register_type( "Array<[string, number, number, number]>" ); - emscripten::register_type( - "number[]" - ); + emscripten::register_type("number[]"); emscripten::class_("ClpIrStreamReader") .constructor( @@ -273,7 +270,10 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { "getNumEventsBuffered", &clp_ffi_js::ir::StreamReader::get_num_events_buffered ) - .function("getFilteredLogEventMap", &clp_ffi_js::ir::StreamReader::get_filtered_log_event_map) + .function( + "getFilteredLogEventMap", + &clp_ffi_js::ir::StreamReader::get_filtered_log_event_map + ) .function("build", &clp_ffi_js::ir::StreamReader::build) .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) .function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events); diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index c636e705..6e1cc225 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -12,8 +12,8 @@ #include #include -#include #include +#include namespace clp_ffi_js::ir { EMSCRIPTEN_DECLARE_VAL_TYPE(DataArrayTsType); @@ -62,7 +62,7 @@ class StreamReader { * * @param logLevelFilter Array of selected log levels */ - void filter_log_events(const emscripten::val& logLevelFilter); + void filter_log_events(emscripten::val const& logLevelFilter); /** * Deserializes all log events in the file. After the stream has been exhausted, it will be @@ -78,7 +78,8 @@ class StreamReader { * * @param begin_idx * @param end_idx - * @param use_filter If true, decode from the filtered log events collection; otherwise, decode from the unfiltered one. + * @param use_filter If true, decode from the filtered log events collection; otherwise, decode + * from the unfiltered one. * @return An array where each element is a decoded log event represented by an array of: * - The log event's message * - The log event's timestamp as milliseconds since the Unix epoch @@ -87,8 +88,8 @@ class StreamReader { * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number * of log events in the collection). */ - [[nodiscard]] auto decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; - + [[nodiscard]] auto + decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType; private: // Constructor @@ -98,7 +99,7 @@ class StreamReader { // Variables std::vector> m_encoded_log_events; std::unique_ptr> - m_stream_reader_data_context; + m_stream_reader_data_context; std::optional> m_filtered_log_event_map; clp::TimestampPattern m_ts_pattern; }; From 14d49778d816c7e536b27424c5ef3b5323e3b814 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 17:29:15 +0000 Subject: [PATCH 19/47] change error logic for short logs, as there is n reason to actually break --- src/clp_ffi_js/ir/StreamReader.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 5d49ccb8..385dd8d3 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -126,22 +126,20 @@ auto StreamReader::build() -> size_t { logtype = message.get_logtype(); constexpr size_t cLogLevelPositionInMessages{1}; - if (logtype.length() < cLogLevelPositionInMessages) { - SPDLOG_WARN("Message is too short to extract log level."); - break; - } - size_t log_level{cLogLevelNone}; - // NOLINTNEXTLINE(readability-qualified-auto) - auto const log_level_name_it{std::find_if( - cLogLevelNames.begin() + cValidLogLevelsBeginIdx, - cLogLevelNames.end(), - [&](std::string_view level) { - return logtype.substr(cLogLevelPositionInMessages).starts_with(level); - } - )}; - if (log_level_name_it != cLogLevelNames.end()) { - log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); + if (logtype.length() > cLogLevelPositionInMessages) { + // NOLINTNEXTLINE(readability-qualified-auto) + auto const log_level_name_it{std::find_if( + cLogLevelNames.begin() + cValidLogLevelsBeginIdx, + cLogLevelNames.end(), + [&](std::string_view level) { + return logtype.substr(cLogLevelPositionInMessages) + .starts_with(level); + } + )}; + if (log_level_name_it != cLogLevelNames.end()) { + log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); + } } auto const log_viewer_event = LogEventWithLevel( @@ -150,7 +148,6 @@ auto StreamReader::build() -> size_t { message, log_level ); - m_encoded_log_events.emplace_back(std::move(log_viewer_event)); continue; } From f4d2fd8816aa1932cd2f5f3323b04bc2e3731355 Mon Sep 17 00:00:00 2001 From: davemarco <83603688+davemarco@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:07:21 -0400 Subject: [PATCH 20/47] Apply suggestions from code review Co-authored-by: Junhao Liao --- src/clp_ffi_js/ir/StreamReader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 385dd8d3..4f6bfbd4 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -142,12 +142,12 @@ auto StreamReader::build() -> size_t { } } - auto const log_viewer_event = LogEventWithLevel( + auto const log_viewer_event{LogEventWithLevel( log_event.get_timestamp(), log_event.get_utc_offset(), message, log_level - ); + )}; m_encoded_log_events.emplace_back(std::move(log_viewer_event)); continue; } From cf093ee3df4b649ae294cbf424c3158adb9abe10 Mon Sep 17 00:00:00 2001 From: davemarco <83603688+davemarco@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:07:38 -0400 Subject: [PATCH 21/47] Apply suggestions from code review Co-authored-by: Junhao Liao --- src/clp_ffi_js/ir/StreamReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 4f6bfbd4..1235746a 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -199,7 +199,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte } else { log_event_idx = i; } - auto const& log_event = m_encoded_log_events[log_event_idx]; + auto const& log_event{m_encoded_log_events[log_event_idx]}; message.clear(); auto const parsed{log_event.get_message().decode_and_unparse()}; From 09656b435889d0bfaedb13095ea21d20e513b2c5 Mon Sep 17 00:00:00 2001 From: davemarco <83603688+davemarco@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:08:07 -0400 Subject: [PATCH 22/47] Apply suggestions from code review Co-authored-by: Junhao Liao --- src/clp_ffi_js/ir/StreamReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 1235746a..d5bec036 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -231,7 +231,7 @@ void StreamReader::filter_log_events(emscripten::val const& logLevelFilter) { } m_filtered_log_event_map.emplace(); - std::vector filter_levels = emscripten::vecFromJSArray(logLevelFilter); + auto filter_levels{emscripten::vecFromJSArray(logLevelFilter)}; for (auto const& [logEventIdx, logEvent] : std::views::enumerate(m_encoded_log_events)) { if (std::ranges::find(filter_levels, logEvent.get_log_level()) != filter_levels.end()) { From 65a788f20f855fff4373e0207685e97b36d077da Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 20:28:59 +0000 Subject: [PATCH 23/47] junhao review --- src/clp_ffi_js/constants.hpp | 13 +++- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 9 +-- src/clp_ffi_js/ir/StreamReader.cpp | 90 +++++++++++++------------ tools/yscope-dev-utils | 2 +- 4 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index 9bf336a9..7f0161fc 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -2,12 +2,19 @@ #define CLP_FFI_JS_CONSTANTS_HPP #include -#include #include namespace clp_ffi_js { -constexpr size_t cLogLevelNone{0}; -constexpr size_t cValidLogLevelsBeginIdx{cLogLevelNone + 1}; +enum class LogLevel { + NONE, // This should not be used. + TRACE, + DEBUG, + INFO, + WARN, + ERROR, + FATAL, +}; +constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::TRACE}; constexpr std::array cLogLevelNames{ "NONE", // This should not be used. "TRACE", diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index 75d324e3..36bd1967 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace clp_ffi_js::ir { @@ -19,20 +20,20 @@ class LogEventWithLevel : public clp::ir::LogEvent { clp::ir::epoch_time_ms_t timestamp, clp::UtcOffset utc_offset, clp::ir::EncodedTextAst message, - size_t log_level + LogLevel log_level ) : clp::ir::LogEvent(timestamp, utc_offset, std::move(message)), m_log_level{log_level} {} // Methods - [[nodiscard]] auto get_log_level() const -> size_t; + [[nodiscard]] auto get_log_level() const -> LogLevel; private: - size_t m_log_level; + LogLevel m_log_level; }; template -auto LogEventWithLevel::get_log_level() const -> size_t { +auto LogEventWithLevel::get_log_level() const -> LogLevel { return m_log_level; } } // namespace clp_ffi_js::ir diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index d5bec036..d194f2e4 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -118,55 +118,57 @@ auto StreamReader::build() -> size_t { logtype.reserve(cDefaultReservedMessageLength); while (true) { auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; - if (false == result.has_error()) { - auto const log_event = result.value(); - auto const message = log_event.get_message(); - - logtype.clear(); - logtype = message.get_logtype(); - - constexpr size_t cLogLevelPositionInMessages{1}; - size_t log_level{cLogLevelNone}; - if (logtype.length() > cLogLevelPositionInMessages) { - // NOLINTNEXTLINE(readability-qualified-auto) - auto const log_level_name_it{std::find_if( - cLogLevelNames.begin() + cValidLogLevelsBeginIdx, - cLogLevelNames.end(), - [&](std::string_view level) { - return logtype.substr(cLogLevelPositionInMessages) - .starts_with(level); - } - )}; - if (log_level_name_it != cLogLevelNames.end()) { - log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); - } + if (result.has_error()) { + auto const error{result.error()}; + if (std::errc::no_message_available == error) { + break; } - - auto const log_viewer_event{LogEventWithLevel( - log_event.get_timestamp(), - log_event.get_utc_offset(), - message, - log_level - )}; - m_encoded_log_events.emplace_back(std::move(log_viewer_event)); - continue; + if (std::errc::result_out_of_range == error) { + SPDLOG_ERROR("File contains an incomplete IR stream"); + break; + } + throw ClpFfiJsException{ + clp::ErrorCode::ErrorCode_Corrupt, + __FILENAME__, + __LINE__, + "Failed to deserialize: "s + error.category().name() + ":" + error.message() + }; } - auto const error{result.error()}; - if (std::errc::no_message_available == error) { - break; + auto const log_event = result.value(); + auto const message = log_event.get_message(); + + logtype.clear(); + logtype = message.get_logtype(); + + constexpr size_t cLogLevelPositionInMessages{1}; + LogLevel log_level{LogLevel::NONE}; + if (logtype.length() > cLogLevelPositionInMessages) { + // NOLINTNEXTLINE(readability-qualified-auto) + auto const log_level_name_it{std::find_if( + cLogLevelNames.begin() + cValidLogLevelsBeginIdx, + cLogLevelNames.end(), + [&](std::string_view level) { + return logtype.substr(cLogLevelPositionInMessages) + .starts_with(level); + } + )}; + if (log_level_name_it != cLogLevelNames.end()) { + log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); + } } - if (std::errc::result_out_of_range == error) { - SPDLOG_ERROR("File contains an incomplete IR stream"); - break; + + auto const log_viewer_event{LogEventWithLevel( + log_event.get_timestamp(), + log_event.get_utc_offset(), + message, + log_level + )}; + m_encoded_log_events.emplace_back(std::move(log_viewer_event)); + continue; } - throw ClpFfiJsException{ - clp::ErrorCode::ErrorCode_Corrupt, - __FILENAME__, - __LINE__, - "Failed to deserialize: "s + error.category().name() + ":" + error.message() - }; } m_stream_reader_data_context.reset(nullptr); + } return m_encoded_log_events.size(); } @@ -235,7 +237,7 @@ void StreamReader::filter_log_events(emscripten::val const& logLevelFilter) { for (auto const& [logEventIdx, logEvent] : std::views::enumerate(m_encoded_log_events)) { if (std::ranges::find(filter_levels, logEvent.get_log_level()) != filter_levels.end()) { - m_filtered_log_event_map->push_back(logEventIdx); + m_filtered_log_event_map->emplace_back(logEventIdx); } } } diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils index 159768c7..92cd10da 160000 --- a/tools/yscope-dev-utils +++ b/tools/yscope-dev-utils @@ -1 +1 @@ -Subproject commit 159768c7d171595ed2cba17b758c10043a2efe96 +Subproject commit 92cd10da59a6c2fa5c5182ff7ca0c3d7862a7113 From ca2a0eb3a91cda509ff1bc2478e0c3b765c7d882 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 20:32:36 +0000 Subject: [PATCH 24/47] small change --- src/clp_ffi_js/constants.hpp | 2 +- src/clp_ffi_js/ir/StreamReader.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index 7f0161fc..48fafb8a 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -6,7 +6,7 @@ namespace clp_ffi_js { enum class LogLevel { - NONE, // This should not be used. + NONE, TRACE, DEBUG, INFO, diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index d194f2e4..82331eac 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -119,7 +119,7 @@ auto StreamReader::build() -> size_t { while (true) { auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; if (result.has_error()) { - auto const error{result.error()}; + auto const error{result.error()}; if (std::errc::no_message_available == error) { break; } From a912eebf8674855d14724971362d536b10d678da Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 20:41:43 +0000 Subject: [PATCH 25/47] fix braces --- src/clp_ffi_js/ir/StreamReader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 82331eac..ba0502e0 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -165,7 +165,6 @@ auto StreamReader::build() -> size_t { )}; m_encoded_log_events.emplace_back(std::move(log_viewer_event)); continue; - } } m_stream_reader_data_context.reset(nullptr); From b7c28c9b4ca0c880f0f1eb4998083f1dcfe56c38 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 20:43:10 +0000 Subject: [PATCH 26/47] line issue --- src/clp_ffi_js/ir/StreamReader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index ba0502e0..10e0b9a2 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -167,7 +167,6 @@ auto StreamReader::build() -> size_t { continue; } m_stream_reader_data_context.reset(nullptr); - } return m_encoded_log_events.size(); } From 8f81a5170f10bd0917fe0e30b2fda69906be0802 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 20:43:39 +0000 Subject: [PATCH 27/47] add line back --- src/clp_ffi_js/ir/StreamReader.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 10e0b9a2..fae3c999 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -168,6 +168,7 @@ auto StreamReader::build() -> size_t { } m_stream_reader_data_context.reset(nullptr); } + return m_encoded_log_events.size(); } From 5be897449d0c9f4d8b40513d3310a0d22b02acee Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 20:51:05 +0000 Subject: [PATCH 28/47] submodule fix? --- tools/yscope-dev-utils | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils index 92cd10da..159768c7 160000 --- a/tools/yscope-dev-utils +++ b/tools/yscope-dev-utils @@ -1 +1 @@ -Subproject commit 92cd10da59a6c2fa5c5182ff7ca0c3d7862a7113 +Subproject commit 159768c7d171595ed2cba17b758c10043a2efe96 From fce620e95b91bd1d76ebffe3dc8a64a7a2d879da Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 20:54:21 +0000 Subject: [PATCH 29/47] fix new name --- src/clp_ffi_js/ir/StreamReader.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 6e1cc225..0f8671a8 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include namespace clp_ffi_js::ir { @@ -97,7 +97,7 @@ class StreamReader { stream_reader_data_context); // Variables - std::vector> m_encoded_log_events; + std::vector> m_encoded_log_events; std::unique_ptr> m_stream_reader_data_context; std::optional> m_filtered_log_event_map; From 47b9fed47c99867d53a20f71b89b948c685e37f6 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Sat, 5 Oct 2024 20:58:25 +0000 Subject: [PATCH 30/47] fix lint --- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 1 + src/clp_ffi_js/ir/StreamReader.cpp | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index 36bd1967..3839f8d2 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -4,6 +4,7 @@ #include #include + #include namespace clp_ffi_js::ir { diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index fae3c999..f0b303bd 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -148,8 +148,7 @@ auto StreamReader::build() -> size_t { cLogLevelNames.begin() + cValidLogLevelsBeginIdx, cLogLevelNames.end(), [&](std::string_view level) { - return logtype.substr(cLogLevelPositionInMessages) - .starts_with(level); + return logtype.substr(cLogLevelPositionInMessages).starts_with(level); } )}; if (log_level_name_it != cLogLevelNames.end()) { From e8b732cd0dfc92fd36e93a92e79ea1d30b56dc84 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Mon, 7 Oct 2024 16:14:46 +0000 Subject: [PATCH 31/47] small change to trigger workflow --- src/clp_ffi_js/ir/StreamReader.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 0f8671a8..7d5e3b3d 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -85,7 +85,7 @@ class StreamReader { * - The log event's timestamp as milliseconds since the Unix epoch * - The log event's log level as an integer that indexes into `cLogLevelNames` * - The log event's number (1-indexed) in the stream - * @return null if any log event in the range doesn't exist (e.g., the range exceeds the number + * @return null if any log event in the range doesn't exist (e.g. the range exceeds the number * of log events in the collection). */ [[nodiscard]] auto From a273e33317c7c175ad41bcea521c15821e7ea70f Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Mon, 7 Oct 2024 17:54:55 +0000 Subject: [PATCH 32/47] fix clang --- src/clp_ffi_js/constants.hpp | 3 ++- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 3 +++ src/clp_ffi_js/ir/StreamReader.cpp | 31 +++++++++++++------------ src/clp_ffi_js/ir/StreamReader.hpp | 3 +-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index 48fafb8a..767d1026 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -2,10 +2,11 @@ #define CLP_FFI_JS_CONSTANTS_HPP #include +#include #include namespace clp_ffi_js { -enum class LogLevel { +enum class LogLevel : std::uint8_t { NONE, TRACE, DEBUG, diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index 3839f8d2..2ff3d446 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -3,7 +3,10 @@ #include +#include #include +#include +#include #include diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index f0b303bd..fc6da843 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -134,8 +133,8 @@ auto StreamReader::build() -> size_t { "Failed to deserialize: "s + error.category().name() + ":" + error.message() }; } - auto const log_event = result.value(); - auto const message = log_event.get_message(); + auto const& log_event = result.value(); + auto const& message = log_event.get_message(); logtype.clear(); logtype = message.get_logtype(); @@ -145,14 +144,16 @@ auto StreamReader::build() -> size_t { if (logtype.length() > cLogLevelPositionInMessages) { // NOLINTNEXTLINE(readability-qualified-auto) auto const log_level_name_it{std::find_if( - cLogLevelNames.begin() + cValidLogLevelsBeginIdx, + cLogLevelNames.begin() + static_cast(cValidLogLevelsBeginIdx), cLogLevelNames.end(), [&](std::string_view level) { return logtype.substr(cLogLevelPositionInMessages).starts_with(level); } )}; if (log_level_name_it != cLogLevelNames.end()) { - log_level = std::distance(cLogLevelNames.begin(), log_level_name_it); + log_level = static_cast( + std::distance(cLogLevelNames.begin(), log_level_name_it) + ); } } @@ -162,8 +163,7 @@ auto StreamReader::build() -> size_t { message, log_level )}; - m_encoded_log_events.emplace_back(std::move(log_viewer_event)); - continue; + m_encoded_log_events.emplace_back(log_viewer_event); } m_stream_reader_data_context.reset(nullptr); } @@ -177,7 +177,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte return DecodedResultsTsType(emscripten::val::null()); } - size_t length; + size_t length{0}; if (use_filter) { length = m_filtered_log_event_map->size(); } else { @@ -193,7 +193,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte auto const results{emscripten::val::array()}; for (size_t i = begin_idx; i < end_idx; ++i) { - size_t log_event_idx; + size_t log_event_idx = 0; if (use_filter) { log_event_idx = m_filtered_log_event_map->at(i); } else { @@ -224,18 +224,19 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte return DecodedResultsTsType(results); } -void StreamReader::filter_log_events(emscripten::val const& logLevelFilter) { - if (logLevelFilter.isNull()) { +void StreamReader::filter_log_events(emscripten::val const& log_level_filter) { + if (log_level_filter.isNull()) { m_filtered_log_event_map.reset(); return; } m_filtered_log_event_map.emplace(); - auto filter_levels{emscripten::vecFromJSArray(logLevelFilter)}; + std::vector filter_levels{emscripten::vecFromJSArray(log_level_filter)}; - for (auto const& [logEventIdx, logEvent] : std::views::enumerate(m_encoded_log_events)) { - if (std::ranges::find(filter_levels, logEvent.get_log_level()) != filter_levels.end()) { - m_filtered_log_event_map->emplace_back(logEventIdx); + for (size_t log_event_idx = 0; log_event_idx < m_encoded_log_events.size(); ++log_event_idx) { + auto const& log_event = m_encoded_log_events[log_event_idx]; + if (std::ranges::find(filter_levels, log_event.get_log_level()) != filter_levels.end()) { + m_filtered_log_event_map->emplace_back(log_event_idx); } } } diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 7d5e3b3d..c7f49931 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -62,7 +61,7 @@ class StreamReader { * * @param logLevelFilter Array of selected log levels */ - void filter_log_events(emscripten::val const& logLevelFilter); + void filter_log_events(emscripten::val const& log_level_filter); /** * Deserializes all log events in the file. After the stream has been exhausted, it will be From 0a09a45fe8b498cf72fc9f973c50017b57ea159c Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Tue, 8 Oct 2024 00:25:28 +0000 Subject: [PATCH 33/47] fix previous mistake? fixing linting error --- src/clp_ffi_js/ir/StreamReader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index fc6da843..8181961a 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -157,13 +157,13 @@ auto StreamReader::build() -> size_t { } } - auto const log_viewer_event{LogEventWithLevel( + auto log_viewer_event{LogEventWithLevel( log_event.get_timestamp(), log_event.get_utc_offset(), message, log_level )}; - m_encoded_log_events.emplace_back(log_viewer_event); + m_encoded_log_events.emplace_back(std::move(log_viewer_event)); } m_stream_reader_data_context.reset(nullptr); } From ed140f150af04a966ad0c7f8d598c471ebb4fc3f Mon Sep 17 00:00:00 2001 From: davemarco <83603688+davemarco@users.noreply.github.com> Date: Wed, 9 Oct 2024 14:28:41 -0400 Subject: [PATCH 34/47] Apply suggestions from code review Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> --- src/clp_ffi_js/constants.hpp | 11 ++++++++++- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 7 +++++-- src/clp_ffi_js/ir/StreamReader.cpp | 1 - src/clp_ffi_js/ir/StreamReader.hpp | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index 767d1026..5a7c0079 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -6,8 +6,11 @@ #include namespace clp_ffi_js { +/** +* Enum of known log levels. +*/ enum class LogLevel : std::uint8_t { - NONE, + NONE = 0, TRACE, DEBUG, INFO, @@ -16,6 +19,12 @@ enum class LogLevel : std::uint8_t { FATAL, }; constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::TRACE}; + +/** +* Strings corresponding to `LogLevel`. +* +* NOTE: These must be kept in sync manually. +*/ constexpr std::array cLogLevelNames{ "NONE", // This should not be used. "TRACE", diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index 2ff3d446..f72185af 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -13,7 +13,10 @@ namespace clp_ffi_js::ir { /** - * A class derived from LogEvent with an additional member for log level. + * A class derived from `clp::ir::LogEvent` with an additional member for the log level. + * + * NOTE: Once we move to the next IR format, this class should no longer be necessary since each + * IR log event will contain a set of key-value pairs, one of which should be the log level. * @tparam encoded_variable_t The type of encoded variables in the event */ template @@ -26,7 +29,7 @@ class LogEventWithLevel : public clp::ir::LogEvent { clp::ir::EncodedTextAst message, LogLevel log_level ) - : clp::ir::LogEvent(timestamp, utc_offset, std::move(message)), + : clp::ir::LogEvent{timestamp, utc_offset, std::move(message)}, m_log_level{log_level} {} // Methods diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 8181961a..58dbae4d 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -138,7 +138,6 @@ auto StreamReader::build() -> size_t { logtype.clear(); logtype = message.get_logtype(); - constexpr size_t cLogLevelPositionInMessages{1}; LogLevel log_level{LogLevel::NONE}; if (logtype.length() > cLogLevelPositionInMessages) { diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index c7f49931..863174f2 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -59,7 +59,7 @@ class StreamReader { /** * Generates a filtered collection from all log events. * - * @param logLevelFilter Array of selected log levels + * @param log_level_filter Array of selected log levels */ void filter_log_events(emscripten::val const& log_level_filter); From 81e7739238429e6e2361f4b5a5fb99420418a4e6 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 9 Oct 2024 19:12:31 +0000 Subject: [PATCH 35/47] fix lint --- src/clp_ffi_js/constants.hpp | 16 ++-- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 6 +- src/clp_ffi_js/ir/StreamReader.cpp | 114 ++++++++++++------------ src/clp_ffi_js/ir/StreamReader.hpp | 4 +- 4 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index 5a7c0079..432b5524 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -7,10 +7,10 @@ namespace clp_ffi_js { /** -* Enum of known log levels. -*/ + * Enum of known log levels. + */ enum class LogLevel : std::uint8_t { - NONE = 0, + NONE = 0, // This should not be used. TRACE, DEBUG, INFO, @@ -21,12 +21,12 @@ enum class LogLevel : std::uint8_t { constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::TRACE}; /** -* Strings corresponding to `LogLevel`. -* -* NOTE: These must be kept in sync manually. -*/ + * Strings corresponding to `LogLevel`. + * + * NOTE: These must be kept in sync manually. + */ constexpr std::array cLogLevelNames{ - "NONE", // This should not be used. + "NONE", "TRACE", "DEBUG", "INFO", diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index f72185af..63fbedb1 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -1,5 +1,5 @@ -#ifndef CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP -#define CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP +#ifndef CLP_FFI_JS_IR_LOGEVENTWITHLEVEL_HPP +#define CLP_FFI_JS_IR_LOGEVENTWITHLEVEL_HPP #include @@ -45,4 +45,4 @@ auto LogEventWithLevel::get_log_level() const -> LogLevel { } } // namespace clp_ffi_js::ir -#endif // CLP_FFI_JS_IR_LOG_EVENT_WITH_LEVEL_HPP +#endif // CLP_FFI_JS_IR_LOGEVENTWITHLEVEL_HPP diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 58dbae4d..41e47227 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -99,74 +99,74 @@ auto StreamReader::get_num_events_buffered() const -> size_t { return m_encoded_log_events.size(); } -auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapType { +auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapTsType { if (std::nullopt == m_filtered_log_event_map) { - return FilteredLogEventMapType(emscripten::val::null()); + return FilteredLogEventMapTsType(emscripten::val::null()); } - return FilteredLogEventMapType(emscripten::val::array(m_filtered_log_event_map.value())); + return FilteredLogEventMapTsType(emscripten::val::array(m_filtered_log_event_map.value())); } auto StreamReader::build() -> size_t { - if (nullptr != m_stream_reader_data_context) { - constexpr size_t cDefaultNumReservedLogEvents{500'000}; - m_encoded_log_events.reserve(cDefaultNumReservedLogEvents); + if (nullptr == m_stream_reader_data_context) { + return m_encoded_log_events.size(); + } + constexpr size_t cDefaultNumReservedLogEvents{500'000}; + m_encoded_log_events.reserve(cDefaultNumReservedLogEvents); - std::string logtype; - constexpr size_t cDefaultReservedMessageLength{512}; - logtype.reserve(cDefaultReservedMessageLength); - while (true) { - auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; - if (result.has_error()) { - auto const error{result.error()}; - if (std::errc::no_message_available == error) { - break; - } - if (std::errc::result_out_of_range == error) { - SPDLOG_ERROR("File contains an incomplete IR stream"); - break; - } - throw ClpFfiJsException{ - clp::ErrorCode::ErrorCode_Corrupt, - __FILENAME__, - __LINE__, - "Failed to deserialize: "s + error.category().name() + ":" + error.message() - }; + std::string logtype; + constexpr size_t cDefaultReservedMessageLength{512}; + logtype.reserve(cDefaultReservedMessageLength); + while (true) { + auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; + if (result.has_error()) { + auto const error{result.error()}; + if (std::errc::no_message_available == error) { + break; } - auto const& log_event = result.value(); - auto const& message = log_event.get_message(); - - logtype.clear(); - logtype = message.get_logtype(); - constexpr size_t cLogLevelPositionInMessages{1}; - LogLevel log_level{LogLevel::NONE}; - if (logtype.length() > cLogLevelPositionInMessages) { - // NOLINTNEXTLINE(readability-qualified-auto) - auto const log_level_name_it{std::find_if( - cLogLevelNames.begin() + static_cast(cValidLogLevelsBeginIdx), - cLogLevelNames.end(), - [&](std::string_view level) { - return logtype.substr(cLogLevelPositionInMessages).starts_with(level); - } - )}; - if (log_level_name_it != cLogLevelNames.end()) { - log_level = static_cast( - std::distance(cLogLevelNames.begin(), log_level_name_it) - ); - } + if (std::errc::result_out_of_range == error) { + SPDLOG_ERROR("File contains an incomplete IR stream"); + break; } - - auto log_viewer_event{LogEventWithLevel( - log_event.get_timestamp(), - log_event.get_utc_offset(), - message, - log_level + throw ClpFfiJsException{ + clp::ErrorCode::ErrorCode_Corrupt, + __FILENAME__, + __LINE__, + "Failed to deserialize: "s + error.category().name() + ":" + error.message() + }; + } + auto const& log_event = result.value(); + auto const& message = log_event.get_message(); + + logtype.clear(); + logtype = message.get_logtype(); + constexpr size_t cLogLevelPositionInMessages{1}; + LogLevel log_level{LogLevel::NONE}; + if (logtype.length() > cLogLevelPositionInMessages) { + // NOLINTNEXTLINE(readability-qualified-auto) + auto const log_level_name_it{std::find_if( + cLogLevelNames.begin() + static_cast(cValidLogLevelsBeginIdx), + cLogLevelNames.end(), + [&](std::string_view level) { + return logtype.substr(cLogLevelPositionInMessages).starts_with(level); + } )}; - m_encoded_log_events.emplace_back(std::move(log_viewer_event)); + if (log_level_name_it != cLogLevelNames.end()) { + log_level = static_cast( + std::distance(cLogLevelNames.begin(), log_level_name_it) + ); + } } - m_stream_reader_data_context.reset(nullptr); - } + auto log_viewer_event{LogEventWithLevel( + log_event.get_timestamp(), + log_event.get_utc_offset(), + message, + log_level + )}; + m_encoded_log_events.emplace_back(std::move(log_viewer_event)); + } + m_stream_reader_data_context.reset(nullptr); return m_encoded_log_events.size(); } @@ -256,7 +256,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { emscripten::register_type( "Array<[string, number, number, number]>" ); - emscripten::register_type("number[]"); + emscripten::register_type("number[]"); emscripten::class_("ClpIrStreamReader") .constructor( diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 863174f2..b6b9e413 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -17,7 +17,7 @@ namespace clp_ffi_js::ir { EMSCRIPTEN_DECLARE_VAL_TYPE(DataArrayTsType); EMSCRIPTEN_DECLARE_VAL_TYPE(DecodedResultsTsType); -EMSCRIPTEN_DECLARE_VAL_TYPE(FilteredLogEventMapType); +EMSCRIPTEN_DECLARE_VAL_TYPE(FilteredLogEventMapTsType); /** * Class to deserialize and decode Zstandard-compressed CLP IR streams as well as format decoded @@ -54,7 +54,7 @@ class StreamReader { /** * @return The filtered log events map. */ - [[nodiscard]] auto get_filtered_log_event_map() const -> FilteredLogEventMapType; + [[nodiscard]] auto get_filtered_log_event_map() const -> FilteredLogEventMapTsType; /** * Generates a filtered collection from all log events. From e96700544b9f5a476e879e583211c3bbd47eb99e Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 9 Oct 2024 20:04:53 +0000 Subject: [PATCH 36/47] rename member function --- src/clp_ffi_js/ir/StreamReader.cpp | 4 ++-- src/clp_ffi_js/ir/StreamReader.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 41e47227..4c99100e 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -107,7 +107,7 @@ auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapTsTy return FilteredLogEventMapTsType(emscripten::val::array(m_filtered_log_event_map.value())); } -auto StreamReader::build() -> size_t { +auto StreamReader::deserialize_stream() -> size_t { if (nullptr == m_stream_reader_data_context) { return m_encoded_log_events.size(); } @@ -271,7 +271,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { "getFilteredLogEventMap", &clp_ffi_js::ir::StreamReader::get_filtered_log_event_map ) - .function("build", &clp_ffi_js::ir::StreamReader::build) + .function("deserializeStream", &clp_ffi_js::ir::StreamReader::deserialize_stream) .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) .function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events); } diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index b6b9e413..2ab3c25e 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -69,7 +69,7 @@ class StreamReader { * * @return The number of successfully deserialized ("valid") log events. */ - [[nodiscard]] auto build() -> size_t; + [[nodiscard]] auto deserialize_stream() -> size_t; /** * Decodes log events in the range `[beginIdx, endIdx)` of the filtered or unfiltered From 55dabd40da705c8e7161bebc99c835e9593cc0c9 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 9 Oct 2024 23:13:37 +0000 Subject: [PATCH 37/47] remove clear --- src/clp_ffi_js/ir/StreamReader.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 4c99100e..cfb58a7d 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -138,7 +138,6 @@ auto StreamReader::deserialize_stream() -> size_t { auto const& log_event = result.value(); auto const& message = log_event.get_message(); - logtype.clear(); logtype = message.get_logtype(); constexpr size_t cLogLevelPositionInMessages{1}; LogLevel log_level{LogLevel::NONE}; @@ -199,14 +198,13 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte log_event_idx = i; } auto const& log_event{m_encoded_log_events[log_event_idx]}; - message.clear(); auto const parsed{log_event.get_message().decode_and_unparse()}; if (false == parsed.has_value()) { SPDLOG_ERROR("Failed to decode message."); break; } - message.append(parsed.value()); + message = parsed.value(); m_ts_pattern.insert_formatted_timestamp(log_event.get_timestamp(), message); From bd0371a19fd4a5420d6f62b7e0f2b25500a0c0cd Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 9 Oct 2024 23:18:33 +0000 Subject: [PATCH 38/47] inline --- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index 63fbedb1..38abf807 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -32,17 +32,13 @@ class LogEventWithLevel : public clp::ir::LogEvent { : clp::ir::LogEvent{timestamp, utc_offset, std::move(message)}, m_log_level{log_level} {} - // Methods - [[nodiscard]] auto get_log_level() const -> LogLevel; + [[nodiscard]] auto get_log_level() const -> LogLevel { + return m_log_level; + } private: LogLevel m_log_level; }; - -template -auto LogEventWithLevel::get_log_level() const -> LogLevel { - return m_log_level; -} } // namespace clp_ffi_js::ir #endif // CLP_FFI_JS_IR_LOGEVENTWITHLEVEL_HPP From 1c4ab8804babbe65995cf8a02a248a7afe960de2 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 9 Oct 2024 23:24:42 +0000 Subject: [PATCH 39/47] fix lint --- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index 38abf807..8dc6891f 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -32,9 +32,7 @@ class LogEventWithLevel : public clp::ir::LogEvent { : clp::ir::LogEvent{timestamp, utc_offset, std::move(message)}, m_log_level{log_level} {} - [[nodiscard]] auto get_log_level() const -> LogLevel { - return m_log_level; - } + [[nodiscard]] auto get_log_level() const -> LogLevel { return m_log_level; } private: LogLevel m_log_level; From 2b946ba317603a67502282fdbfc37de01e2de263 Mon Sep 17 00:00:00 2001 From: davemarco <83603688+davemarco@users.noreply.github.com> Date: Thu, 10 Oct 2024 09:22:55 -0400 Subject: [PATCH 40/47] Apply suggestions from code review Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> --- src/clp_ffi_js/ir/LogEventWithLevel.hpp | 1 - src/clp_ffi_js/ir/StreamReader.cpp | 27 +++++++++++-------------- src/clp_ffi_js/ir/StreamReader.hpp | 5 ++--- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/clp_ffi_js/ir/LogEventWithLevel.hpp b/src/clp_ffi_js/ir/LogEventWithLevel.hpp index 8dc6891f..22a00af3 100644 --- a/src/clp_ffi_js/ir/LogEventWithLevel.hpp +++ b/src/clp_ffi_js/ir/LogEventWithLevel.hpp @@ -11,7 +11,6 @@ #include namespace clp_ffi_js::ir { - /** * A class derived from `clp::ir::LogEvent` with an additional member for the log level. * diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index cfb58a7d..c181c4e7 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -100,23 +100,21 @@ auto StreamReader::get_num_events_buffered() const -> size_t { } auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapTsType { - if (std::nullopt == m_filtered_log_event_map) { - return FilteredLogEventMapTsType(emscripten::val::null()); + if (false == m_filtered_log_event_map.has_value()) { + return FilteredLogEventMapTsType{emscripten::val::null()}; } - return FilteredLogEventMapTsType(emscripten::val::array(m_filtered_log_event_map.value())); + return FilteredLogEventMapTsType{emscripten::val::array(m_filtered_log_event_map.value())}; } auto StreamReader::deserialize_stream() -> size_t { if (nullptr == m_stream_reader_data_context) { return m_encoded_log_events.size(); } + constexpr size_t cDefaultNumReservedLogEvents{500'000}; m_encoded_log_events.reserve(cDefaultNumReservedLogEvents); - std::string logtype; - constexpr size_t cDefaultReservedMessageLength{512}; - logtype.reserve(cDefaultReservedMessageLength); while (true) { auto result{m_stream_reader_data_context->get_deserializer().deserialize_log_event()}; if (result.has_error()) { @@ -138,7 +136,7 @@ auto StreamReader::deserialize_stream() -> size_t { auto const& log_event = result.value(); auto const& message = log_event.get_message(); - logtype = message.get_logtype(); + auto const& logtype = message.get_logtype(); constexpr size_t cLogLevelPositionInMessages{1}; LogLevel log_level{LogLevel::NONE}; if (logtype.length() > cLogLevelPositionInMessages) { @@ -171,8 +169,8 @@ auto StreamReader::deserialize_stream() -> size_t { auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const -> DecodedResultsTsType { - if (use_filter && (std::nullopt == m_filtered_log_event_map)) { - return DecodedResultsTsType(emscripten::val::null()); + if (use_filter && false == m_filtered_log_event_map.has_value()) { + return DecodedResultsTsType{emscripten::val::null()}; } size_t length{0}; @@ -181,17 +179,17 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte } else { length = m_encoded_log_events.size(); } - if (length < end_idx || 0 > begin_idx) { - return DecodedResultsTsType(emscripten::val::null()); + return DecodedResultsTsType{emscripten::val::null()}; } + std::string message; constexpr size_t cDefaultReservedMessageLength{512}; message.reserve(cDefaultReservedMessageLength); auto const results{emscripten::val::array()}; for (size_t i = begin_idx; i < end_idx; ++i) { - size_t log_event_idx = 0; + size_t log_event_idx{0}; if (use_filter) { log_event_idx = m_filtered_log_event_map->at(i); } else { @@ -228,8 +226,7 @@ void StreamReader::filter_log_events(emscripten::val const& log_level_filter) { } m_filtered_log_event_map.emplace(); - std::vector filter_levels{emscripten::vecFromJSArray(log_level_filter)}; - + auto filter_levels{emscripten::vecFromJSArray(log_level_filter)}; for (size_t log_event_idx = 0; log_event_idx < m_encoded_log_events.size(); ++log_event_idx) { auto const& log_event = m_encoded_log_events[log_event_idx]; if (std::ranges::find(filter_levels, log_event.get_log_level()) != filter_levels.end()) { @@ -254,7 +251,7 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { emscripten::register_type( "Array<[string, number, number, number]>" ); - emscripten::register_type("number[]"); + emscripten::register_type("number[] | null"); emscripten::class_("ClpIrStreamReader") .constructor( diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 2ab3c25e..febc924b 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -64,7 +64,7 @@ class StreamReader { void filter_log_events(emscripten::val const& log_level_filter); /** - * Deserializes all log events in the file. After the stream has been exhausted, it will be + * Deserializes all log events in the stream. After the stream has been exhausted, it will be * deallocated. * * @return The number of successfully deserialized ("valid") log events. @@ -77,8 +77,7 @@ class StreamReader { * * @param begin_idx * @param end_idx - * @param use_filter If true, decode from the filtered log events collection; otherwise, decode - * from the unfiltered one. + * @param use_filter Whether to decode from the filtered or unfiltered log events collection. * @return An array where each element is a decoded log event represented by an array of: * - The log event's message * - The log event's timestamp as milliseconds since the Unix epoch From c04d88784594b37632b9c5a9b0b13543c9560100 Mon Sep 17 00:00:00 2001 From: davemarco <83603688+davemarco@users.noreply.github.com> Date: Thu, 10 Oct 2024 09:24:03 -0400 Subject: [PATCH 41/47] Apply suggestions from code review Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> --- src/clp_ffi_js/constants.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index 432b5524..fbd3b900 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -10,7 +10,7 @@ namespace clp_ffi_js { * Enum of known log levels. */ enum class LogLevel : std::uint8_t { - NONE = 0, // This should not be used. + NONE = 0, // This isn't a valid log level. TRACE, DEBUG, INFO, From bab5036fa4f73fb87f4a7d25e3a59375db4c8efe Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Thu, 10 Oct 2024 13:41:41 +0000 Subject: [PATCH 42/47] kirk review --- src/clp_ffi_js/constants.hpp | 2 +- src/clp_ffi_js/ir/StreamReader.cpp | 38 +++++++++++++++--------------- src/clp_ffi_js/ir/StreamReader.hpp | 8 ++++++- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index fbd3b900..3e320582 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -26,7 +26,7 @@ constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::TRACE}; * NOTE: These must be kept in sync manually. */ constexpr std::array cLogLevelNames{ - "NONE", + "NONE", // This isn't a valid log level. "TRACE", "DEBUG", "INFO", diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index c181c4e7..ac4f712e 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -107,6 +107,22 @@ auto StreamReader::get_filtered_log_event_map() const -> FilteredLogEventMapTsTy return FilteredLogEventMapTsType{emscripten::val::array(m_filtered_log_event_map.value())}; } +void StreamReader::filter_log_events(emscripten::val const& log_level_filter) { + if (log_level_filter.isNull()) { + m_filtered_log_event_map.reset(); + return; + } + + m_filtered_log_event_map.emplace(); + auto filter_levels{emscripten::vecFromJSArray(log_level_filter)}; + for (size_t log_event_idx = 0; log_event_idx < m_encoded_log_events.size(); ++log_event_idx) { + auto const& log_event = m_encoded_log_events[log_event_idx]; + if (std::ranges::find(filter_levels, log_event.get_log_level()) != filter_levels.end()) { + m_filtered_log_event_map->emplace_back(log_event_idx); + } + } +} + auto StreamReader::deserialize_stream() -> size_t { if (nullptr == m_stream_reader_data_context) { return m_encoded_log_events.size(); @@ -179,7 +195,7 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte } else { length = m_encoded_log_events.size(); } - if (length < end_idx || 0 > begin_idx) { + if (length < end_idx || begin_idx > end_idx) { return DecodedResultsTsType{emscripten::val::null()}; } @@ -219,22 +235,6 @@ auto StreamReader::decode_range(size_t begin_idx, size_t end_idx, bool use_filte return DecodedResultsTsType(results); } -void StreamReader::filter_log_events(emscripten::val const& log_level_filter) { - if (log_level_filter.isNull()) { - m_filtered_log_event_map.reset(); - return; - } - - m_filtered_log_event_map.emplace(); - auto filter_levels{emscripten::vecFromJSArray(log_level_filter)}; - for (size_t log_event_idx = 0; log_event_idx < m_encoded_log_events.size(); ++log_event_idx) { - auto const& log_event = m_encoded_log_events[log_event_idx]; - if (std::ranges::find(filter_levels, log_event.get_log_level()) != filter_levels.end()) { - m_filtered_log_event_map->emplace_back(log_event_idx); - } - } -} - StreamReader::StreamReader( StreamReaderDataContext&& stream_reader_data_context ) @@ -266,8 +266,8 @@ EMSCRIPTEN_BINDINGS(ClpIrStreamReader) { "getFilteredLogEventMap", &clp_ffi_js::ir::StreamReader::get_filtered_log_event_map ) + .function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events) .function("deserializeStream", &clp_ffi_js::ir::StreamReader::deserialize_stream) - .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range) - .function("filterLogEvents", &clp_ffi_js::ir::StreamReader::filter_log_events); + .function("decodeRange", &clp_ffi_js::ir::StreamReader::decode_range); } } // namespace diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index febc924b..dec6c360 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -25,6 +25,12 @@ EMSCRIPTEN_DECLARE_VAL_TYPE(FilteredLogEventMapTsType); */ class StreamReader { public: + /** + * Mapping between an index in the filtered log events collection to an index in the unfiltered + * log events collection. + */ + using FilteredLogEventsMap = std::optional>; + /** * Creates a StreamReader to read from the given array. * @@ -98,7 +104,7 @@ class StreamReader { std::vector> m_encoded_log_events; std::unique_ptr> m_stream_reader_data_context; - std::optional> m_filtered_log_event_map; + FilteredLogEventsMap m_filtered_log_event_map; clp::TimestampPattern m_ts_pattern; }; } // namespace clp_ffi_js::ir From b3fde470e89e7a9cbdf5fccf924f33d74d0c7f58 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Thu, 10 Oct 2024 13:53:15 +0000 Subject: [PATCH 43/47] fix lint --- src/clp_ffi_js/constants.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index 3e320582..045227da 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -26,7 +26,7 @@ constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::TRACE}; * NOTE: These must be kept in sync manually. */ constexpr std::array cLogLevelNames{ - "NONE", // This isn't a valid log level. + "NONE", // This isn't a valid log level. "TRACE", "DEBUG", "INFO", From 756428046993e7264bf4d34421b32040a10f72df Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Thu, 10 Oct 2024 18:15:21 +0000 Subject: [PATCH 44/47] fix bug with log level in enscripten --- src/clp_ffi_js/ir/StreamReader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index ac4f712e..6091787b 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -114,10 +114,10 @@ void StreamReader::filter_log_events(emscripten::val const& log_level_filter) { } m_filtered_log_event_map.emplace(); - auto filter_levels{emscripten::vecFromJSArray(log_level_filter)}; + auto filter_levels{emscripten::vecFromJSArray(log_level_filter)}; for (size_t log_event_idx = 0; log_event_idx < m_encoded_log_events.size(); ++log_event_idx) { auto const& log_event = m_encoded_log_events[log_event_idx]; - if (std::ranges::find(filter_levels, log_event.get_log_level()) != filter_levels.end()) { + if (std::ranges::find(filter_levels, static_cast(log_event.get_log_level())) != filter_levels.end()) { m_filtered_log_event_map->emplace_back(log_event_idx); } } From 7d01cf23571ad64f567bd6b95320c40f4db05d8d Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Thu, 10 Oct 2024 18:19:57 +0000 Subject: [PATCH 45/47] fix lint --- src/clp_ffi_js/ir/StreamReader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 6091787b..748f0bf9 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -117,7 +117,9 @@ void StreamReader::filter_log_events(emscripten::val const& log_level_filter) { auto filter_levels{emscripten::vecFromJSArray(log_level_filter)}; for (size_t log_event_idx = 0; log_event_idx < m_encoded_log_events.size(); ++log_event_idx) { auto const& log_event = m_encoded_log_events[log_event_idx]; - if (std::ranges::find(filter_levels, static_cast(log_event.get_log_level())) != filter_levels.end()) { + if (std::ranges::find(filter_levels, static_cast(log_event.get_log_level())) + != filter_levels.end()) + { m_filtered_log_event_map->emplace_back(log_event_idx); } } From bd29b8f28806d7389472fa64c235496fcc4ff80c Mon Sep 17 00:00:00 2001 From: davemarco <83603688+davemarco@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:05:18 -0400 Subject: [PATCH 46/47] Apply suggestions from code review Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> --- src/clp_ffi_js/ir/StreamReader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 748f0bf9..096f6f59 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -114,10 +114,14 @@ void StreamReader::filter_log_events(emscripten::val const& log_level_filter) { } m_filtered_log_event_map.emplace(); - auto filter_levels{emscripten::vecFromJSArray(log_level_filter)}; + auto filter_levels{emscripten::vecFromJSArray>(log_level_filter + )}; for (size_t log_event_idx = 0; log_event_idx < m_encoded_log_events.size(); ++log_event_idx) { auto const& log_event = m_encoded_log_events[log_event_idx]; - if (std::ranges::find(filter_levels, static_cast(log_event.get_log_level())) + if (std::ranges::find( + filter_levels, + clp::enum_to_underlying_type(log_event.get_log_level()) + ) != filter_levels.end()) { m_filtered_log_event_map->emplace_back(log_event_idx); From a244f5e3604e232d675df9aaed87817a6cb4135d Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Thu, 10 Oct 2024 19:20:09 +0000 Subject: [PATCH 47/47] kirk review --- src/clp_ffi_js/ir/StreamReader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 096f6f59..b9c86b6b 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #include #include #include