mirror of
https://github.com/datarhei/core.git
synced 2025-11-02 20:24:02 +08:00
Expose resource usage in report history
This commit is contained in:
@@ -570,9 +570,20 @@ func (p *parser) parseAVstreamProgress(line string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *parser) Stop(state string) {
|
||||
func (p *parser) Stop(state string, pusage process.Usage) {
|
||||
fmt.Printf("%+v\n", pusage)
|
||||
usage := Usage{}
|
||||
|
||||
usage.CPU.Average = pusage.CPU.Average
|
||||
usage.CPU.Max = pusage.CPU.Max
|
||||
usage.CPU.Limit = pusage.CPU.Limit
|
||||
|
||||
usage.Memory.Average = pusage.Memory.Average
|
||||
usage.Memory.Max = pusage.Memory.Max
|
||||
usage.Memory.Limit = pusage.Memory.Limit
|
||||
|
||||
// The process stopped. The right moment to store the current state to the log history
|
||||
p.storeReportHistory(state)
|
||||
p.storeReportHistory(state, usage)
|
||||
}
|
||||
|
||||
func (p *parser) Progress() Progress {
|
||||
@@ -806,6 +817,7 @@ type ReportHistoryEntry struct {
|
||||
ExitedAt time.Time
|
||||
ExitState string
|
||||
Progress Progress
|
||||
Usage Usage
|
||||
}
|
||||
|
||||
type ReportHistorySearchResult struct {
|
||||
@@ -850,7 +862,7 @@ func (p *parser) SearchReportHistory(state string, from, to *time.Time) []Report
|
||||
return result
|
||||
}
|
||||
|
||||
func (p *parser) storeReportHistory(state string) {
|
||||
func (p *parser) storeReportHistory(state string, usage Usage) {
|
||||
if p.logHistory == nil {
|
||||
return
|
||||
}
|
||||
@@ -868,6 +880,7 @@ func (p *parser) storeReportHistory(state string) {
|
||||
ExitedAt: time.Now(),
|
||||
ExitState: state,
|
||||
Progress: p.Progress(),
|
||||
Usage: usage,
|
||||
}
|
||||
|
||||
p.logHistory.Value = h
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/datarhei/core/v16/process"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -165,7 +166,7 @@ func TestParserLogHistory(t *testing.T) {
|
||||
history := parser.ReportHistory()
|
||||
require.Equal(t, 0, len(history))
|
||||
|
||||
parser.Stop("finished")
|
||||
parser.Stop("finished", process.Usage{})
|
||||
|
||||
history = parser.ReportHistory()
|
||||
require.Equal(t, 1, len(history))
|
||||
@@ -203,7 +204,7 @@ func TestParserLogHistoryLength(t *testing.T) {
|
||||
parser.prelude.done = true
|
||||
parser.Parse("frame= 5968 fps= 25 q=19.4 size=443kB time=00:03:58.44 bitrate=5632kbits/s speed=0.999x skip=9733 drop=3522 dup=87463")
|
||||
|
||||
parser.Stop("finished")
|
||||
parser.Stop("finished", process.Usage{})
|
||||
}
|
||||
|
||||
history = parser.ReportHistory()
|
||||
@@ -226,7 +227,7 @@ func TestParserLogMinimalHistoryLength(t *testing.T) {
|
||||
parser.prelude.done = true
|
||||
parser.Parse("frame= 5968 fps= 25 q=19.4 size=443kB time=00:03:58.44 bitrate=5632kbits/s speed=0.999x skip=9733 drop=3522 dup=87463")
|
||||
|
||||
parser.Stop("finished")
|
||||
parser.Stop("finished", process.Usage{})
|
||||
}
|
||||
|
||||
history = parser.ReportHistory()
|
||||
@@ -257,7 +258,7 @@ func TestParserLogMinimalHistoryLengthWithoutFullHistory(t *testing.T) {
|
||||
parser.prelude.done = true
|
||||
parser.Parse("frame= 5968 fps= 25 q=19.4 size=443kB time=00:03:58.44 bitrate=5632kbits/s speed=0.999x skip=9733 drop=3522 dup=87463")
|
||||
|
||||
parser.Stop("finished")
|
||||
parser.Stop("finished", process.Usage{})
|
||||
}
|
||||
|
||||
history = parser.ReportHistory()
|
||||
@@ -279,7 +280,7 @@ func TestParserLogHistorySearch(t *testing.T) {
|
||||
parser.prelude.done = true
|
||||
parser.Parse("frame= 5968 fps= 25 q=19.4 size=443kB time=00:03:58.44 bitrate=5632kbits/s speed=0.999x skip=9733 drop=3522 dup=87463")
|
||||
|
||||
parser.Stop("finished")
|
||||
parser.Stop("finished", process.Usage{})
|
||||
|
||||
parser.ResetStats()
|
||||
|
||||
@@ -292,7 +293,7 @@ func TestParserLogHistorySearch(t *testing.T) {
|
||||
parser.prelude.done = true
|
||||
parser.Parse("frame= 5968 fps= 25 q=19.4 size=443kB time=00:03:58.44 bitrate=5632kbits/s speed=0.999x skip=9733 drop=3522 dup=87463")
|
||||
|
||||
parser.Stop("finished")
|
||||
parser.Stop("finished", process.Usage{})
|
||||
|
||||
parser.ResetStats()
|
||||
|
||||
@@ -305,7 +306,7 @@ func TestParserLogHistorySearch(t *testing.T) {
|
||||
parser.prelude.done = true
|
||||
parser.Parse("frame= 5968 fps= 25 q=19.4 size=443kB time=00:03:58.44 bitrate=5632kbits/s speed=0.999x skip=9733 drop=3522 dup=87463")
|
||||
|
||||
parser.Stop("failed")
|
||||
parser.Stop("failed", process.Usage{})
|
||||
|
||||
res := parser.SearchReportHistory("", nil, nil)
|
||||
require.Equal(t, 3, len(res))
|
||||
@@ -905,7 +906,7 @@ func TestParserPatterns(t *testing.T) {
|
||||
pp, ok := p.(*parser)
|
||||
require.True(t, ok)
|
||||
|
||||
pp.storeReportHistory("something")
|
||||
pp.storeReportHistory("something", Usage{})
|
||||
|
||||
report := p.ReportHistory()
|
||||
require.Equal(t, 1, len(report))
|
||||
|
||||
@@ -321,3 +321,16 @@ type AVstream struct {
|
||||
Duplicating bool
|
||||
GOP string
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
CPU struct {
|
||||
Average float64
|
||||
Max float64
|
||||
Limit float64
|
||||
}
|
||||
Memory struct {
|
||||
Average float64
|
||||
Max uint64
|
||||
Limit uint64
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user