github.com/matrixorigin/matrixone@v1.2.0/pkg/perfcounter/counter_set.go (about) 1 // Copyright 2023 Matrix Origin 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 perfcounter 16 17 import ( 18 "fmt" 19 "reflect" 20 21 "github.com/matrixorigin/matrixone/pkg/util/metric/stats" 22 ) 23 24 type CounterSet struct { 25 FileService FileServiceCounterSet 26 DistTAE DistTAECounterSet 27 TAE TAECounterSet 28 } 29 30 type FileServiceCounterSet struct { 31 S3 struct { 32 List stats.Counter 33 Head stats.Counter 34 Put stats.Counter 35 Get stats.Counter 36 Delete stats.Counter 37 DeleteMulti stats.Counter 38 } 39 40 Cache struct { 41 Read stats.Counter 42 Hit stats.Counter 43 Memory struct { 44 Read stats.Counter 45 Hit stats.Counter 46 Capacity stats.Counter 47 Used stats.Counter 48 Available stats.Counter 49 } 50 Disk struct { 51 Read stats.Counter 52 Hit stats.Counter 53 GetFileContent stats.Counter 54 SetFileContent stats.Counter 55 OpenIOEntryFile stats.Counter 56 OpenFullFile stats.Counter 57 CreateFile stats.Counter 58 StatFile stats.Counter 59 WriteFile stats.Counter 60 Error stats.Counter 61 Evict stats.Counter 62 EvictPending stats.Counter 63 EvictImmediately stats.Counter 64 } 65 Remote struct { 66 Read stats.Counter 67 Hit stats.Counter 68 } 69 LRU struct { 70 Evict stats.Counter 71 EvictWithZeroRead stats.Counter 72 } 73 } 74 75 FileWithChecksum struct { 76 Read stats.Counter 77 Write stats.Counter 78 UnderlyingRead stats.Counter 79 UnderlyingWrite stats.Counter 80 } 81 } 82 83 type DistTAECounterSet struct { 84 Logtail struct { 85 Entries stats.Counter 86 InsertEntries stats.Counter 87 MetadataInsertEntries stats.Counter 88 DeleteEntries stats.Counter 89 MetadataDeleteEntries stats.Counter 90 91 InsertRows stats.Counter 92 DeleteRows stats.Counter 93 ActiveRows stats.Counter 94 InsertBlocks stats.Counter 95 } 96 } 97 98 type TAECounterSet struct { 99 LogTail struct { 100 Entries stats.Counter 101 InsertEntries stats.Counter 102 DeleteEntries stats.Counter 103 } 104 105 CheckPoint struct { 106 DoGlobalCheckPoint stats.Counter 107 DoIncrementalCheckpoint stats.Counter 108 DeleteGlobalEntry stats.Counter 109 DeleteIncrementalEntry stats.Counter 110 } 111 112 Object struct { 113 Create stats.Counter 114 CreateNonAppendable stats.Counter 115 SoftDelete stats.Counter 116 MergeBlocks stats.Counter 117 CompactBlock stats.Counter 118 } 119 120 Block struct { 121 Create stats.Counter 122 CreateNonAppendable stats.Counter 123 SoftDelete stats.Counter 124 Flush stats.Counter 125 } 126 } 127 128 var statsCounterType = reflect.TypeOf((*stats.Counter)(nil)).Elem() 129 130 type IterFieldsFunc func(path []string, counter *stats.Counter) error 131 132 func (c *CounterSet) IterFields(fn IterFieldsFunc) error { 133 return iterFields( 134 reflect.ValueOf(c), 135 []string{}, 136 fn, 137 ) 138 } 139 140 func iterFields(v reflect.Value, path []string, fn IterFieldsFunc) error { 141 142 if v.Type() == statsCounterType { 143 return fn(path, v.Addr().Interface().(*stats.Counter)) 144 } 145 146 t := v.Type() 147 148 switch t.Kind() { 149 150 case reflect.Pointer: 151 iterFields(v.Elem(), path, fn) 152 153 case reflect.Struct: 154 for i := 0; i < t.NumField(); i++ { 155 field := t.Field(i) 156 if err := iterFields(v.Field(i), append(path, field.Name), fn); err != nil { 157 return err 158 } 159 } 160 161 case reflect.Map: 162 if t.Key().Kind() != reflect.String { 163 panic(fmt.Sprintf("unknown type: %v", v.Type())) 164 } 165 iter := v.MapRange() 166 for iter.Next() { 167 if err := iterFields(iter.Value(), append(path, iter.Key().String()), fn); err != nil { 168 return err 169 } 170 } 171 172 default: 173 panic(fmt.Sprintf("unknown type: %v", v.Type())) 174 } 175 176 return nil 177 }