add mac osx support

main
Ben Grewell 4 years ago
parent f589823ad2
commit a4409243ab

@ -2,7 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/reporter_darwin.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -37,7 +39,7 @@
<property name="go.import.settings.migrated" value="true" />
<property name="go.sdk.automatically.set" value="true" />
<property name="go.tried.to.enable.integration.vgo.integrator" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../ran_onf/onos-ric-master/cmd/apps/onos-ric-mlb/onos-ran-mlb.go" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>

@ -0,0 +1,96 @@
package iperf
import (
"fmt"
"github.com/BGrewell/go-conversions"
"github.com/BGrewell/tail"
"log"
"strconv"
"strings"
"time"
)
//TODO: This has not been tested on OS X ... my assumption is it is the exact same as linux but if it's not then the
// reporting will be broken
func (r *Reporter) runLogProcessor() {
var err error
r.tailer, err = tail.TailFile(r.LogFile, tail.Config{
Follow: true,
ReOpen: true,
Poll: false, // on linux we don't need to poll as the fsnotify works properly
MustExist: true,
})
if err != nil {
log.Fatalf("failed to tail log file: %v", err)
}
for {
select {
case line := <-r.tailer.Lines:
if line == nil {
continue
}
if len(line.Text) > 5 {
id := line.Text[1:4]
stream, err := strconv.Atoi(strings.TrimSpace(id))
if err != nil {
continue
}
fields := strings.Fields(line.Text[5:])
if len(fields) >= 9 {
if fields[0] == "local" {
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 {
log.Printf("failed to convert units: %s\n", err)
}
retrans, err := strconv.Atoi(fields[6])
if err != nil {
log.Printf("failed to convert units: %s\n", err)
}
cwndStr := fmt.Sprintf("%s%s", fields[7], fields[8])
cwnd, err := conversions.StringBitRateToInt(cwndStr)
if err != nil {
log.Printf("failed to convert units: %s\n", err)
}
cwnd = cwnd / 8
omitted := false
if len(fields) >= 10 && fields[9] == "(omitted)" {
omitted = true
}
report := &StreamIntervalReport{
Socket: stream,
StartInterval: float32(start),
EndInterval: float32(end),
Seconds: float32(end - start),
Bytes: int(transferedBytes),
BitsPerSecond: float64(rate),
Retransmissions: retrans,
CongestionWindow: int(cwnd),
Omitted: omitted,
}
r.ReportingChannel <- report
}
}
case <-time.After(100 * time.Millisecond):
if !r.running {
return
}
}
}
}
Loading…
Cancel
Save