This file is indexed.

/usr/bin/circuits.bench is in python-circuits 2.1.0-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#! /usr/bin/python
# -*- coding: utf-8 -*-


"""(Tool) Bench Marking Tool

THis tool does some simple benchmaking of the circuits library.
"""

import sys
import math
import optparse

from time import sleep

if sys.platform == "win32":
    from time import clock as time
else:
    from time import time  # NOQA

try:
    import hotshot
    import hotshot.stats
except ImportError:
    hotshot = None  # NOQA

try:
    import psyco
except ImportError:
    psyco = None  # NOQA

from circuits import __version__ as systemVersion
from circuits import handler, Event, Component, Manager, Debugger

USAGE = "%prog [options]"
VERSION = "%prog v" + systemVersion


def duration(seconds):
    days = int(seconds / 60 / 60 / 24)
    seconds = (seconds) % (60 * 60 * 24)
    hours = int((seconds / 60 / 60))
    seconds = (seconds) % (60 * 60)
    mins = int((seconds / 60))
    seconds = int((seconds) % (60))
    return (days, hours, mins, seconds)


def parse_options():
    """parse_options() -> opts, args

    Parse the command-line options given returning both
    the parsed options and arguments.
    """

    parser = optparse.OptionParser(usage=USAGE, version=VERSION)

    parser.add_option(
        "-t", "--time",
        action="store", type="int", default=0, dest="time",
        help="Stop after specified elapsed seconds"
    )

    parser.add_option(
        "-e", "--events",
        action="store", type="int", default=0, dest="events",
        help="Stop after specified number of events"
    )

    parser.add_option(
        "-p", "--profile",
        action="store_true", default=False, dest="profile",
        help="Enable execution profiling support"
    )

    parser.add_option(
        "-d", "--debug",
        action="store_true", default=False, dest="debug",
        help="Enable debug mode"
    )

    parser.add_option(
        "-m", "--mode",
        action="store", type="choice", default="speed", dest="mode",
        choices=["sync", "speed", "latency"],
        help="Operation mode"
    )

    parser.add_option(
        "-s", "--speed",
        action="store_true", default=False, dest="speed",
        help="Enable psyco (circuits on speed!)"
    )

    parser.add_option(
        "-q", "--quiet",
        action="store_false", default=True, dest="verbose",
        help="Suppress output"
    )

    opts, args = parser.parse_args()

    return opts, args


class Stop(Event):
    """Stop Event"""


class Term(Event):
    """Term Event"""


class Hello(Event):
    """Hello Event"""


class Received(Event):
    """Received Event"""


class Base(Component):

    def __init__(self, opts, *args, **kwargs):
        super(Base, self).__init__(*args, **kwargs)

        self.opts = opts


class SpeedTest(Base):

    def received(self, message=""):
        self.fire(Hello("hello"))

    def hello(self, message):
        self.fire(Received(message))


class LatencyTest(Base):

    t = None

    def received(self, message=""):
        print("Latency: %0.9f us" % ((time() - self.t) * 1e6))
        sleep(1)
        self.fire(Hello("hello"))

    def hello(self, message=""):
        self.t = time()
        self.fire(Received(message))


class State(Base):

    done = False

    def stop(self):
        self.fire(Term())

    def term(self):
        self.done = True


class Monitor(Base):

    sTime = sys.maxsize
    events = 0
    state = 0

    @handler(filter=True)
    def event(self, *args, **kwargs):
        self.events += 1

        if self.events > self.opts.events:
            self.stop()


def main():
    opts, args = parse_options()

    if opts.speed and psyco:
        psyco.full()

    manager = Manager()

    monitor = Monitor(opts)
    manager += monitor

    state = State(opts)
    manager += state

    if opts.debug:
        manager += Debugger()

    if opts.mode.lower() == "speed":
        if opts.verbose:
            print("Setting up Speed Test...")
        manager += SpeedTest(opts)
        monitor.sTime = time()
    elif opts.mode.lower() == "latency":
        if opts.verbose:
            print("Setting up Latency Test...")
        manager += LatencyTest(opts)
        monitor.sTime = time()

    if opts.verbose:
        print("Setting up Sender...")
        print("Setting up Receiver...")

    monitor.sTime = time()

    if opts.profile:
        if hotshot:
            profiler = hotshot.Profile("bench.prof")
            profiler.start()

    manager.fire(Hello("hello"))

    while not state.done:
        try:
            manager.tick()

            if opts.events > 0 and monitor.events > opts.events:
                manager.fire(Stop())
            if opts.time > 0 and (time() - monitor.sTime) > opts.time:
                manager.fire(Stop())
        except KeyboardInterrupt:
            manager.fire(Stop())

    if opts.verbose:
        print()

    eTime = time()

    tTime = eTime - monitor.sTime

    events = monitor.events
    speed = int(math.ceil(float(monitor.events) / tTime))

    print("Total Events: %d (%d/s after %0.2fs)" % (events, speed, tTime))

    if opts.profile and hotshot:
        profiler.stop()
        profiler.close()

        stats = hotshot.stats.load("bench.prof")
        stats.strip_dirs()
        stats.sort_stats("time", "calls")
        stats.print_stats(20)

###
### Entry Point
###

if __name__ == "__main__":
    main()