Skip to content

Commit 2cf410f

Browse files
committed
Print response time for page requests in server mode
Log status, path, and duration for page requests only (not assets or status polls). Example: 200 /RDoc.html (12.3ms)
1 parent 840399d commit 2cf410f

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

lib/rdoc/server.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ def shutdown
109109

110110
private
111111

112+
def measure
113+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
114+
yield
115+
((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round(1)
116+
end
117+
112118
def create_generator
113119
gen = RDoc::Generator::Aliki.new(@store, @options)
114120
gen.file_output = false
@@ -145,7 +151,14 @@ def handle_client(client)
145151
return write_response(client, 405, 'text/plain', 'Method Not Allowed')
146152
end
147153

148-
status, content_type, body = route(path)
154+
if path.start_with?('/__') || path.match?(%r{\A/(?:css|js)/})
155+
status, content_type, body = route(path)
156+
else
157+
duration_ms = measure do
158+
status, content_type, body = route(path)
159+
end
160+
$stderr.puts "#{status} #{path} (#{duration_ms}ms)"
161+
end
149162
write_response(client, status, content_type, body)
150163
rescue => e
151164
write_response(client, 500, 'text/html', <<~HTML)

0 commit comments

Comments
 (0)