Skip to content

Commit

Permalink
changed parse to report the "correct" number of iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
kent007 committed Jan 12, 2021
1 parent ee322f7 commit de1494e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion top/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ func topRowToSkip(data []byte) bool {
func Parse(s string) ([]Row, int, error) {
lines := strings.Split(s, "\n")
rows := make([][]string, 0, len(lines))
iterations := 0

//start this one before, since the first measurement doesn't really count
iterations := -1
for _, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 {
Expand Down Expand Up @@ -172,6 +174,9 @@ func Parse(s string) ([]Row, int, error) {
tcRows = append(tcRows, rs.row)
}
}
if iterations == 0 {
return tcRows, 0, fmt.Errorf("top did not take a significant measurement besides startup")
}
return tcRows, iterations, nil
}

Expand Down
6 changes: 3 additions & 3 deletions top/top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestGet(t *testing.T) {
now := time.Now()
rows, iterations, err := Get(DefaultExecPath, 0, 1, .5)
rows, iterations, err := Get(DefaultExecPath, 0, 1, 1)
if err != nil {
t.Skip(err)
}
Expand All @@ -22,8 +22,8 @@ func TestGet(t *testing.T) {
func TestTimedGet(t *testing.T) {
now := time.Now()
log.Printf("starting test at %s", now.String())
stopTimestamp := now.Add(3 * time.Second).UnixNano()
rows, iterations, err := GetTimed(DefaultExecPath, 0, stopTimestamp, 1)
stopTimestamp := now.Add(3*time.Second + 300*time.Millisecond).UnixNano()
rows, iterations, err := GetTimed(DefaultExecPath, 0, stopTimestamp, 3)

if err != nil {
t.Skip(err)
Expand Down

0 comments on commit de1494e

Please sign in to comment.