This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
138 lines (110 loc) · 3.13 KB
/
Makefile
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
export GO111MODULE=on
DB_HOST:=127.0.0.1
DB_PORT:=3306
DB_USER:=isucari
DB_PASS:=isucari
DB_NAME:=isucari
MYSQL_CMD:=mysql -h$(DB_HOST) -P$(DB_PORT) -u$(DB_USER) -p$(DB_PASS) $(DB_NAME)
NGX_LOG:=/tmp/access.log
MYSQL_LOG:=/tmp/slow-query.log
KATARU_CFG:=./kataribe.toml
SLACKCAT:=slackcat --tee --channel general
SLACKRAW:=slackcat --channel general
PPROF:=go tool pprof -png -output pprof.png http://localhost:6060/debug/pprof/profile
PROJECT_ROOT:=/home/isucon/isucari
BUILD_DIR:=/home/isucon/isucari/webapp/go
BIN_NAME:=isucari
CA:=-o /dev/null -s -w "%{http_code}\n"
all: build
.PHONY: clean
clean:
cd $(BUILD_DIR); \
rm -rf torb
deps:
cd $(BUILD_DIR); \
go mod download
.PHONY: build
build:
cd $(BUILD_DIR); \
go build -o $(BIN_NAME)
#TODO
.PHONY: restart
restart:
sudo systemctl restart isucari.golang.service
.PHONY: test
test:
curl localhost $(CA)
# ここから元から作ってるやつ
.PHONY: dev
dev: build
cd $(BUILD_DIR); \
./$(BIN_NAME)
.PHONY: bench-dev
bench-dev: commit before slow-on dev
.PHONY: bench
bench: commit before build restart log
.PHONY: log
log:
sudo journalctl -u isucari.golang -n10 -f
.PHONY: maji
bench: commit before build restart
.PHONY: anal
anal: slow kataru
.PHONY: push
push:
git push
.PHONY: commit
commit:
cd $(PROJECT_ROOT); \
git add .; \
git commit --allow-empty -m "bench"
.PHONY: before
before:
$(eval when := $(shell date "+%s"))
mkdir -p ~/logs/$(when)
@if [ -f $(NGX_LOG) ]; then \
sudo mv -f $(NGX_LOG) ~/logs/$(when)/ ; \
fi
# @if [ -f $(MYSQL_LOG) ]; then \
# sudo mv -f $(MYSQL_LOG) ~/logs/$(when)/ ; \
# fi
sudo systemctl restart nginx
# sudo systemctl restart mysql
.PHONY: slow
slow:
sudo pt-query-digest $(MYSQL_LOG) | $(SLACKCAT)
.PHONY: kataru
kataru:
sudo cat $(NGX_LOG) | kataribe -f ./kataribe.toml | $(SLACKCAT)
.PHONY: pprof
pprof:
$(PPROF)
$(SLACKRAW) -n pprof.png ./pprof.png
.PHONY: slow-on
slow-on:
sudo mysql -e "set global slow_query_log_file = '$(MYSQL_LOG)'; set global long_query_time = 0; set global slow_query_log = ON;"
# sudo $(MYSQL_CMD) -e "set global slow_query_log_file = '$(MYSQL_LOG)'; set global long_query_time = 0; set global slow_query_log = ON;"
.PHONY: slow-off
slow-off:
sudo mysql -e "set global slow_query_log = OFF;"
# sudo $(MYSQL_CMD) -e "set global slow_query_log = OFF;"
.PHONY: setup
setup:
sudo apt install -y percona-toolkit dstat git unzip snapd
git config --global user.email "[email protected]"
git config --global user.name "tohutohu"
wget https://github.com/matsuu/kataribe/releases/download/v0.4.1/kataribe-v0.4.1_linux_amd64.zip -O kataribe.zip
unzip -o kataribe.zip
sudo mv kataribe /usr/local/bin/
sudo chmod +x /usr/local/bin/kataribe
rm kataribe.zip
kataribe -generate
wget https://github.com/KLab/myprofiler/releases/download/0.2/myprofiler.linux_amd64.tar.gz
tar xf myprofiler.linux_amd64.tar.gz
rm myprofiler.linux_amd64.tar.gz
sudo mv myprofiler /usr/local/bin/
sudo chmod +x /usr/local/bin/myprofiler
wget https://github.com/bcicen/slackcat/releases/download/v1.5/slackcat-1.5-linux-amd64 -O slackcat
sudo mv slackcat /usr/local/bin/
sudo chmod +x /usr/local/bin/slackcat
slackcat --configure