mirror of https://github.com/tstack/lnav.git
[time-offset] fixes
Defect Number: Reviewed By: Testing Done:
This commit is contained in:
parent
6f41cbe394
commit
469124d72b
3
NEWS
3
NEWS
|
@ -25,6 +25,8 @@ lnav v0.8.5:
|
|||
to a single file.
|
||||
* Added 'spooky_hash()' and 'group_spooky_hash()' SQL functions to
|
||||
generate a hash of their parameters.
|
||||
* Added 'time_offset' to the 'lnav_file' table so that the timestamps in
|
||||
a file can be adjusted programmatically.
|
||||
|
||||
Interface Changes:
|
||||
* The auto-complete behavior in the prompt has been modified to fall back
|
||||
|
@ -49,6 +51,7 @@ lnav v0.8.5:
|
|||
contents of the current view and a ":write-screen-to" command has been
|
||||
added to write only the current screen contents.
|
||||
* Disabled filters are now saved in sessions.
|
||||
* The ":adjust-log-time" command now accepts relative times as input.
|
||||
|
||||
Fixes:
|
||||
* The ":write-json-to" command will now pass through JSON cells as their
|
||||
|
|
|
@ -65,7 +65,7 @@ Navigation
|
|||
Time
|
||||
----
|
||||
|
||||
* adjust-log-time <date> - Change the timestamps for a log file.
|
||||
* adjust-log-time <date|relative-time> - Change the timestamps for a log file.
|
||||
* unix-time <secs-or-date> - Convert a unix-timestamp in seconds to a
|
||||
human-readable form or vice-versa.
|
||||
* current-time - Print the current time in human-readable form and as
|
||||
|
|
|
@ -48,11 +48,12 @@ struct lnav_file : public tvt_iterator_cursor<lnav_file> {
|
|||
static constexpr const char *CREATE_STMT = R"(
|
||||
-- Access lnav's open file list through this table.
|
||||
CREATE TABLE lnav_file (
|
||||
device integer, -- The device the file is stored on.
|
||||
inode integer, -- The inode for the file on the device.
|
||||
filepath text, -- The path to the file.
|
||||
format text, -- The log file format for the file.
|
||||
lines integer -- The number of lines in the file.
|
||||
device integer, -- The device the file is stored on.
|
||||
inode integer, -- The inode for the file on the device.
|
||||
filepath text, -- The path to the file.
|
||||
format text, -- The log file format for the file.
|
||||
lines integer, -- The number of lines in the file.
|
||||
base_time integer -- The millisecond offset for timestamps.
|
||||
);
|
||||
)";
|
||||
|
||||
|
@ -96,6 +97,13 @@ CREATE TABLE lnav_file (
|
|||
case 4:
|
||||
to_sqlite(ctx, (int64_t) lf->size());
|
||||
break;
|
||||
case 5: {
|
||||
auto tv = lf->get_time_offset();
|
||||
int64_t ms = (tv.tv_sec * 1000LL) + tv.tv_usec / 1000LL;
|
||||
|
||||
to_sqlite(ctx, ms);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ensure(0);
|
||||
break;
|
||||
|
@ -103,6 +111,37 @@ CREATE TABLE lnav_file (
|
|||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int delete_row(sqlite3_vtab *vt, sqlite3_int64 rowid) {
|
||||
vt->zErrMsg = sqlite3_mprintf(
|
||||
"Rows cannot be deleted from this table");
|
||||
return SQLITE_ERROR;
|
||||
};
|
||||
|
||||
int insert_row(sqlite3_vtab *tab, sqlite3_int64 &rowid_out) {
|
||||
tab->zErrMsg = sqlite3_mprintf(
|
||||
"Rows cannot be inserted into this table");
|
||||
return SQLITE_ERROR;
|
||||
};
|
||||
|
||||
int update_row(sqlite3_vtab *tab,
|
||||
sqlite3_int64 &rowid,
|
||||
sqlite3_int64 device,
|
||||
sqlite3_int64 inode,
|
||||
const char *path,
|
||||
const char *format,
|
||||
sqlite3_int64 lines,
|
||||
sqlite3_int64 time_offset) {
|
||||
auto lf = lnav_data.ld_files[rowid];
|
||||
struct timeval tv = {
|
||||
(int) (time_offset / 1000LL),
|
||||
(int) (time_offset / (1000LL * 1000LL)),
|
||||
};
|
||||
|
||||
lf->adjust_content_time(0, tv, true);
|
||||
|
||||
return SQLITE_OK;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
|
13
src/help.txt
13
src/help.txt
|
@ -480,12 +480,13 @@ COMMANDS
|
|||
|
||||
help Switch to this help text view.
|
||||
|
||||
adjust-log-time <date>
|
||||
Change the time of the top log line to the given time.
|
||||
All other log lines in the same file will also be
|
||||
adjusted using the same offset. After the adjustment,
|
||||
the displayed timestamp will be rewritten to the new
|
||||
time and highlighted with a magenta color.
|
||||
adjust-log-time <date|relative-time>
|
||||
Change the time of the top log line to the given time or
|
||||
adjusted by the relative time. All other log lines in the
|
||||
same file will also be adjusted using the same offset.
|
||||
After the adjustment, the displayed timestamp will be
|
||||
rewritten to the new time and highlighted with a magenta
|
||||
color.
|
||||
|
||||
This command is useful for lining up log files that
|
||||
have timestamps from different machines.
|
||||
|
|
|
@ -137,6 +137,8 @@ static string com_adjust_log_time(exec_context &ec, string cmdline, vector<strin
|
|||
vis_line_t top_line;
|
||||
struct exttm tm;
|
||||
std::shared_ptr<logfile> lf;
|
||||
relative_time rt;
|
||||
struct relative_time::parse_error pe;
|
||||
|
||||
top_line = lnav_data.ld_views[LNV_LOG].get_top();
|
||||
top_content = lss.at(top_line);
|
||||
|
@ -148,26 +150,31 @@ static string com_adjust_log_time(exec_context &ec, string cmdline, vector<strin
|
|||
|
||||
dts.set_base_time(top_time.tv_sec);
|
||||
args[1] = remaining_args(cmdline, args);
|
||||
if (dts.scan(args[1].c_str(), args[1].size(), NULL, &tm, new_time) != NULL) {
|
||||
timersub(&new_time, &top_time, &time_diff);
|
||||
|
||||
if (ec.ec_dry_run) {
|
||||
char buffer[1024];
|
||||
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"info: log timestamps will be adjusted by %ld.%06ld seconds",
|
||||
time_diff.tv_sec, time_diff.tv_usec);
|
||||
|
||||
retval = buffer;
|
||||
} else {
|
||||
lf->adjust_content_time(top_content, time_diff, false);
|
||||
|
||||
lss.set_force_rebuild();
|
||||
|
||||
retval = "info: adjusted time";
|
||||
}
|
||||
if (rt.parse(args[1], pe)) {
|
||||
new_time = rt.add(top_time).to_timeval();
|
||||
}
|
||||
else if (dts.scan(args[1].c_str(), args[1].size(), NULL, &tm, new_time) != NULL) {
|
||||
// nothing to do
|
||||
} else {
|
||||
retval = "error: could not parse timestamp";
|
||||
return "error: could not parse timestamp";
|
||||
}
|
||||
|
||||
timersub(&new_time, &top_time, &time_diff);
|
||||
if (ec.ec_dry_run) {
|
||||
char buffer[1024];
|
||||
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"info: log timestamps will be adjusted by %ld.%06ld seconds",
|
||||
time_diff.tv_sec, time_diff.tv_usec);
|
||||
|
||||
retval = buffer;
|
||||
} else {
|
||||
lf->adjust_content_time(top_content, time_diff, false);
|
||||
|
||||
lss.set_force_rebuild();
|
||||
|
||||
retval = "info: adjusted time";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -480,12 +480,13 @@ COMMANDS
|
|||
|
||||
help Switch to this help text view.
|
||||
|
||||
adjust-log-time <date>
|
||||
Change the time of the top log line to the given time.
|
||||
All other log lines in the same file will also be
|
||||
adjusted using the same offset. After the adjustment,
|
||||
the displayed timestamp will be rewritten to the new
|
||||
time and highlighted with a magenta color.
|
||||
adjust-log-time <date|relative-time>
|
||||
Change the time of the top log line to the given time or
|
||||
adjusted by the relative time. All other log lines in the
|
||||
same file will also be adjusted using the same offset.
|
||||
After the adjustment, the displayed timestamp will be
|
||||
rewritten to the new time and highlighted with a magenta
|
||||
color.
|
||||
|
||||
This command is useful for lining up log files that
|
||||
have timestamps from different machines.
|
||||
|
|
|
@ -163,6 +163,16 @@ check_output "adjust-log-time is not working" <<EOF
|
|||
192.168.202.254 - - [01/Jan/2010:00:00:03 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
|
||||
EOF
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":adjust-log-time -1h" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "adjust-log-time is not working" <<EOF
|
||||
192.168.202.254 - - [20/Jul/2009:21:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
|
||||
192.168.202.254 - - [20/Jul/2009:21:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
|
||||
192.168.202.254 - - [20/Jul/2009:21:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":goto 1" \
|
||||
|
|
|
@ -2,6 +2,30 @@
|
|||
|
||||
lnav_test="${top_builddir}/src/lnav-test"
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ";SELECT basename(filepath),format,lines,base_time FROM lnav_file" \
|
||||
-c ":write-csv-to -" \
|
||||
${test_dir}/logfile_access_log.0 \
|
||||
${test_dir}/logfile_access_log.1
|
||||
|
||||
check_output "lnav_file table is not working?" <<EOF
|
||||
basename(filepath),format,lines,base_time
|
||||
logfile_access_log.0,access_log,3,0
|
||||
logfile_access_log.1,access_log,1,0
|
||||
EOF
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ";UPDATE lnav_file SET base_time = 60 * 1000" \
|
||||
${test_dir}/logfile_access_log.0 \
|
||||
${test_dir}/logfile_access_log.1
|
||||
|
||||
check_output "time_offset in lnav_file table is not working?" <<EOF
|
||||
192.168.202.254 - - [20/Jul/2009:23:00:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
|
||||
192.168.202.254 - - [20/Jul/2009:23:00:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
|
||||
192.168.202.254 - - [20/Jul/2009:23:00:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
|
||||
10.112.81.15 - - [15/Feb/2013:06:01:31 +0000] "-" 400 0 "-" "-"
|
||||
EOF
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ";INSERT INTO lnav_view_filters VALUES ('log', 0, 1, 'out', '')" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
|
Loading…
Reference in New Issue