File: oscilloscope-cmd.py

package info (click to toggle)
tuna 0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 860 kB
  • sloc: python: 4,310; sh: 161; makefile: 43
file content (107 lines) | stat: -rwxr-xr-x 3,783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python3
# Arnaldo Carvalho de Melo <acme@redhat.com>
#
# Please check the tuna repository at:
# http://git.kernel.org/?p=linux/kernel/git/acme/tuna.git;a=tree
# For newer versions and to see it integrated with tuna
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation;
# version 2.1 of the License.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

import getopt
import sys
import gi
from gi.repository import Gtk
gi.require_version("Gtk", "3.0")
from tuna import oscilloscope


def usage():
    print('''Usage: oscilloscope [OPTIONS]
    -h, --help			Give this help list
    -d, --delimiter=CHARACTER	CHARACTER used as a delimiter [Default: :]
    -f, --field=FIELD		FIELD to plot [Default: 2]
    -g, --geometry=GEOMETRY         X geometry specification (see "X" man page)
    -m, --max_value=MAX_VALUE	MAX_VALUE for the scale
    -M, --sample_multiplier=VALUE	VALUE to multiply each sample
    -n, --noscale			Do not scale when a sample is > MAX_SCALE
    -s, --nr_samples_on_screen=NR	Show NR samples on screen
    -S, --snapshot_samples=NR	Take NR samples, a snapshot and exit
    -u, --unit=TYPE			Unit TYPE [Default: us]
''')


def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:],
                                   "d:f:g:hM:m:ns:S:u:",
                                   ("geometry=",
                                    "help", "max_value=",
                                    "sample_multiplier=",
                                    "noscale",
                                    "nr_samples_on_screen=",
                                    "snapshot_samples=",
                                    "unit="))
    except getopt.GetoptError as err:
        usage()
        print(str(err))
        sys.exit(2)

    max_value = 250
    sample_multiplier = 1
    snapshot_samples = 0
    delimiter = ':'
    field = 2
    ylabel = "Latency"
    unitlabel = "us"
    geometry = None
    scale = True
    nr_samples_on_screen = 250

    for o, a in opts:
        if o in ("-d", "--delimiter"):
            delimiter = a
        elif o in ("-f", "--field"):
            field = int(a)
        elif o in ("-g", "--geometry"):
            geometry = a
        elif o in ("-h", "--help"):
            usage()
            return
        elif o in ("-m", "--max_value"):
            max_value = int(a)
        elif o in ("-M", "--sample_multiplier"):
            sample_multiplier = float(a)
        elif o in ("-n", "--noscale"):
            scale = False
        elif o in ("-s", "--nr_samples_on_screen"):
            nr_samples_on_screen = int(a)
        elif o in ("-S", "--snapshot_samples"):
            snapshot_samples = int(a)
        elif o in ("-u", "--unit"):
            unitlabel = a

    o = oscilloscope.cyclictestoscope(max_value, snapshot_samples,
                                      nr_samples_on_screen=nr_samples_on_screen,
                                      delimiter=delimiter, field=field,
                                      ylabel="%s (%s)" % (ylabel, unitlabel),
                                      geometry=geometry, scale=scale,
                                      sample_multiplier=sample_multiplier)
    o.run()
    Gtk.main()


if __name__ == '__main__':
    main()