Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move CLP IR types from the ffi to the ir namespace. #199

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ set(SOURCE_FILES_clp
src/ir/parsing.cpp
src/ir/parsing.hpp
src/ir/parsing.inc
src/ir/types.hpp
src/ir/utils.cpp
src/ir/utils.hpp
src/LibarchiveFileReader.cpp
Expand Down Expand Up @@ -388,9 +389,10 @@ set(SOURCE_FILES_clg
src/ir/LogEvent.hpp
src/ir/parsing.cpp
src/ir/parsing.hpp
src/ir/parsing.inc
src/ir/types.hpp
src/LogSurgeonReader.cpp
src/LogSurgeonReader.hpp
src/ir/parsing.inc
src/LogTypeDictionaryEntry.cpp
src/LogTypeDictionaryEntry.hpp
src/LogTypeDictionaryReader.hpp
Expand Down Expand Up @@ -524,9 +526,10 @@ set(SOURCE_FILES_clo
src/ir/LogEvent.hpp
src/ir/parsing.cpp
src/ir/parsing.hpp
src/ir/parsing.inc
src/ir/types.hpp
src/LogSurgeonReader.cpp
src/LogSurgeonReader.hpp
src/ir/parsing.inc
src/LogTypeDictionaryEntry.cpp
src/LogTypeDictionaryEntry.hpp
src/LogTypeDictionaryReader.hpp
Expand Down Expand Up @@ -698,6 +701,7 @@ set(SOURCE_FILES_unitTest
src/ir/parsing.cpp
src/ir/parsing.hpp
src/ir/parsing.inc
src/ir/types.hpp
src/ir/utils.cpp
src/ir/utils.hpp
src/LibarchiveFileReader.cpp
Expand Down
54 changes: 29 additions & 25 deletions components/core/src/EncodedVariableInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
#include <cassert>

#include "Defs.h"
#include "ffi/encoding_methods.hpp"
#include "ffi/ir_stream/decoding_methods.hpp"
#include "ir/parsing.hpp"
#include "ir/LogEvent.hpp"
#include "ir/types.hpp"
#include "spdlog_with_specializations.hpp"
#include "string_utils.hpp"
#include "type_utils.hpp"

using ffi::cEightByteEncodedFloatDigitsBitMask;
using ir::eight_byte_encoded_variable_t;
using ir::four_byte_encoded_variable_t;
using ir::LogEvent;
using ir::VariablePlaceholder;
using std::string;
using std::unordered_set;
using std::vector;
Expand Down Expand Up @@ -221,10 +225,10 @@ void EncodedVariableInterpreter::encode_and_add_to_dictionary(

template <typename encoded_variable_t>
void EncodedVariableInterpreter::encode_and_add_to_dictionary(
ir::LogEvent<encoded_variable_t> const& log_event,
LogEvent<encoded_variable_t> const& log_event,
LogTypeDictionaryEntry& logtype_dict_entry,
VariableDictionaryWriter& var_dict,
std::vector<ffi::eight_byte_encoded_variable_t>& encoded_vars,
std::vector<eight_byte_encoded_variable_t>& encoded_vars,
std::vector<variable_dictionary_id_t>& var_ids,
size_t& raw_num_bytes
) {
Expand All @@ -242,23 +246,23 @@ void EncodedVariableInterpreter::encode_and_add_to_dictionary(
raw_num_bytes += ffi::decode_integer_var(encoded_var).length();
logtype_dict_entry.add_int_var();

ffi::eight_byte_encoded_variable_t eight_byte_encoded_var{};
if constexpr (std::is_same_v<encoded_variable_t, ffi::eight_byte_encoded_variable_t>) {
eight_byte_encoded_variable_t eight_byte_encoded_var{};
if constexpr (std::is_same_v<encoded_variable_t, eight_byte_encoded_variable_t>) {
eight_byte_encoded_var = encoded_var;
} else { // std::is_same_v<encoded_variable_t, ffi::four_byte_encoded_variable_t>
} else { // std::is_same_v<encoded_variable_t, four_byte_encoded_variable_t>
eight_byte_encoded_var = ffi::encode_four_byte_integer_as_eight_byte(encoded_var);
}
encoded_vars.push_back(eight_byte_encoded_var);
};

auto encoded_float_handler = [&](ffi::four_byte_encoded_variable_t encoded_var) {
auto encoded_float_handler = [&](four_byte_encoded_variable_t encoded_var) {
raw_num_bytes += ffi::decode_float_var(encoded_var).length();
logtype_dict_entry.add_float_var();

ffi::eight_byte_encoded_variable_t eight_byte_encoded_var{};
if constexpr (std::is_same_v<encoded_variable_t, ffi::eight_byte_encoded_variable_t>) {
eight_byte_encoded_variable_t eight_byte_encoded_var{};
if constexpr (std::is_same_v<encoded_variable_t, eight_byte_encoded_variable_t>) {
eight_byte_encoded_var = encoded_var;
} else { // std::is_same_v<encoded_variable_t, ffi::four_byte_encoded_variable_t>
} else { // std::is_same_v<encoded_variable_t, four_byte_encoded_variable_t>
eight_byte_encoded_var = ffi::encode_four_byte_float_as_eight_byte(encoded_var);
}
encoded_vars.push_back(eight_byte_encoded_var);
Expand All @@ -267,12 +271,12 @@ void EncodedVariableInterpreter::encode_and_add_to_dictionary(
auto dict_var_handler = [&](string const& dict_var) {
raw_num_bytes += dict_var.length();

ffi::eight_byte_encoded_variable_t encoded_var{};
if constexpr (std::is_same_v<encoded_variable_t, ffi::eight_byte_encoded_variable_t>) {
eight_byte_encoded_variable_t encoded_var{};
if constexpr (std::is_same_v<encoded_variable_t, eight_byte_encoded_variable_t>) {
encoded_var = encode_var_dict_id(
add_dict_var(dict_var, logtype_dict_entry, var_dict, var_ids)
);
} else { // std::is_same_v<encoded_variable_t, ffi::four_byte_encoded_variable_t>
} else { // std::is_same_v<encoded_variable_t, four_byte_encoded_variable_t>
encoded_var = encode_var(dict_var, logtype_dict_entry, var_dict, var_ids);
}
encoded_vars.push_back(encoded_var);
Expand Down Expand Up @@ -309,7 +313,7 @@ bool EncodedVariableInterpreter::decode_variables_into_message(
return false;
}

ir::VariablePlaceholder var_placeholder;
VariablePlaceholder var_placeholder;
size_t constant_begin_pos = 0;
string float_str;
variable_dictionary_id_t var_dict_id;
Expand All @@ -327,18 +331,18 @@ bool EncodedVariableInterpreter::decode_variables_into_message(
placeholder_position - constant_begin_pos
);
switch (var_placeholder) {
case ir::VariablePlaceholder::Integer:
case VariablePlaceholder::Integer:
decompressed_msg += std::to_string(encoded_vars[var_ix++]);
break;
case ir::VariablePlaceholder::Float:
case VariablePlaceholder::Float:
convert_encoded_float_to_string(encoded_vars[var_ix++], float_str);
decompressed_msg += float_str;
break;
case ir::VariablePlaceholder::Dictionary:
case VariablePlaceholder::Dictionary:
var_dict_id = decode_var_dict_id(encoded_vars[var_ix++]);
decompressed_msg += var_dict.get_value(var_dict_id);
break;
case ir::VariablePlaceholder::Escape:
case VariablePlaceholder::Escape:
break;
default:
SPDLOG_ERROR(
Expand Down Expand Up @@ -459,21 +463,21 @@ variable_dictionary_id_t EncodedVariableInterpreter::add_dict_var(
// Explicitly declare template specializations so that we can define the template methods in this
// file
template void
EncodedVariableInterpreter::encode_and_add_to_dictionary<ffi::eight_byte_encoded_variable_t>(
ir::LogEvent<ffi::eight_byte_encoded_variable_t> const& log_event,
EncodedVariableInterpreter::encode_and_add_to_dictionary<eight_byte_encoded_variable_t>(
LogEvent<eight_byte_encoded_variable_t> const& log_event,
LogTypeDictionaryEntry& logtype_dict_entry,
VariableDictionaryWriter& var_dict,
std::vector<ffi::eight_byte_encoded_variable_t>& encoded_vars,
std::vector<eight_byte_encoded_variable_t>& encoded_vars,
std::vector<variable_dictionary_id_t>& var_ids,
size_t& raw_num_bytes
);

template void
EncodedVariableInterpreter::encode_and_add_to_dictionary<ffi::four_byte_encoded_variable_t>(
ir::LogEvent<ffi::four_byte_encoded_variable_t> const& log_event,
EncodedVariableInterpreter::encode_and_add_to_dictionary<four_byte_encoded_variable_t>(
LogEvent<four_byte_encoded_variable_t> const& log_event,
LogTypeDictionaryEntry& logtype_dict_entry,
VariableDictionaryWriter& var_dict,
std::vector<ffi::eight_byte_encoded_variable_t>& encoded_vars,
std::vector<eight_byte_encoded_variable_t>& encoded_vars,
std::vector<variable_dictionary_id_t>& var_ids,
size_t& raw_num_bytes
);
3 changes: 2 additions & 1 deletion components/core/src/EncodedVariableInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>

#include "ir/LogEvent.hpp"
#include "ir/types.hpp"
#include "Query.hpp"
#include "TraceableException.hpp"
#include "VariableDictionaryReader.hpp"
Expand Down Expand Up @@ -107,7 +108,7 @@ class EncodedVariableInterpreter {
ir::LogEvent<encoded_variable_t> const& log_event,
LogTypeDictionaryEntry& logtype_dict_entry,
VariableDictionaryWriter& var_dict,
std::vector<ffi::eight_byte_encoded_variable_t>& encoded_vars,
std::vector<ir::eight_byte_encoded_variable_t>& encoded_vars,
std::vector<variable_dictionary_id_t>& var_ids,
size_t& raw_num_bytes
);
Expand Down
1 change: 1 addition & 0 deletions components/core/src/Grep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "EncodedVariableInterpreter.hpp"
#include "ir/parsing.hpp"
#include "ir/types.hpp"
#include "LogSurgeonReader.hpp"
#include "StringReader.hpp"
#include "Utils.hpp"
Expand Down
16 changes: 9 additions & 7 deletions components/core/src/LogTypeDictionaryEntry.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#include "LogTypeDictionaryEntry.hpp"

#include "ir/parsing.hpp"
#include "ir/types.hpp"
#include "type_utils.hpp"
#include "Utils.hpp"

using ir::VariablePlaceholder;
using std::string;
using std::string_view;

size_t LogTypeDictionaryEntry::get_placeholder_info(
size_t placeholder_ix,
ir::VariablePlaceholder& placeholder
VariablePlaceholder& placeholder
) const {
if (placeholder_ix >= m_placeholder_positions.size()) {
return SIZE_MAX;
}

auto var_position = m_placeholder_positions[placeholder_ix];
placeholder = static_cast<ir::VariablePlaceholder>(m_value[var_position]);
placeholder = static_cast<VariablePlaceholder>(m_value[var_position]);

return m_placeholder_positions[placeholder_ix];
}
Expand Down Expand Up @@ -73,7 +75,7 @@ bool LogTypeDictionaryEntry::parse_next_var(
) -> void {
m_placeholder_positions.push_back(logtype.size());
++m_num_escaped_placeholders;
logtype += enum_to_underlying_type(ir::VariablePlaceholder::Escape);
logtype += enum_to_underlying_type(VariablePlaceholder::Escape);
};
// clang-format on
if (ir::get_bounds_of_next_var(msg, var_begin_pos, var_end_pos)) {
Expand Down Expand Up @@ -144,21 +146,21 @@ ErrorCode LogTypeDictionaryEntry::try_read_from_file(
if (is_escaped) {
constant += c;
is_escaped = false;
} else if (enum_to_underlying_type(ir::VariablePlaceholder::Escape) == c) {
} else if (enum_to_underlying_type(VariablePlaceholder::Escape) == c) {
is_escaped = true;
add_constant(constant, 0, constant.length());
constant.clear();
add_escape();
} else {
if (enum_to_underlying_type(ir::VariablePlaceholder::Integer) == c) {
if (enum_to_underlying_type(VariablePlaceholder::Integer) == c) {
add_constant(constant, 0, constant.length());
constant.clear();
add_int_var();
} else if (enum_to_underlying_type(ir::VariablePlaceholder::Float) == c) {
} else if (enum_to_underlying_type(VariablePlaceholder::Float) == c) {
add_constant(constant, 0, constant.length());
constant.clear();
add_float_var();
} else if (enum_to_underlying_type(ir::VariablePlaceholder::Dictionary) == c) {
} else if (enum_to_underlying_type(VariablePlaceholder::Dictionary) == c) {
add_constant(constant, 0, constant.length());
constant.clear();
add_dictionary_var();
Expand Down
2 changes: 1 addition & 1 deletion components/core/src/LogTypeDictionaryEntry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "DictionaryEntry.hpp"
#include "ErrorCode.hpp"
#include "FileReader.hpp"
#include "ir/parsing.hpp"
#include "ir/types.hpp"
#include "streaming_compression/zstd/Compressor.hpp"
#include "streaming_compression/zstd/Decompressor.hpp"
#include "TraceableException.hpp"
Expand Down
15 changes: 9 additions & 6 deletions components/core/src/clp/FileCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
#include <log_surgeon/ReaderParser.hpp>

#include "../ffi/ir_stream/decoding_methods.hpp"
#include "../ir/types.hpp"
#include "../ir/utils.hpp"
#include "../LogSurgeonReader.hpp"
#include "../Profiler.hpp"
#include "utils.hpp"

using ir::eight_byte_encoded_variable_t;
using ir::four_byte_encoded_variable_t;
using ir::has_ir_stream_magic_number;
using ir::LogEventDeserializer;
using log_surgeon::LogEventView;
Expand Down Expand Up @@ -432,7 +435,7 @@ bool FileCompressor::compress_ir_stream(
try {
std::error_code error_code{};
if (uses_four_byte_encoding) {
auto result = LogEventDeserializer<ffi::four_byte_encoded_variable_t>::create(reader);
auto result = LogEventDeserializer<four_byte_encoded_variable_t>::create(reader);
if (result.has_error()) {
error_code = result.error();
} else {
Expand All @@ -447,7 +450,7 @@ bool FileCompressor::compress_ir_stream(
);
}
} else {
auto result = LogEventDeserializer<ffi::eight_byte_encoded_variable_t>::create(reader);
auto result = LogEventDeserializer<eight_byte_encoded_variable_t>::create(reader);
if (result.has_error()) {
error_code = result.error();
} else {
Expand Down Expand Up @@ -548,23 +551,23 @@ std::error_code FileCompressor::compress_ir_stream_by_encoding(
// Explicitly declare template specializations so that we can define the template methods in this
// file
template std::error_code
FileCompressor::compress_ir_stream_by_encoding<ffi::eight_byte_encoded_variable_t>(
FileCompressor::compress_ir_stream_by_encoding<eight_byte_encoded_variable_t>(
size_t target_data_size_of_dicts,
streaming_archive::writer::Archive::UserConfig& archive_user_config,
size_t target_encoded_file_size,
string const& path,
group_id_t group_id,
streaming_archive::writer::Archive& archive,
LogEventDeserializer<ffi::eight_byte_encoded_variable_t>& log_event_deserializer
LogEventDeserializer<eight_byte_encoded_variable_t>& log_event_deserializer
);
template std::error_code
FileCompressor::compress_ir_stream_by_encoding<ffi::four_byte_encoded_variable_t>(
FileCompressor::compress_ir_stream_by_encoding<four_byte_encoded_variable_t>(
size_t target_data_size_of_dicts,
streaming_archive::writer::Archive::UserConfig& archive_user_config,
size_t target_encoded_file_size,
string const& path,
group_id_t group_id,
streaming_archive::writer::Archive& archive,
LogEventDeserializer<ffi::four_byte_encoded_variable_t>& log_event_deserializer
LogEventDeserializer<four_byte_encoded_variable_t>& log_event_deserializer
);
} // namespace clp
4 changes: 4 additions & 0 deletions components/core/src/ffi/encoding_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <algorithm>
#include <string_view>

#include "../ir/types.hpp"

using ir::eight_byte_encoded_variable_t;
using ir::four_byte_encoded_variable_t;
using std::string_view;

namespace ffi {
Expand Down
Loading
Loading