mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* Remove pruningPointUTXOSetStaging and implement UpdatePruningPointUTXOSet. * Implement StageStartSavingNewPruningPointUTXOSet, HadStartedSavingNewPruningPointUTXOSet, and FinishSavingNewPruningPointUTXOSet. * Fix a bad return. * Implement UpdatePruningPointUTXOSetIfRequired. * Call UpdatePruningPointUTXOSetIfRequired on consensus creation. * Rename savingNewPruningPointUTXOSetKey to updatingPruningPointUTXOSet. * Add a log. * Add calls to runtime.GC() at its start and end. * Rename a variable. * Replace calls to runtime.GC to calls to LogMemoryStats. * Wrap the contents of LogMemoryStats in a log closure.
30 lines
869 B
Go
30 lines
869 B
Go
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"time"
|
|
)
|
|
|
|
// LogAndMeasureExecutionTime logs that `functionName` has
|
|
// started. The user is expected to defer `onEnd`, which
|
|
// will then log that the function has ended, as well as
|
|
// the time duration the function had ran.
|
|
func LogAndMeasureExecutionTime(log *Logger, functionName string) (onEnd func()) {
|
|
start := time.Now()
|
|
log.Debugf("%s start", functionName)
|
|
return func() {
|
|
log.Debugf("%s end. Took: %s", functionName, time.Since(start))
|
|
}
|
|
}
|
|
|
|
// LogMemoryStats logs memory stats for `functionName`
|
|
func LogMemoryStats(log *Logger, functionName string) {
|
|
log.Debug(NewLogClosure(func() string {
|
|
stats := runtime.MemStats{}
|
|
runtime.ReadMemStats(&stats)
|
|
return fmt.Sprintf("%s: used memory: %d bytes, total: %d bytes", functionName,
|
|
stats.Alloc, stats.HeapIdle-stats.HeapReleased+stats.HeapInuse)
|
|
}))
|
|
}
|