-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elnode-tools.el
103 lines (86 loc) · 3.19 KB
/
elnode-tools.el
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
;;; elnode-tools.el --- dev tools for elnode -*- lexical-binding: t -*-
;; Copyright (C) 2014 Nic Ferrier
;; Author: Nic Ferrier <[email protected]>
;; Keywords: lisp
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; 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, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Just some tools to help debug and improve elnode
;;; Code:
(require 'elp)
(require 'elnode)
(require 'dash)
(require 'profiler)
(require 'cl-macs)
(defun process-sentinel-set (proc func)
(set-process-sentinel proc func)
proc)
(defvar elnode-elp-do-profiler nil)
(defun elnode-elp-handler (httpcon)
(let ((elnode-webserver-visit-file t))
(elnode-docroot-for "~/sources/emacs/etc/"
:with file
:on httpcon
:do (elnode-send-file httpcon file))))
(defun elnode-elp (&optional port)
(interactive
(list
(when current-prefix-arg
(string-to-number
(read-from-minibuffer "port to hit: ")))))
(let ((sock (or port 8001))
(elnode--do-error-logging :status))
(unless (kva sock elnode-server-socket)
(elnode-start 'elnode-elp-handler :port 8001))
(let ((elnode--do-error-logging :warning))
(when elnode-elp-do-profiler
(profiler-stop)
(profiler-start 'cpu))
(elp-reset-all)
(elp-instrument-package "elnode")
(elp-instrument-package "kv")
(elp-instrument-package "process")
(elp-instrument-package "set-process")
(let (fin)
(switch-to-buffer
(process-buffer
(process-sentinel-set
(start-process-shell-command
"elnode-ab" "elnode-ab"
(format
(concat
"ab -r -n 4000 -c 200 -s 20 "
"http://127.0.0.1:%s/COPYING "
" > /tmp/elnode-elp-101.txt") sock))
(lambda (proc status) (setq fin t)))))
(while (not fin) (sleep-for 20))
(when elnode-elp-do-profiler
(profiler-report)
(profiler-stop))
(when (get-buffer "elnode-elp-101.txt")
(with-current-buffer (get-buffer "elnode-elp-101.txt")
(set-buffer-modified-p nil)))
(find-file "/tmp/elnode-elp-101.txt")
(elp-results)
(elp-reset-all)))))
(defun elnode-check-request-buffers ()
(interactive)
(noflet ((request-buffers ()
(->> (buffer-list)
(-filter
(lambda (b) (string-match " \\*elnode.*" (buffer-name b)))))))
(let ((before (request-buffers)))
(-each (request-buffers) (lambda (b) (kill-buffer b)))
(message "request buffers: %d > %d"
(length before)
(length (request-buffers))))))
(provide 'elnode-tools)
;;; elnode-tools.el ends here