diff options
-rw-r--r-- | gps/client.py | 3 | ||||
-rwxr-xr-x | gpsprof | 47 | ||||
-rw-r--r-- | gpsprof.xml | 9 |
3 files changed, 42 insertions, 17 deletions
diff --git a/gps/client.py b/gps/client.py index f4c1e7cb..e21c2807 100644 --- a/gps/client.py +++ b/gps/client.py @@ -21,7 +21,8 @@ class gpscommon: self.sock = None # in case we blow up in connect self.linebuffer = "" self.verbose = verbose - self.connect(host, port) + if host != None: + self.connect(host, port) def connect(self, host, port): """Connect to a host on a given port. @@ -6,7 +6,7 @@ # Collect and plot latency-profiling data from a running gpsd. # Requires gnuplot. # -import sys, os, time, getopt, socket, math, copy, signal +import sys, os, time, getopt, socket, math, copy, signal, json import gps class Baton: @@ -47,12 +47,12 @@ class plotter: self.fixes = [] self.start_time = int(time.time()) def whatami(self): - "How do we identify this pollting run?" + "How do we identify this plotting run?" return "%s, %s, %d %dN%d, cycle %ds" % \ - (gps.misc.isotime(self.start_time), - self.device.get('driver', "unknown"), self.device['bps'], - 9 - self.device['stopbits'], - self.device['stopbits'], self.device['cycle']) + (gps.misc.isotime(self.start_time), + self.device.get('driver', "unknown"), self.device['bps'], + 9 - self.device['stopbits'], + self.device['stopbits'], self.device['cycle']) def collect(self, verbose, logfp=None): "Collect data from the GPS." try: @@ -106,12 +106,25 @@ class plotter: continue if countdown == await: sys.stderr.write("first fix in %.2fsec, gathering %d samples..." % (time.time()-basetime,await)) - if plotter.sample(): + if self.sample(): countdown -= 1 baton.end() finally: self.session.send('?WATCH={"enable":false,"timing":false}') signal.signal(signal.SIGUSR1, signal.SIG_DFL) + def replot(self, infp): + "Replot from a JSON log file." + baton = Baton("gpsprof: replotting", "done") + self.session = gps.gps(host=None) + for line in infp: + baton.twirl() + self.session.unpack(line) + if self.session.data["class"] == "DEVICES": + self.device = copy.copy(self.session.data["devices"][0]) + elif self.session.data["class"] != "TPV": + continue + self.sample() + baton.end() def dump(self): "Dump the raw data for post-analysis." return self.header() + self.data() @@ -305,7 +318,7 @@ formatters = (spaceplot, uninstrumented, instrumented) if __name__ == '__main__': try: - (options, arguments) = getopt.getopt(sys.argv[1:], "d:f:hl:m:n:s:t:T:D:") + (options, arguments) = getopt.getopt(sys.argv[1:], "d:f:hl:m:n:rs:t:T:D:") plotmode = "space" raw = False @@ -316,6 +329,7 @@ if __name__ == '__main__': terminal = None dumpfile = None logfp = None + redo = False for (switch, val) in options: if (switch == '-f'): plotmode = val @@ -334,6 +348,8 @@ if __name__ == '__main__': dumpfile = val elif (switch == '-l'): logfp = open(val, "w") + elif (switch == '-r'): + redo = True elif (switch == '-D'): verbose = int(val) elif (switch == '-h'): @@ -345,27 +361,30 @@ if __name__ == '__main__': if plotmode: for formatter in formatters: if formatter.name == plotmode: - plotter = formatter() + plot = formatter() break else: sys.stderr.write("gpsprof: no such formatter.\n") sys.exit(1) # Get fix data from the GPS - plotter.collect(verbose, logfp) - plotter.postprocess() + if redo: + plot.replot(sys.stdin) + else: + plot.collect(verbose, logfp) + plot.postprocess() # Save the timing data (only) for post-analysis if required. if dumpfile: with open(dumpfile, "w") as fp: - fp.write(plotter.dump()) + fp.write(plot.dump()) if logfp: logfp.close() # Ship the plot to standard output if not title: - title = plotter.whatami() + title = plot.whatami() if terminal: sys.stdout.write("set terminal %s\n" % terminal) sys.stdout.write("set title \"%s\"\n" % title) - sys.stdout.write(plotter.plot()) + sys.stdout.write(plot.plot()) except KeyboardInterrupt: pass diff --git a/gpsprof.xml b/gpsprof.xml index d0be6bde..099af047 100644 --- a/gpsprof.xml +++ b/gpsprof.xml @@ -27,8 +27,9 @@ BSD terms apply: see the file COPYING in the distribution root for details. <arg choice='opt'>-n <replaceable>packetcount</replaceable></arg> <arg choice='opt'>-t <replaceable>title</replaceable></arg> <arg choice='opt'>-T <replaceable>terminal</replaceable></arg> - <arg choice='opt'>-d <replaceable>dumpfile</replaceable></arg> - <arg choice='opt'>-l <replaceable>logfile</replaceable></arg> + <arg choice='opt'>-d <replaceable>dumpfile</replaceable></arg> + <arg choice='opt'>-l <replaceable>logfile</replaceable></arg> + <arg choice='opt'>-r </arg> <arg choice='opt'>-D <replaceable>debuglevel</replaceable></arg> <arg choice='opt'>-h</arg> </cmdsynopsis> @@ -165,6 +166,10 @@ code, to a specified file for post-analysis.</para> <para>The -l option dumps the raw JSON reports collected from the device to a specified file.</para> +<para>The -r option replots from a JSON logfile (such as -l produces) +on standard input. Both -n and -l options are ignored when this +one is selected.</para> + <para>The -h option makes <application>gpsprof</application> print a usage message and exit.</para> |