/
stats.go
53 lines (43 loc) · 1.35 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2018 The VeChainThor developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package node
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/miniBamboo/workshare/block"
"github.com/miniBamboo/workshare/workshare"
)
type blockStats struct {
exec, commit, real mclock.AbsTime
txs int
usedGas uint64
processed, queued, ignored int
}
func (s *blockStats) UpdateProcessed(n int, txs int, exec, commit, real mclock.AbsTime, usedGas uint64) {
s.processed += n
s.txs += txs
s.exec += exec
s.commit += commit
s.real += real
s.usedGas += usedGas
}
func (s *blockStats) UpdateIgnored(n int) {
s.ignored += n
}
func (s *blockStats) UpdateQueued(n int) {
s.queued += n
}
func (s *blockStats) LogContext(last *block.Header) []interface{} {
return []interface{}{
"txs", s.txs,
"mgas", float64(s.usedGas) / 1000 / 1000,
"et", fmt.Sprintf("%v|%v", common.PrettyDuration(s.exec), common.PrettyDuration(s.commit)),
"mgas/s", float64(s.usedGas) * 1000 / float64(s.real),
"id", shortID(last.ID()),
}
}
func shortID(id workshare.Bytes32) string {
return fmt.Sprintf("[#%v…%x]", block.Number(id), id[28:])
}