gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/benchmarks/tools/sysbench_test.go (about) 1 // Copyright 2020 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tools 16 17 import ( 18 "testing" 19 ) 20 21 // TestSysbenchCpu tests parses on sample 'sysbench cpu' output. 22 func TestSysbenchCpu(t *testing.T) { 23 sampleData := ` 24 sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3) 25 26 Running the test with following options: 27 Number of threads: 8 28 Initializing random number generator from current time 29 30 31 Prime numbers limit: 10000 32 33 Initializing worker threads... 34 35 Threads started! 36 37 CPU speed: 38 events per second: 9093.38 39 40 General statistics: 41 total time: 10.0007s 42 total number of events: 90949 43 44 Latency (ms): 45 min: 0.64 46 avg: 0.88 47 max: 24.65 48 95th percentile: 1.55 49 sum: 79936.91 50 51 Threads fairness: 52 events (avg/stddev): 11368.6250/831.38 53 execution time (avg/stddev): 9.9921/0.01 54 ` 55 sysbench := SysbenchCPU{} 56 want := 9093.38 57 if got, err := sysbench.parseEvents(sampleData); err != nil { 58 t.Fatalf("parse cpu events failed: %v", err) 59 } else if want != got { 60 t.Fatalf("got: %f want: %f", got, want) 61 } 62 } 63 64 // TestSysbenchMemory tests parsers on sample 'sysbench memory' output. 65 func TestSysbenchMemory(t *testing.T) { 66 sampleData := ` 67 sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3) 68 69 Running the test with following options: 70 Number of threads: 8 71 Initializing random number generator from current time 72 73 74 Running memory speed test with the following options: 75 block size: 1KiB 76 total size: 102400MiB 77 operation: write 78 scope: global 79 80 Initializing worker threads... 81 82 Threads started! 83 84 Total operations: 47999046 (9597428.64 per second) 85 86 46874.07 MiB transferred (9372.49 MiB/sec) 87 88 89 General statistics: 90 total time: 5.0001s 91 total number of events: 47999046 92 93 Latency (ms): 94 min: 0.00 95 avg: 0.00 96 max: 0.21 97 95th percentile: 0.00 98 sum: 33165.91 99 100 Threads fairness: 101 events (avg/stddev): 5999880.7500/111242.52 102 execution time (avg/stddev): 4.1457/0.09 103 ` 104 sysbench := SysbenchMemory{} 105 want := 9597428.64 106 if got, err := sysbench.parseOperations(sampleData); err != nil { 107 t.Fatalf("parse memory ops failed: %v", err) 108 } else if want != got { 109 t.Fatalf("got: %f want: %f", got, want) 110 } 111 } 112 113 // TestSysbenchMutex tests parsers on sample 'sysbench mutex' output. 114 func TestSysbenchMutex(t *testing.T) { 115 sampleData := ` 116 sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3) 117 118 The 'mutex' test requires a command argument. See 'sysbench mutex help' 119 root@ec078132e294:/# sysbench mutex --threads=8 run 120 sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3) 121 122 Running the test with following options: 123 Number of threads: 8 124 Initializing random number generator from current time 125 126 127 Initializing worker threads... 128 129 Threads started! 130 131 132 General statistics: 133 total time: 0.2320s 134 total number of events: 8 135 136 Latency (ms): 137 min: 152.35 138 avg: 192.48 139 max: 231.41 140 95th percentile: 231.53 141 sum: 1539.83 142 143 Threads fairness: 144 events (avg/stddev): 1.0000/0.00 145 execution time (avg/stddev): 0.1925/0.04 146 ` 147 148 sysbench := SysbenchMutex{} 149 want := .1925 150 if got, err := sysbench.parseExecutionTime(sampleData); err != nil { 151 t.Fatalf("parse mutex time failed: %v", err) 152 } else if want != got { 153 t.Fatalf("got: %f want: %f", got, want) 154 } 155 156 want = 0.04 157 if got, err := sysbench.parseDeviation(sampleData); err != nil { 158 t.Fatalf("parse mutex deviation failed: %v", err) 159 } else if want != got { 160 t.Fatalf("got: %f want: %f", got, want) 161 } 162 163 want = 192.48 164 if got, err := sysbench.parseLatency(sampleData); err != nil { 165 t.Fatalf("parse mutex time failed: %v", err) 166 } else if want != got { 167 t.Fatalf("got: %f want: %f", got, want) 168 } 169 }