Skip to content

Commit 7838a73

Browse files
committed
[logfile] implement upper time cutoff
1 parent c31857e commit 7838a73

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/base/date_time_scanner.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ point::from(string_fragment in, std::optional<timeval> ref_point)
422422
std::optional<timeval> tv_opt;
423423

424424
if (parse_res.isOk()) {
425-
auto tm = exttm::from_tv(ref_point.value_or(current_timeval()));
425+
auto now_tv = current_timeval();
426+
now_tv.tv_sec = convert_log_time_to_local(now_tv.tv_sec);
427+
auto tm = exttm::from_tv(ref_point.value_or(now_tv));
426428
tv_opt = parse_res.unwrap().adjust(tm).to_timeval();
427429
} else {
428430
date_time_scanner dts;

src/logfile.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,19 @@ logfile::process_prefix(shared_buffer_ref& sbr,
924924
this->lf_index.back().set_has_ansi(li.li_utf8_scan_result.usr_has_ansi);
925925
}
926926

927+
if (this->lf_format != nullptr
928+
&& this->lf_index.back().get_time<std::chrono::microseconds>()
929+
> this->lf_options.loo_time_range.tr_end)
930+
{
931+
if (!this->lf_upper_bound_size) {
932+
this->lf_upper_bound_size = this->lf_index.back().get_offset();
933+
log_debug("%s: upper found in file found %llu",
934+
this->lf_filename_as_string.c_str(),
935+
this->lf_upper_bound_size.value());
936+
}
937+
this->lf_index.pop_back();
938+
}
939+
927940
return retval;
928941
}
929942

@@ -1075,6 +1088,9 @@ logfile::rebuild_index(std::optional<ui_clock::time_point> deadline)
10751088
if (this->lf_text_format == text_format_t::TF_BINARY) {
10761089
this->lf_index_size = st.st_size;
10771090
this->lf_stat = st;
1091+
} else if (this->lf_upper_bound_size) {
1092+
this->lf_index_size = this->lf_line_buffer.get_file_size();
1093+
this->lf_stat = st;
10781094
} else if (this->lf_line_buffer.is_data_available(this->lf_index_size,
10791095
st.st_size))
10801096
{
@@ -1868,7 +1884,11 @@ logfile::message_byte_length(logfile::const_iterator ll, bool include_continues)
18681884
|| (include_continues && next_line->is_continued())));
18691885

18701886
if (next_line == this->end()) {
1871-
retval = this->lf_index_size - ll->get_offset();
1887+
if (this->lf_upper_bound_size) {
1888+
retval = this->lf_upper_bound_size.value() - ll->get_offset();
1889+
} else {
1890+
retval = this->lf_index_size - ll->get_offset();
1891+
}
18721892
if (retval > line_buffer::MAX_LINE_BUFFER_SIZE) {
18731893
retval = line_buffer::MAX_LINE_BUFFER_SIZE;
18741894
}

src/logfile.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ private:
605605
};
606606
file_size_t lf_file_size_at_map_time{0};
607607
std::vector<content_map_entry> lf_content_map;
608+
std::optional<file_size_t> lf_upper_bound_size;
608609

609610
std::optional<content_map_entry> find_content_map_entry(file_off_t offset);
610611

0 commit comments

Comments
 (0)