mirror of
https://github.com/tstack/lnav
synced 2024-11-03 23:15:38 +00:00
[spectro] support marking lines in a bucket
This commit is contained in:
parent
7f6b352143
commit
99eb3a54f3
@ -116,8 +116,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
bool is_data_available(off_t off) {
|
||||
return (this->lb_file_size == -1 || off < this->lb_file_size);
|
||||
bool is_data_available(off_t off, off_t stat_size) {
|
||||
if (this->is_compressed()) {
|
||||
return (this->lb_file_size == -1 || off < this->lb_file_size);
|
||||
}
|
||||
return off < stat_size;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -81,6 +81,14 @@ void listview_curses::reload_data(void)
|
||||
|
||||
bool listview_curses::handle_key(int ch)
|
||||
{
|
||||
for (list<list_input_delegate *>::iterator iter = this->lv_input_delegates.begin();
|
||||
iter != this->lv_input_delegates.end();
|
||||
++iter) {
|
||||
if ((*iter)->list_input_handle_key(*this, ch)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
vis_line_t height(0);
|
||||
|
||||
unsigned long width;
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
@ -119,6 +120,13 @@ public:
|
||||
attr_line_t &value_out) = 0;
|
||||
};
|
||||
|
||||
class list_input_delegate {
|
||||
public:
|
||||
virtual ~list_input_delegate() { };
|
||||
|
||||
virtual bool list_input_handle_key(listview_curses &lv, int ch) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* View that displays a list of lines that can optionally contain highlighting.
|
||||
*/
|
||||
@ -168,6 +176,12 @@ public:
|
||||
return this->lv_overlay_source;
|
||||
};
|
||||
|
||||
listview_curses &add_input_delegate(list_input_delegate &lid) {
|
||||
this->lv_input_delegates.push_back(&lid);
|
||||
|
||||
return *this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param va The action to invoke when the view is scrolled.
|
||||
* @todo Allow multiple observers.
|
||||
@ -497,6 +511,7 @@ protected:
|
||||
|
||||
std::string lv_title;
|
||||
list_data_source * lv_source; /*< The data source delegate. */
|
||||
std::list<list_input_delegate *> lv_input_delegates;
|
||||
list_overlay_source *lv_overlay_source;
|
||||
action lv_scroll; /*< The scroll action. */
|
||||
WINDOW * lv_window; /*< The window that contains this view. */
|
||||
|
@ -2551,7 +2551,8 @@ int main(int argc, char *argv[])
|
||||
.set_overlay_source(&lnav_data.ld_db_overlay);
|
||||
lnav_data.ld_views[LNV_SPECTRO]
|
||||
.set_sub_source(&lnav_data.ld_spectro_source)
|
||||
.set_overlay_source(&lnav_data.ld_spectro_source);
|
||||
.set_overlay_source(&lnav_data.ld_spectro_source)
|
||||
.add_input_delegate(lnav_data.ld_spectro_source);
|
||||
|
||||
lnav_data.ld_match_view.set_left(0);
|
||||
|
||||
|
@ -2475,10 +2475,71 @@ public:
|
||||
if (lv_iter != values.end()) {
|
||||
switch (lv_iter->lv_kind) {
|
||||
case logline_value::VALUE_FLOAT:
|
||||
row_out.add_value(sr, lv_iter->lv_value.d);
|
||||
row_out.add_value(sr, lv_iter->lv_value.d, ll->is_marked());
|
||||
break;
|
||||
case logline_value::VALUE_INTEGER:
|
||||
row_out.add_value(sr, lv_iter->lv_value.i);
|
||||
row_out.add_value(sr, lv_iter->lv_value.i, ll->is_marked());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void spectro_mark(textview_curses &tc,
|
||||
time_t begin_time, time_t end_time,
|
||||
double range_min, double range_max) {
|
||||
// XXX need to refactor this and the above method
|
||||
textview_curses &log_tc = lnav_data.ld_views[LNV_LOG];
|
||||
logfile_sub_source &lss = lnav_data.ld_log_source;
|
||||
vis_line_t begin_line = lss.find_from_time(begin_time);
|
||||
vis_line_t end_line = lss.find_from_time(end_time);
|
||||
vector<logline_value> values;
|
||||
string_attrs_t sa;
|
||||
|
||||
if (begin_line == -1) {
|
||||
begin_line = vis_line_t(0);
|
||||
}
|
||||
if (end_line == -1) {
|
||||
end_line = vis_line_t(lss.text_line_count());
|
||||
}
|
||||
for (vis_line_t curr_line = begin_line; curr_line < end_line; ++curr_line) {
|
||||
content_line_t cl = lss.at(curr_line);
|
||||
logfile *lf = lss.find(cl);
|
||||
logfile::iterator ll = lf->begin() + cl;
|
||||
log_format *format = lf->get_format();
|
||||
shared_buffer_ref sbr;
|
||||
|
||||
if (ll->is_continued()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lf->read_full_message(ll, sbr);
|
||||
sa.clear();
|
||||
values.clear();
|
||||
format->annotate(sbr, sa, values);
|
||||
|
||||
vector<logline_value>::iterator lv_iter;
|
||||
|
||||
lv_iter = find_if(values.begin(), values.end(),
|
||||
logline_value_cmp(&this->lsvs_colname));
|
||||
|
||||
if (lv_iter != values.end()) {
|
||||
switch (lv_iter->lv_kind) {
|
||||
case logline_value::VALUE_FLOAT:
|
||||
if (range_min <= lv_iter->lv_value.d &&
|
||||
lv_iter->lv_value.d <= range_max) {
|
||||
log_tc.toggle_user_mark(&textview_curses::BM_USER,
|
||||
curr_line);
|
||||
}
|
||||
break;
|
||||
case logline_value::VALUE_INTEGER:
|
||||
if (range_min <= lv_iter->lv_value.i &&
|
||||
lv_iter->lv_value.i <= range_max) {
|
||||
log_tc.toggle_user_mark(&textview_curses::BM_USER,
|
||||
curr_line);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -2519,7 +2580,7 @@ static string com_spectrogram(string cmdline, vector<string> &args)
|
||||
auto_ptr<log_spectro_value_source> lsvs(new log_spectro_value_source(colname));
|
||||
|
||||
if (!lsvs->lsvs_found) {
|
||||
retval = "error: unknown message field -- " + colname.to_string();
|
||||
retval = "error: unknown numeric message field -- " + colname.to_string();
|
||||
}
|
||||
else {
|
||||
ss.ss_value_source = lsvs.release();
|
||||
|
@ -320,6 +320,7 @@ void log_format::check_for_new_year(std::vector<logline> &dst, exttm etm,
|
||||
if (!do_change) {
|
||||
return;
|
||||
}
|
||||
log_debug("%d:detected year change", dst.size());
|
||||
for (iter = dst.begin(); iter != dst.end(); iter++) {
|
||||
time_t ot = iter->get_time();
|
||||
struct tm otm;
|
||||
|
@ -153,7 +153,11 @@ class generic_log_format : public log_format {
|
||||
logline::level_t level_val = logline::string2level(
|
||||
level_str, level.length());
|
||||
|
||||
this->check_for_new_year(dst, log_time, log_tv);
|
||||
if (!((log_time.et_flags & ETF_DAY_SET) &&
|
||||
(log_time.et_flags & ETF_MONTH_SET) &&
|
||||
(log_time.et_flags & ETF_YEAR_SET))) {
|
||||
this->check_for_new_year(dst, log_time, log_tv);
|
||||
}
|
||||
|
||||
dst.push_back(logline(offset, log_tv, level_val));
|
||||
return SCAN_MATCH;
|
||||
|
@ -205,9 +205,9 @@ void logfile::process_prefix(off_t offset, shared_buffer_ref &sbr)
|
||||
|
||||
switch (found) {
|
||||
case log_format::SCAN_MATCH:
|
||||
if (prescan_size > 0) {
|
||||
if (prescan_size > 0 && prescan_size < this->lf_index.size()) {
|
||||
logline &second_to_last = this->lf_index[prescan_size - 1];
|
||||
logline &latest = this->lf_index.back();
|
||||
logline &latest = this->lf_index[prescan_size];
|
||||
|
||||
if (latest < second_to_last) {
|
||||
log_debug("%s:%d: out-of-time-order line detected %d.%03d < %d.%03d",
|
||||
@ -279,7 +279,7 @@ throw (line_buffer::error, logfile::error)
|
||||
this->close();
|
||||
return false;
|
||||
}
|
||||
else if (this->lf_line_buffer.is_data_available(this->lf_index_size)) {
|
||||
else if (this->lf_line_buffer.is_data_available(this->lf_index_size, st.st_size)) {
|
||||
// We haven't reached the end of the file. Note that we use the
|
||||
// line buffer's notion of the file size since it may be compressed.
|
||||
bool has_format = this->lf_format.get() != NULL;
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "ansi_scrubber.hh"
|
||||
#include "textview_curses.hh"
|
||||
|
||||
struct spectrogram_bounds {
|
||||
@ -83,14 +84,24 @@ struct spectrogram_row {
|
||||
delete this->sr_values;
|
||||
}
|
||||
|
||||
int *sr_values;
|
||||
struct row_bucket {
|
||||
row_bucket() : rb_counter(0), rb_marks(0) { };
|
||||
|
||||
int rb_counter;
|
||||
int rb_marks;
|
||||
};
|
||||
|
||||
row_bucket *sr_values;
|
||||
unsigned long sr_width;
|
||||
double sr_column_size;
|
||||
|
||||
void add_value(spectrogram_request &sr, double value) {
|
||||
void add_value(spectrogram_request &sr, double value, bool marked) {
|
||||
long index = lrint((value - sr.sr_bounds.sb_min_value_out) / sr.sr_column_size);
|
||||
|
||||
this->sr_values[index] += 1;
|
||||
this->sr_values[index].rb_counter += 1;
|
||||
if (marked) {
|
||||
this->sr_values[index].rb_marks += 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -102,23 +113,118 @@ public:
|
||||
|
||||
virtual void spectro_row(spectrogram_request &sr,
|
||||
spectrogram_row &row_out) = 0;
|
||||
|
||||
virtual void spectro_mark(textview_curses &tc,
|
||||
time_t begin_time, time_t end_time,
|
||||
double range_min, double range_max) = 0;
|
||||
};
|
||||
|
||||
class spectrogram_source
|
||||
: public text_sub_source,
|
||||
public text_time_translator,
|
||||
public list_overlay_source {
|
||||
public list_overlay_source,
|
||||
public list_input_delegate {
|
||||
public:
|
||||
|
||||
spectrogram_source()
|
||||
: ss_granularity(60),
|
||||
ss_value_source(NULL) {
|
||||
ss_value_source(NULL),
|
||||
ss_cursor_column(-1) {
|
||||
|
||||
};
|
||||
|
||||
void invalidate() {
|
||||
this->ss_cached_bounds.sb_count = 0;
|
||||
this->ss_row_cache.clear();
|
||||
this->ss_cursor_column = -1;
|
||||
};
|
||||
|
||||
bool list_input_handle_key(listview_curses &lv, int ch) {
|
||||
switch (ch) {
|
||||
case 'm': {
|
||||
if (this->ss_cursor_top < 0 ||
|
||||
this->ss_cursor_top >= this->text_line_count() ||
|
||||
this->ss_cursor_column == -1 ||
|
||||
this->ss_value_source == NULL) {
|
||||
alerter::singleton().chime();
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned long width;
|
||||
vis_line_t height;
|
||||
|
||||
lv.get_dimensions(height, width);
|
||||
|
||||
spectrogram_bounds &sb = this->ss_cached_bounds;
|
||||
time_t begin_time = this->time_for_row(this->ss_cursor_top);
|
||||
time_t end_time = begin_time + this->ss_granularity;
|
||||
double range_min, range_max, column_size;
|
||||
|
||||
column_size = (sb.sb_max_value_out - sb.sb_min_value_out) /
|
||||
(double) (width - 1);
|
||||
range_min = sb.sb_min_value_out + this->ss_cursor_column * column_size;
|
||||
range_max = range_min + column_size + column_size * 0.01;
|
||||
this->ss_value_source->spectro_mark((textview_curses &) lv,
|
||||
begin_time, end_time,
|
||||
range_min, range_max);
|
||||
this->invalidate();
|
||||
lv.reload_data();
|
||||
return true;
|
||||
}
|
||||
case KEY_LEFT:
|
||||
case KEY_RIGHT: {
|
||||
unsigned long width;
|
||||
vis_line_t height;
|
||||
string_attrs_t sa;
|
||||
|
||||
this->ss_cursor_top = lv.get_top();
|
||||
lv.get_dimensions(height, width);
|
||||
|
||||
this->text_attrs_for_line((textview_curses &) lv, this->ss_cursor_top, sa);
|
||||
|
||||
if (sa.empty()) {
|
||||
this->ss_cursor_column = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
string_attrs_t::iterator current;
|
||||
|
||||
struct line_range lr(this->ss_cursor_column, this->ss_cursor_column + 1);
|
||||
|
||||
current = find_string_attr(sa, lr);
|
||||
|
||||
if (current != sa.end()) {
|
||||
if (ch == KEY_LEFT) {
|
||||
if (current == sa.begin()) {
|
||||
current = sa.end();
|
||||
}
|
||||
else {
|
||||
--current;
|
||||
}
|
||||
}
|
||||
else {
|
||||
++current;
|
||||
}
|
||||
}
|
||||
|
||||
if (current == sa.end()) {
|
||||
if (ch == KEY_LEFT) {
|
||||
current = sa.end();
|
||||
--current;
|
||||
}
|
||||
else {
|
||||
current = sa.begin();
|
||||
}
|
||||
}
|
||||
this->ss_cursor_column = current->sa_range.lr_start;
|
||||
|
||||
lv.reload_data();
|
||||
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
size_t list_overlay_count(const listview_curses &lv) {
|
||||
@ -236,6 +342,8 @@ public:
|
||||
int row,
|
||||
std::string &value_out,
|
||||
bool no_scrub) {
|
||||
spectrogram_row &s_row = this->load_row(tc, row);
|
||||
|
||||
time_t row_time;
|
||||
char tm_buffer[128];
|
||||
struct tm tm;
|
||||
@ -246,6 +354,22 @@ public:
|
||||
strftime(tm_buffer, sizeof(tm_buffer), " %a %b %d %H:%M:%S", &tm);
|
||||
|
||||
value_out = tm_buffer;
|
||||
value_out.resize(s_row.sr_width, ' ');
|
||||
|
||||
for (int lpc = 0; lpc <= s_row.sr_width; lpc++) {
|
||||
if (s_row.sr_values[lpc].rb_marks) {
|
||||
value_out[lpc] = 'x';
|
||||
}
|
||||
}
|
||||
|
||||
if (this->ss_cursor_top == row && this->ss_cursor_column != -1) {
|
||||
if (value_out[this->ss_cursor_column] == 'x') {
|
||||
value_out[this->ss_cursor_column] = '*';
|
||||
}
|
||||
else {
|
||||
value_out[this->ss_cursor_column] = '+';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void text_attrs_for_line(textview_curses &tc,
|
||||
@ -255,44 +379,12 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
this->cache_bounds();
|
||||
|
||||
view_colors &vc = view_colors::singleton();
|
||||
unsigned long width;
|
||||
vis_line_t height;
|
||||
|
||||
tc.get_dimensions(height, width);
|
||||
width -= 2;
|
||||
|
||||
spectrogram_bounds &sb = this->ss_cached_bounds;
|
||||
spectrogram_thresholds &st = this->ss_cached_thresholds;
|
||||
spectrogram_request sr(sb);
|
||||
time_t row_time;
|
||||
spectrogram_row &s_row = this->load_row(tc, row);
|
||||
|
||||
sr.sr_width = width;
|
||||
row_time = rounddown(sb.sb_begin_time, this->ss_granularity) +
|
||||
row * this->ss_granularity;
|
||||
sr.sr_begin_time = row_time;
|
||||
sr.sr_end_time = row_time + this->ss_granularity;
|
||||
|
||||
sr.sr_column_size = (sb.sb_max_value_out - sb.sb_min_value_out) /
|
||||
(double) (width - 1);
|
||||
|
||||
spectrogram_row &s_row = this->ss_row_cache[row_time];
|
||||
|
||||
if (s_row.sr_values == NULL ||
|
||||
s_row.sr_width != width ||
|
||||
s_row.sr_column_size != sr.sr_column_size) {
|
||||
s_row.sr_width = width;
|
||||
s_row.sr_column_size = sr.sr_column_size;
|
||||
delete s_row.sr_values;
|
||||
s_row.sr_values = new int[width + 1];
|
||||
memset(s_row.sr_values, 0, sizeof(int) * (width + 1));
|
||||
this->ss_value_source->spectro_row(sr, s_row);
|
||||
}
|
||||
|
||||
for (int lpc = 0; lpc <= width; lpc++) {
|
||||
int col_value = s_row.sr_values[lpc];
|
||||
for (int lpc = 0; lpc <= s_row.sr_width; lpc++) {
|
||||
int col_value = s_row.sr_values[lpc].rb_counter;
|
||||
|
||||
if (col_value == 0) {
|
||||
continue;
|
||||
@ -357,12 +449,52 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
spectrogram_row &load_row(textview_curses &tc, int row) {
|
||||
this->cache_bounds();
|
||||
|
||||
unsigned long width;
|
||||
vis_line_t height;
|
||||
|
||||
tc.get_dimensions(height, width);
|
||||
width -= 2;
|
||||
|
||||
spectrogram_bounds &sb = this->ss_cached_bounds;
|
||||
spectrogram_request sr(sb);
|
||||
time_t row_time;
|
||||
|
||||
sr.sr_width = width;
|
||||
row_time = rounddown(sb.sb_begin_time, this->ss_granularity) +
|
||||
row * this->ss_granularity;
|
||||
sr.sr_begin_time = row_time;
|
||||
sr.sr_end_time = row_time + this->ss_granularity;
|
||||
|
||||
sr.sr_column_size = (sb.sb_max_value_out - sb.sb_min_value_out) /
|
||||
(double) (width - 1);
|
||||
|
||||
spectrogram_row &s_row = this->ss_row_cache[row_time];
|
||||
|
||||
if (s_row.sr_values == NULL ||
|
||||
s_row.sr_width != width ||
|
||||
s_row.sr_column_size != sr.sr_column_size) {
|
||||
s_row.sr_width = width;
|
||||
s_row.sr_column_size = sr.sr_column_size;
|
||||
delete s_row.sr_values;
|
||||
s_row.sr_values = new spectrogram_row::row_bucket[width + 1];
|
||||
memset(s_row.sr_values, 0, sizeof(int) * (width + 1));
|
||||
this->ss_value_source->spectro_row(sr, s_row);
|
||||
}
|
||||
|
||||
return s_row;
|
||||
}
|
||||
|
||||
int ss_granularity;
|
||||
spectrogram_value_source *ss_value_source;
|
||||
spectrogram_bounds ss_cached_bounds;
|
||||
spectrogram_thresholds ss_cached_thresholds;
|
||||
size_t ss_cached_line_count;
|
||||
std::map<time_t, spectrogram_row> ss_row_cache;
|
||||
vis_line_t ss_cursor_top;
|
||||
int ss_cursor_column;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user