Skip to content

Commit 83a2614

Browse files
committed
2.20.11.27 修复 mtls-auto-fill 除 0 bug .
1 parent 706cc16 commit 83a2614

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

bin/mtls-auto-fill

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor
1919

2020
name = os.path.basename(__file__)
2121

22-
InsertStat = namedtuple('InsertStat','start_at end_at tps cost_time')
22+
InsertStat = namedtuple('InsertStat','start_at end_at rows cost_time')
2323

2424
def parser_cmd_args():
2525
"""
@@ -74,28 +74,31 @@ def insert(host="127.0.0.1",port=3306,user="apuser",password="mtls@0352",databas
7474
end_at = datetime.now()
7575

7676
# 微秒级的精度
77-
cost_time = (end_at - start_at).microseconds
78-
tps = (rows/cost_time) * 1000000
79-
stat = InsertStat(start_at=start_at,end_at=end_at,tps=tps,cost_time=cost_time/1000000)
77+
cost_time = (end_at - start_at).total_seconds()
78+
stat = InsertStat(start_at=start_at,end_at=end_at,rows=rows,cost_time=cost_time)
8079
return stat
8180

8281
def create_report(stats:InsertStat=None):
8382
"""
8483
"""
8584
assert stats is not None
86-
sum_tps = 0
85+
sum_rows = 0
8786
sum_cost_time = 0
8887
for s in stats:
89-
if hasattr(s,'tps'):
90-
sum_tps = sum_tps + s.tps
88+
if hasattr(s,'rows'):
89+
sum_rows = sum_rows + s.rows
9190
sum_cost_time = sum_cost_time + s.cost_time
9291

93-
tps = sum_tps / len(stats)
94-
cost_time = sum_cost_time / len(stats)
92+
avg_cost_time = sum_cost_time / len(stats)
93+
94+
if avg_cost_time == 0:
95+
# 后面 avg_cost_time 要做为分母,所以当这个值是 0 的时候把它设置为 1
96+
avg_cost_time = 1
97+
tps = sum_rows / avg_cost_time
9598

9699
print("-"*36)
97100
print(f"|tps = {tps}")
98-
print(f"|cost_time = {cost_time}")
101+
print(f"|cost_time = {avg_cost_time}")
99102
print("-"*36)
100103

101104

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
scripts = olds_scripts + news_scripts
1313

1414
setup(name='mysqltools-python',
15-
version='2.20.11.20',
15+
version='2.20.11.27',
1616
scripts=scripts,
1717
packages=['mtls', 'mtls.kits'],
1818
maintainer='Neeky',

0 commit comments

Comments
 (0)