Skip to content

Commit 7c5b19e

Browse files
authored
Merge pull request #45196 from richardkasongo2003/vis_server
Added local web server for Tracer log viewer
2 parents d0c5d92 + 4ef1136 commit 7c5b19e

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

FWCore/Services/web/README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@
55
### standard web server
66
If the output of `edmTracerCompactLogViewer.py` and the files from `FWCore/Services/web` have been placed in a directory accessible to a web server, you may just point your browser to the correct URL to run the viewer.
77

8-
### local file
9-
By default, web browsers are not allowed to read files from the local disk. Many browsers give options to override that default. After overriding the default, make sure the output of `edmTracerCompactLogViewer.py` and the files from `FWCore/Services/web` have been placed in a directory on your local machine. Then tell your web browser to open the `index.html` file in that directory to start the viewer.
8+
# My HTTP Server
109

11-
#### Local files in Chrome
12-
In order to open a local file using Chrome, you need to
13-
1. Exit from Chrome
14-
1. Start Chrome from the terminal using the `--allow-file-access-from-files` argument.
10+
This is a simple HTTP server implemented in Python using the `http.server` module.
11+
12+
## Usage
13+
14+
1. Run the server script (`server.py`) using Python.
15+
2. Access the server in your web browser by navigating to `http://localhost:65432`.
1516

16-
On macOS, within Terminal the command would be
17-
```
18-
open -a Google\ Chrome --args --allow-file-access-from-files file://<where ever the directory is>/index.html
19-
```
2017

21-
#### Local file in Safari
22-
Local file support in Safari requires access the the Developer menu options. You can turn on those options by going to `Safari/Settings...`, choose the `Advanced` tab and then toggle `Show features for web developers`. Then in the newly added `Developer` tag, toggle `Disable local file restrictions`. Once you've done that, you can use `file://<where ever the directory is>/index.html` to start the application.
2318

2419
## Viewer layout
2520
The viewer is composed to two main areas, the top is the timing viewer and at the bottom shows information about a selected time block. The top time viewer is further divided into three parts. On the left is the macro scoping grouping of framework activity types into Global and Stream activities. If the _module centric_ option was chosen then this area is also divided by each module activity which is sorted based on most time used to least time used. At the bottom is the measurement of time since the start of the job. The main area shows the blocks of time spend doing various work within the Framework.

FWCore/Services/web/server.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from http.server import HTTPServer, BaseHTTPRequestHandler
2+
import os
3+
import mimetypes
4+
5+
class Serv(BaseHTTPRequestHandler):
6+
def do_GET(self):
7+
if self.path == '/':
8+
self.path = '/index.html'
9+
10+
try:
11+
file_path = self.path[1:]
12+
13+
with open(file_path, 'rb') as file:
14+
file_to_open = file.read()
15+
16+
mime_type, _ = mimetypes.guess_type(file_path)
17+
18+
self.send_response(200)
19+
if mime_type:
20+
self.send_header("Content-type", mime_type)
21+
self.end_headers()
22+
23+
self.wfile.write(file_to_open)
24+
25+
except FileNotFoundError:
26+
self.send_response(404)
27+
self.send_header("Content-type", "text/html")
28+
self.end_headers()
29+
self.wfile.write(bytes("File not found", 'utf-8'))
30+
31+
except Exception as e:
32+
self.send_response(500)
33+
self.send_header("Content-type", "text/html")
34+
self.end_headers()
35+
self.wfile.write(bytes(f"Internal server error: {str(e)}", 'utf-8'))
36+
37+
httpd = HTTPServer(('localhost', 65432), Serv)
38+
print("Server started at http://localhost:65432")
39+
httpd.serve_forever()

0 commit comments

Comments
 (0)