[Git][NTPsec/ntpsec][master] Deleted 1 commit: ntpviz, now 2x faster.
Gary E. Miller
gitlab at mg.gitlab.com
Sat Aug 20 02:26:01 UTC 2016
Gary E. Miller pushed to branch master at NTPsec / ntpsec
WARNING: The push did not contain any new commits, but force pushed to delete the commits and changes below.
Deleted commits:
696c2fab by Gary E. Miller at 2016-08-19T19:23:10-07:00
ntpviz, now 2x faster.
Throw out data not needed much earlier.
- - - - -
2 changed files:
- ntpstats/ntpviz
- pylib/statfiles.py
Changes:
=====================================
ntpstats/ntpviz
=====================================
--- a/ntpstats/ntpviz
+++ b/ntpstats/ntpviz
@@ -19,7 +19,7 @@ Python by ESR, concept and GNUPLOT code by Dan Drown.
#SPDX-License-Identifier: BSD-2-Clause
from __future__ import print_function, division
-import os, sys, getopt, socket, binascii, datetime, collections, gzip
+import os, sys, getopt, socket, binascii, datetime, collections, gzip, time
from ntp.statfiles import *
#import cProfile, pstats, StringIO
@@ -57,8 +57,9 @@ set xtic rotate by -45 scale 0
set lmargin 12
set rmargin 12
"""
- def __init__(self, statsdir, sitename=None):
- NTPStats.__init__(self, sitename, statsdir)
+ def __init__(self, statsdir, starttime, endtime, sitename=None):
+ NTPStats.__init__(self, sitename, statsdir, starttime=starttime, \
+ endtime=endtime)
if self.sitename is None:
self.sitename = os.path.basename(statsdir)
def local_offset_gnuplot(self):
@@ -329,18 +330,21 @@ if __name__ == '__main__':
elif switch == "--local-cpu-temp":
show_cpu_temp = True
period = 24 * 60 * 60 * period_days
- statlist = [NTPViz(statsdir=d, sitename=sitename) for d in statsdirs]
- for stats in statlist:
- # Default to one week before the latest date
- if endtime is None and starttime == None:
- endtime = int(stats.rangemax())
- starttime = endtime - period
- elif starttime is None and endtime is not None:
- starttime = endtime - period
- elif starttime is not None and endtime is None:
- endtime = starttime + period
- if starttime:
- stats.clip(starttime, endtime)
+
+ start_time = datetime.datetime.utcnow()
+ start_time_secs = time.time()
+
+ # Default to one week before the latest date
+ if endtime is None and starttime == None:
+ endtime = int(start_time_secs)
+ starttime = endtime - period
+ elif starttime is None and endtime is not None:
+ starttime = endtime - period
+ elif starttime is not None and endtime is None:
+ endtime = starttime + period
+
+ statlist = [NTPViz(statsdir=d, sitename=sitename, starttime=starttime, \
+ endtime=endtime) for d in statsdirs]
for fontpath in ("/usr/share/fonts/liberation",
"/usr/share/fonts/liberation-fonts",
@@ -416,7 +420,6 @@ if __name__ == '__main__':
with open(os.path.join(outdir, "ntpsec-logo.png"), "w") as wp:
wp.write(binascii.a2b_base64(ntpsec_logo))
- now = datetime.datetime.utcnow()
index_header = '''\
<!DOCTYPE html>
<html lang="en">
@@ -433,7 +436,7 @@ if __name__ == '__main__':
<div>
<h1 style="margin-bottom:10px;">NTP Stats</h1>
'''
- index_header += 'Last Update: %s UTC <br>' % now.strftime("%c")
+ index_header += 'Last Update: %s UTC <br>' % start_time.strftime("%c")
index_header += 'Period: %s days <br></div> ' % period_days
index_header += '<div style="clear:both;"></div>'
=====================================
pylib/statfiles.py
=====================================
--- a/pylib/statfiles.py
+++ b/pylib/statfiles.py
@@ -12,7 +12,7 @@ import os, sys, time, glob, calendar, subprocess, socket
class NTPStats:
"Gather statistics for a specified NTP site"
@staticmethod
- def unixize(line):
+ def unixize(line, starttime, endtime):
"Extract first two fields, MJD and seconds past midnight."
"convert timestamp (MJD & seconds past midnight) to Unix time"
"Replace MJD+second with Unix time."
@@ -23,12 +23,14 @@ class NTPStats:
# unparseable time 0 and it will be stripped later
return None
time = 24*60*60*mjd+second-3506716800; # warning: 32 bit overflows
+ if time < starttime or time > endtime:
+ return None
return str( str(time) + " " + " ".join(line.split()[2:]))
@staticmethod
def timestamp(line):
"get Unix time from converted line."
return float(line.split()[0])
- def __init__(self, sitename, statsdir):
+ def __init__(self, sitename, statsdir, starttime=0,endtime=9999999999):
"Grab content of all logfiles, sorted by timestamp."
self.sitename = sitename
for stem in ("clockstats", "peerstats", "loopstats", "rawstats", "cputemp"):
@@ -42,14 +44,20 @@ class NTPStats:
except IOError:
pass
# Filter out blank lines (we don't know where these come from)
- lines = [line.strip(' \0\r\n\t') \
- for line in lines if line.strip(' \0\r\n\t')]
- if stem != "cputemp":
+ lines = [line.strip(' \0\r\n\t') for line in lines]
+ if stem == "cputemp":
+ # cputemp is already in UNIX time
+ lines = [ line for line in lines if (line != None \
+ and int(line.split()[0]) >= starttime and \
+ int(line.split()[0]) <= endtime) ]
+ else:
# Morph first field into Unix time with fractional seconds
- lines = [NTPStats.unixize(line) for line in lines \
- if line != None]
+ lines = [ NTPStats.unixize(line,starttime, endtime) \
+ for line in lines if line != None]
+
+ lines = [ line for line in lines if line != None]
# Sort by datestamp
- lines.sort(key=lambda line: line[0])
+ lines.sort(key=lambda line: line.split()[0])
setattr(self, stem, lines)
def clip(self, start, end):
"Select a range of entries"
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/696c2fab13ba7c28b7d9db1b906155a2e32c8e7c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160820/88a50318/attachment.html>
More information about the vc
mailing list