aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/my-mariadb.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-mariadb.el')
-rw-r--r--emacs/.emacs.d/lisp/my/my-mariadb.el103
1 files changed, 101 insertions, 2 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-mariadb.el b/emacs/.emacs.d/lisp/my/my-mariadb.el
index 6b0e06b..1759af2 100644
--- a/emacs/.emacs.d/lisp/my/my-mariadb.el
+++ b/emacs/.emacs.d/lisp/my/my-mariadb.el
@@ -33,7 +33,9 @@
(interactive)
(if (equal (file-name-extension (buffer-file-name))
"test")
- (call-interactively 'project-compile)
+ (progn
+ (my-mtr-set-compile-command)
+ (call-interactively 'compile))
(sql-send-buffer)))
(defun my-gdb-maria ()
@@ -63,7 +65,7 @@
(replace-regexp-in-string
"/src"
"/build/mysql-test/var/log/mysqld.1.1.rr/latest-trace"
- ;; "/build/mysql-test/var/log/mysqld.2.2.rr/latest-trace"
+ ;; "/build/mysql-test/var/log/mysqld.2.1.rr/latest-trace"
(project-root (project-current t))))
(expand-file-name "~/bin/gdb-mi.sh"))))
@@ -251,6 +253,24 @@ enum spider_malloc_id {
nil t)
(tempel-insert 'ps)))
+(defun my-mariadb-kb-url-p (url)
+ (string-match-p "https://mariadb.com/kb/en/\\([^/]+\\)/" url))
+
+(defun my-wiki-mariadb-extract-kb-source ()
+ "Extract the kb source from the current buffer.
+
+Used for wiki mode as a post-processor."
+ (let ((source
+ (dom-text
+ (dom-by-id
+ (libxml-parse-html-region (point-min) (point-max))
+ "answer_source"))))
+ (erase-buffer)
+ (insert source))
+ (goto-char (point-min))
+ (save-buffer)
+ )
+
(defun my-mariadb-fetch-kb-source (url)
"Fetches the source to an maridb kb entry at URL.
@@ -270,5 +290,84 @@ switches to the buffer."
(file-name (format "/tmp/%s.wiki" term)))
(my-save-text-and-switch-to-buffer source file-name)))
+(defvar my-mtr-compilation-error-re
+ '(mtr "^\\([^ ]+\\) +\\(w[0-9]+ \\)?\\[ fail \\]"
+ my-mtr-compilation-error-filename))
+
+(defun my-mtr-compilation-error-filename ()
+ (save-excursion
+ (save-match-data
+ (my-mtr-find-test-file
+ (match-string 1)
+ (project-root (project-current))))))
+
+(defun my-mtr-find-test-file (test-name dir)
+ (pcase-let ((`(,suite ,base) (string-split test-name "\\.")))
+ (seq-find
+ (lambda (file)
+ (string-match-p (format "%s\\(/t\\)?/%s.test$" suite base) file))
+ (directory-files-recursively dir
+ (format "%s.test" base))))
+ )
+
+(defun my-mtr-set-compile-command ()
+ (when (and buffer-file-name
+ (equal "test" (file-name-extension buffer-file-name)))
+ (when-let*
+ ((source-dir (expand-file-name (project-root (project-current))))
+ (build-dir (replace-regexp-in-string "/src/$" "/build/" source-dir))
+ (test-name
+ (progn
+ (when (string-match
+ "^.*/mysql-test/\\(suite/\\)?\\(.+?\\)/\\(t/\\)?\\([^/]+\\)\\.test$"
+ buffer-file-name)
+ (format "%s.%s"
+ (match-string 2 buffer-file-name)
+ (match-string 4 buffer-file-name))))))
+ (setq-local
+ compile-command
+ (format "%s %s %s %s"
+ "taskset -c 0-3"
+ (file-name-concat build-dir "mysql-test/mtr")
+ test-name
+ "--rr")))))
+
+(defun my-mtr-remove-if-1 ()
+ "Remove if (1) blocks"
+ (interactive)
+ (while (re-search-forward
+ (rx bol (0+ space) "if" (0+ space) "(1)" (0+ space) eol)
+ nil t)
+ (kill-whole-line)
+ (my-delete-pair-dwim)))
+
+(defun my-mtr-remove-if-0 ()
+ "Remove if (0) blocks"
+ (interactive)
+ (while (re-search-forward
+ (rx bol (0+ space) "if" (0+ space) "(0)" (0+ space) eol)
+ nil t)
+ (kill-whole-line)
+ (kill-sexp)))
+
+(defun my-mtr-average ()
+ "Calculate average time of mtr --repeat output."
+ (interactive)
+ (let ((run (make-hash-table :test 'equal))
+ (name) (time))
+ (while (re-search-forward "^\\([^ ]+\\).*pass \\] +\\([0-9]+\\)$" nil t)
+ (setq name (match-string 1)
+ time (string-to-number (match-string 2)))
+ (puthash name (cons time (gethash name run)) run))
+ (with-temp-buffer
+ (maphash
+ (lambda (k v)
+ (insert k " " (format "%d" (/ (seq-reduce '+ v 0) (length v))) "\n"))
+ run)
+ (goto-char (point-min))
+ (sort-lines nil (point-min) (point-max))
+ (align-regexp (point-min) (point-max) "\\(\\s-*\\) ")
+ (message (buffer-string)))))
+
(provide 'my-mariadb)
;;; my-mariadb.el ends here