-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved support for small terminal windows (#108)
* cputimer improvements * bugfix: better support for small terminal windows * adaptive progress bar width (termite 0.0.16 -> 0.0.17)
- Loading branch information
Showing
12 changed files
with
494 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package api | ||
|
||
import "time" | ||
|
||
// ElapsedCPUTimeFn returns a pair of CPU time measurements, one for user time and one for system time. | ||
type ElapsedCPUTimeFn = func() (perceived time.Duration, user time.Duration, system time.Duration) | ||
|
||
// CPUTimer an abstraction for a platform system CPU timer | ||
type CPUTimer interface { | ||
Start() ElapsedCPUTimeFn | ||
Elapsed() (perceived time.Duration, usr time.Duration, sys time.Duration) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// +build linux darwin | ||
// +build amd64 arm64 | ||
|
||
package pkg | ||
|
||
import ( | ||
"os/exec" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewChildrenCPUTimer(t *testing.T) { | ||
timer := NewChildrenCPUTimer() | ||
|
||
assert.Equal(t, syscall.RUSAGE_CHILDREN, timer.(*unixChildrenCPUTimer).who) | ||
} | ||
|
||
func TestNewSelfCPUTimer(t *testing.T) { | ||
timer := NewSelfCPUTimer() | ||
|
||
assert.Equal(t, syscall.RUSAGE_SELF, timer.(*unixChildrenCPUTimer).who) | ||
} | ||
|
||
func Test_SelfCPUTimer_Elapsed_Unloaded(t *testing.T) { | ||
timer := NewSelfCPUTimer() | ||
|
||
elapsed := timer.Start() | ||
perceived, usr, sys := elapsed() | ||
|
||
assert.GreaterOrEqual(t, time.Millisecond*1, perceived) | ||
assert.GreaterOrEqual(t, time.Millisecond*1, usr) | ||
assert.GreaterOrEqual(t, time.Millisecond*1, sys) | ||
} | ||
|
||
func Test_SelfCPUTimer_Elapsed_Loaded(t *testing.T) { | ||
timer := NewSelfCPUTimer() | ||
|
||
elapsed := timer.Start() | ||
|
||
assert.Eventually(t, | ||
func() bool { | ||
perceived, usr, sys := elapsed() | ||
|
||
return perceived > time.Nanosecond*1 && usr > time.Nanosecond*1 && sys > time.Nanosecond*1 | ||
}, | ||
time.Second*1, | ||
time.Nanosecond*1, | ||
) | ||
} | ||
|
||
func Test_ChildrenCPUTimer_Elapsed_Loaded(t *testing.T) { | ||
timer := NewChildrenCPUTimer() | ||
|
||
elapsed := timer.Start() | ||
exec.Command("go", "env").Run() | ||
perceived, usr, sys := elapsed() | ||
|
||
assert.GreaterOrEqual(t, perceived, time.Nanosecond*1) | ||
assert.GreaterOrEqual(t, usr, time.Nanosecond*1) | ||
assert.GreaterOrEqual(t, sys, time.Nanosecond*1) | ||
} | ||
|
||
func Test_ChildrenCPUTimer_Elapsed_Unloaded(t *testing.T) { | ||
timer := NewChildrenCPUTimer() | ||
|
||
elapsed := timer.Start() | ||
perceived, usr, sys := elapsed() | ||
|
||
assert.GreaterOrEqual(t, perceived, time.Nanosecond*0) | ||
assert.Equal(t, time.Nanosecond*0, usr) | ||
assert.Equal(t, time.Nanosecond*0, sys) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.