github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/db/stats.go (about) 1 // Copyright 2022 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 db 16 17 import ( 18 "encoding/json" 19 20 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/wal" 21 ) 22 23 type Stats struct { 24 db *DB 25 26 // TODO: Checkpoint Stats 27 28 WalStats *WalStats 29 } 30 31 func NewStats(db *DB) *Stats { 32 return &Stats{ 33 db: db, 34 } 35 } 36 37 func (stats *Stats) Collect() { 38 stats.WalStats = CollectWalStats(stats.db.Wal) 39 } 40 41 func (stats *Stats) ToString(prefix string) string { 42 buf, err := json.MarshalIndent(stats, prefix, " ") 43 if err != nil { 44 panic(err) 45 } 46 return string(buf) 47 } 48 49 type WalStats struct { 50 MaxLSN uint64 51 MaxCkped uint64 52 PendingCnt uint64 53 } 54 55 func CollectWalStats(w wal.Driver) *WalStats { 56 return &WalStats{ 57 MaxLSN: w.GetCurrSeqNum(), 58 MaxCkped: w.GetCheckpointed(), 59 PendingCnt: w.GetPenddingCnt(), 60 } 61 }