fix windows tailer closing issues

main
Ben Grewell 4 years ago
parent 0dc467f289
commit f9a882f5e4

@ -3,9 +3,10 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment=""> <list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/client.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/reporter.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/reporter.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/reporter_linux.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter_linux.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/reporter_linux.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter_linux.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/client/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/tests/client/client.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/reporter_windows.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter_windows.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />

@ -492,7 +492,6 @@ func (c *Client) Start() (err error) {
if err != nil { if err != nil {
return err return err
} }
fmt.Println(cmd)
var exit chan int var exit chan int
c.outputStream, c.errorStream, exit, c.cancel, err = ExecuteAsyncWithCancel(cmd) c.outputStream, c.errorStream, exit, c.cancel, err = ExecuteAsyncWithCancel(cmd)
if err != nil { if err != nil {

@ -1,7 +1,6 @@
package iperf package iperf
import ( import (
"fmt"
"github.com/BGrewell/tail" "github.com/BGrewell/tail"
) )
@ -22,7 +21,6 @@ func (r *Reporter) Stop() {
r.tailer.Stop() r.tailer.Stop()
r.tailer.Cleanup() r.tailer.Cleanup()
close(r.ReportingChannel) close(r.ReportingChannel)
fmt.Println("reporter stopped")
} }
// runLogProcessor is OS specific because of differences in iperf on Windows and Linux // runLogProcessor is OS specific because of differences in iperf on Windows and Linux

@ -45,13 +45,12 @@ Connecting to host 10.254.100.100, port 5201
iperf Done. iperf Done.
*/ */
//TODO: NEED TO UPDATE WINDOWS IMPLEMENTATION ALSO!!!!!
func (r *Reporter) runLogProcessor() { func (r *Reporter) runLogProcessor() {
var err error var err error
r.tailer, err = tail.TailFile(r.LogFile, tail.Config{ r.tailer, err = tail.TailFile(r.LogFile, tail.Config{
Follow: true, Follow: true,
ReOpen: true, ReOpen: true,
Poll: true, // on linux we don't need to poll as the fsnotify works properly Poll: false, // on linux we don't need to poll as the fsnotify works properly
MustExist: true, MustExist: true,
}) })
if err != nil { if err != nil {
@ -120,7 +119,7 @@ func (r *Reporter) runLogProcessor() {
r.ReportingChannel <- report r.ReportingChannel <- report
} }
} }
case <- time.After(1 * time.Second): case <- time.After(100 * time.Millisecond):
if !r.running { if !r.running {
return return
} }

@ -7,10 +7,12 @@ import (
"log" "log"
"strconv" "strconv"
"strings" "strings"
"time"
) )
func (r *Reporter) runLogProcessor() { func (r *Reporter) runLogProcessor() {
tailer, err := tail.TailFile(r.LogFile, tail.Config{ var err error
r.tailer, err = tail.TailFile(r.LogFile, tail.Config{
Follow: true, Follow: true,
ReOpen: true, ReOpen: true,
Poll: true, Poll: true,
@ -19,55 +21,61 @@ func (r *Reporter) runLogProcessor() {
if err != nil { if err != nil {
log.Fatalf("failed to tail log file: %v", err) log.Fatalf("failed to tail log file: %v", err)
} }
for line := range tailer.Lines {
// TODO: For now this only cares about individual streams it ignores the sum lines for {
if len(line.Text) > 5 { select {
id := line.Text[1:4] case line := <- r.tailer.Lines:
stream, err := strconv.Atoi(strings.TrimSpace(id)) if line == nil {
if err != nil {
continue continue
} }
fields := strings.Fields(line.Text[5:]) if len(line.Text) > 5 {
if len(fields) >= 6 { id := line.Text[1:4]
if fields[0] == "local" { stream, err := strconv.Atoi(strings.TrimSpace(id))
continue
}
timeFields := strings.Split(fields[0], "-")
start, err := strconv.ParseFloat(timeFields[0], 32)
if err != nil {
log.Printf("failed to convert start time: %s\n", err)
}
end, err := strconv.ParseFloat(timeFields[1], 32)
transferedStr := fmt.Sprintf("%s%s", fields[2], fields[3])
transferedBytes, err := conversions.StringBitRateToInt(transferedStr)
if err != nil {
log.Printf("failed to convert units: %s\n", err)
}
transferedBytes = transferedBytes / 8
rateStr := fmt.Sprintf("%s%s", fields[4], fields[5])
rate, err := conversions.StringBitRateToInt(rateStr)
if err != nil { if err != nil {
log.Printf("failed to convert units: %s\n", err) continue
}
omitted := false
if len(fields) >= 7 && fields[6] == "(omitted)" {
omitted = true
} }
report := &StreamIntervalReport{ fields := strings.Fields(line.Text[5:])
Socket: stream, if len(fields) >= 6 {
StartInterval: float32(start), if fields[0] == "local" {
EndInterval: float32(end), continue
Seconds: float32(end - start), }
Bytes: int(transferedBytes), timeFields := strings.Split(fields[0], "-")
BitsPerSecond: float64(rate), start, err := strconv.ParseFloat(timeFields[0], 32)
Omitted: omitted, if err != nil {
log.Printf("failed to convert start time: %s\n", err)
}
end, err := strconv.ParseFloat(timeFields[1], 32)
transferedStr := fmt.Sprintf("%s%s", fields[2], fields[3])
transferedBytes, err := conversions.StringBitRateToInt(transferedStr)
if err != nil {
log.Printf("failed to convert units: %s\n", err)
}
transferedBytes = transferedBytes / 8
rateStr := fmt.Sprintf("%s%s", fields[4], fields[5])
rate, err := conversions.StringBitRateToInt(rateStr)
if err != nil {
log.Printf("failed to convert units: %s\n", err)
}
omitted := false
if len(fields) >= 7 && fields[6] == "(omitted)" {
omitted = true
}
report := &StreamIntervalReport{
Socket: stream,
StartInterval: float32(start),
EndInterval: float32(end),
Seconds: float32(end - start),
Bytes: int(transferedBytes),
BitsPerSecond: float64(rate),
Omitted: omitted,
}
r.ReportingChannel <- report
} }
r.ReportingChannel <- report
} }
} case <- time.After(100 * time.Millisecond):
if !r.running {
if !r.running { return
return }
} }
} }
} }

Loading…
Cancel
Save