/usr/share/pyshared/funkload/FunkLoadHTTPServer.py is in funkload 1.16.1-4.
This file is owned by root:root, with mode 0o644.
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 | #!/usr/bin/python
# (C) Copyright 2010 Nuxeo SAS <http://nuxeo.com>
# Author: Goutham Bhat
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
"""Debug HTTPServer module for Funkload."""
import BaseHTTPServer
import threading
import urlparse
from utils import trace
class FunkLoadHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""Handles HTTP requests from client in debug bench mode.
These are the requests currently supported:
/cvu?inc=<INTEGER> :: Increments number of CVU by given value.
/cvu?dec=<INTEGER> :: Decrements number of CVU by given value.
"""
benchrunner = None
def do_GET(self):
benchrunner = FunkLoadHTTPRequestHandler.benchrunner
parsed_url = urlparse.urlparse(self.path)
if parsed_url.path == '/cvu':
query_args = parsed_url.query.split('&')
if len(query_args) > 0:
query_parts = query_args[0].split('=')
if len(query_parts) == 2:
message = 'Number of threads changed from %d to %d.'
old_num_threads = benchrunner.getNumberOfThreads()
if query_parts[0] == 'inc':
benchrunner.addThreads(int(query_parts[1]))
elif query_parts[0] == 'dec':
benchrunner.removeThreads(int(query_parts[1]))
new_num_threads = benchrunner.getNumberOfThreads()
self.respond('CVU changed from %d to %d.' %
(old_num_threads, new_num_threads))
elif parsed_url.path == '/getcvu':
self.respond('CVU = %d' % benchrunner.getNumberOfThreads())
def respond(self, message):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(message)
class FunkLoadHTTPServer(threading.Thread):
"""Starts a HTTP server in a separate thread."""
def __init__(self, benchrunner, port):
threading.Thread.__init__(self)
self.benchrunner = benchrunner
self.port = port
FunkLoadHTTPRequestHandler.benchrunner = benchrunner
def run(self):
port = 8000
if self.port:
port = int(self.port)
server_address = ('', port)
trace("Starting debug HTTP server at port %d\n" % port)
httpd = BaseHTTPServer.HTTPServer(server_address, FunkLoadHTTPRequestHandler)
httpd.serve_forever()
|