vitess.io/vitess@v0.16.2/go/test/stress/results.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package stress 18 19 type ( 20 queryCount struct { 21 success int 22 failure int 23 meaningfulFailure int 24 } 25 26 // result holds the result for a stress test. 27 result struct { 28 selects, inserts, deletes queryCount 29 } 30 ) 31 32 func (qc queryCount) successQPS(seconds float64) int { 33 if seconds <= 0 { 34 return 0 35 } 36 return int(float64(qc.success) / seconds) 37 } 38 39 func (qc queryCount) failureQPS(seconds float64) int { 40 if seconds <= 0 { 41 return 0 42 } 43 return int(float64(qc.failure) / seconds) 44 } 45 46 func (qc queryCount) meaningfulFailureQPS(seconds float64) int { 47 if seconds <= 0 { 48 return 0 49 } 50 return int(float64(qc.meaningfulFailure) / seconds) 51 } 52 53 func (qc queryCount) totalQPS(seconds float64) int { 54 return qc.successQPS(seconds) + qc.failureQPS(seconds) 55 } 56 57 func (qc queryCount) sum() int { 58 return qc.success + qc.failure 59 } 60 61 func sumQueryCounts(qcs ...queryCount) queryCount { 62 var qc queryCount 63 for _, qci := range qcs { 64 qc.success += qci.success 65 qc.failure += qci.failure 66 qc.meaningfulFailure += qci.meaningfulFailure 67 } 68 return qc 69 } 70 71 func (r result) assert() bool { 72 return r.selects.meaningfulFailure == 0 && r.deletes.meaningfulFailure == 0 && r.inserts.meaningfulFailure == 0 73 } 74 75 // print renders the results held by result. 76 func (r result) print(log func(format string, args ...any), seconds float64) { 77 allQCs := sumQueryCounts(r.selects, r.inserts, r.deletes) 78 log(`QPS: 79 select: %d | failed: %d (including %d meaningful failures) | sum: %d 80 insert: %d | failed: %d (including %d meaningful failures) | sum: %d 81 delete: %d | failed: %d (including %d meaningful failures) | sum: %d 82 --------- 83 total: %d | failed: %d (including %d meaningful failures) | sum: %d 84 85 Queries: 86 select: %d | failed: %d (including %d meaningful failures) | sum: %d 87 insert: %d | failed: %d (including %d meaningful failures) | sum: %d 88 delete: %d | failed: %d (including %d meaningful failures) | sum: %d 89 --------- 90 total: %d | failed: %d (including %d meaningful failures) | sum: %d 91 92 `, r.selects.successQPS(seconds), r.selects.failureQPS(seconds), r.selects.meaningfulFailureQPS(seconds), r.selects.totalQPS(seconds), 93 r.inserts.successQPS(seconds), r.inserts.failureQPS(seconds), r.inserts.meaningfulFailureQPS(seconds), r.inserts.totalQPS(seconds), 94 r.deletes.successQPS(seconds), r.deletes.failureQPS(seconds), r.deletes.meaningfulFailureQPS(seconds), r.deletes.totalQPS(seconds), 95 allQCs.successQPS(seconds), allQCs.failureQPS(seconds), allQCs.meaningfulFailureQPS(seconds), allQCs.totalQPS(seconds), 96 r.selects.success, r.selects.failure, r.selects.meaningfulFailure, r.selects.sum(), 97 r.inserts.success, r.inserts.failure, r.inserts.meaningfulFailure, r.inserts.sum(), 98 r.deletes.success, r.deletes.failure, r.deletes.meaningfulFailure, r.deletes.sum(), 99 allQCs.success, allQCs.failure, allQCs.meaningfulFailure, allQCs.sum()) 100 }