Skip to content

Commit

Permalink
Small fix and utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
haiqi96 committed Jan 22, 2024
1 parent 02b4a30 commit 87880f8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/core/src/glt/Grep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ void find_boundaries(

// Now we have the left boundary and right boundary, try to filter out the variables;
// var_begin_ix is an inclusive interval
size_t logtype_variable_num = logtype_entry->get_num_variables();
auto const logtype_variable_num = logtype_entry->get_num_variables();
ir::VariablePlaceholder var_placeholder;
var_begin_ix = 0;
for(size_t var_ix = 0; var_ix < logtype_variable_num; var_ix++) {
Expand All @@ -496,7 +496,7 @@ void find_boundaries(
break;
}
}
if (var_end_ix <= var_begin_ix) {
if (var_end_ix < var_begin_ix) {
printf("end index %lu is smaller than begin index %lu\n", var_end_ix, var_begin_ix);
throw;
}
Expand Down
29 changes: 29 additions & 0 deletions components/core/src/glt/LogTypeDictionaryEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,33 @@ void LogTypeDictionaryEntry::read_from_file(streaming_compression::Decompressor&
throw OperationFailed(error_code, __FILENAME__, __LINE__);
}
}

string LogTypeDictionaryEntry::get_human_readable_value() const {
string human_readable_value;

size_t constant_begin_pos = 0;
for (size_t placeholder_ix = 0; placeholder_ix < get_num_placeholders(); ++placeholder_ix) {
VariablePlaceholder placeholder;
size_t placeholder_pos = get_placeholder_info(placeholder_ix, placeholder);

// Add the constant that's between the last variable and this one, with newlines escaped
human_readable_value.append(m_value, constant_begin_pos, placeholder_pos - constant_begin_pos);

if (VariablePlaceholder::Dictionary == placeholder) {
human_readable_value += "v";
} else if (VariablePlaceholder::Float == placeholder) {
human_readable_value += "f";
} else if (VariablePlaceholder::Integer == placeholder) {
human_readable_value += "i";
}
// Move past the variable delimiter
constant_begin_pos = placeholder_pos + 1;
}
// Append remainder of value, if any
if (constant_begin_pos < m_value.length()) {
human_readable_value.append(m_value, constant_begin_pos, string::npos);
}
return human_readable_value;
}

} // namespace glt
6 changes: 6 additions & 0 deletions components/core/src/glt/LogTypeDictionaryEntry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ class LogTypeDictionaryEntry : public DictionaryEntry<logtype_dictionary_id_t> {
*/
void read_from_file(streaming_compression::Decompressor& decompressor);

/**
* Generate a human readable version of value.
* @param decompressor
*/
std::string get_human_readable_value() const;

private:
// Variables
std::vector<size_t> m_placeholder_positions;
Expand Down

0 comments on commit 87880f8

Please sign in to comment.