aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/my-mariadb.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2025-08-28 08:49:51 +1000
committerYuchen Pei <id@ypei.org>2025-08-28 08:49:51 +1000
commit124a2a6eaa2a8d96405168693f9c8e8afc51b10a (patch)
tree3cdfc91d93c5aec48acf6a0a31d4dc9fe30013a9 /emacs/.emacs.d/lisp/my/my-mariadb.el
parent4ec9311b65f343ceb9efd6709908a6e5ee44b6d7 (diff)
[emacs] misc fixes
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-mariadb.el')
-rw-r--r--emacs/.emacs.d/lisp/my/my-mariadb.el66
1 files changed, 58 insertions, 8 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-mariadb.el b/emacs/.emacs.d/lisp/my/my-mariadb.el
index d6c2463..1759af2 100644
--- a/emacs/.emacs.d/lisp/my/my-mariadb.el
+++ b/emacs/.emacs.d/lisp/my/my-mariadb.el
@@ -65,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"))))
@@ -291,11 +291,24 @@ switches to the buffer."
(my-save-text-and-switch-to-buffer source file-name)))
(defvar my-mtr-compilation-error-re
- '(mtr "^mysqltest: At line \\([0-9]+\\)" nil 1))
+ '(mtr "^\\([^ ]+\\) +\\(w[0-9]+ \\)?\\[ fail \\]"
+ my-mtr-compilation-error-filename))
-;; (defun my-mtr-find-test-file (test-name &optional dir)
-;; (unless dir (setq dir default-directory))
-;; ())
+(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
@@ -306,11 +319,11 @@ switches to the buffer."
(test-name
(progn
(when (string-match
- "^.*/mysql-test/\\(.+?\\)/\\(t/\\)?\\([^/]+\\)\\.test$"
+ "^.*/mysql-test/\\(suite/\\)?\\(.+?\\)/\\(t/\\)?\\([^/]+\\)\\.test$"
buffer-file-name)
(format "%s.%s"
- (match-string 1 buffer-file-name)
- (match-string 3 buffer-file-name))))))
+ (match-string 2 buffer-file-name)
+ (match-string 4 buffer-file-name))))))
(setq-local
compile-command
(format "%s %s %s %s"
@@ -319,5 +332,42 @@ switches to the buffer."
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