-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving driver-unrelated code (metrics) to separate package
Signed-off-by: Lazar Cvetković <[email protected]>
- Loading branch information
Showing
5 changed files
with
71 additions
and
63 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
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
File renamed without changes.
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,67 @@ | ||
package metric | ||
|
||
import ( | ||
"encoding/csv" | ||
"github.com/gocarina/gocsv" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/vhive-serverless/loader/pkg/common" | ||
"math" | ||
"os" | ||
"sync" | ||
) | ||
|
||
func RunCSVWriter(records chan interface{}, filename string, writerDone *sync.WaitGroup) { | ||
log.Debugf("Starting writer for %s", filename) | ||
|
||
file, err := os.Create(filename) | ||
common.Check(err) | ||
defer file.Close() | ||
|
||
writer := gocsv.NewSafeCSVWriter(csv.NewWriter(file)) | ||
if err := gocsv.MarshalChan(records, writer); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
writerDone.Done() | ||
} | ||
|
||
func CreateGlobalMetricsCollector(filename string, collector chan *ExecutionRecord, | ||
signalReady *sync.WaitGroup, signalEverythingWritten *sync.WaitGroup, totalIssuedChannel chan int64) { | ||
|
||
// NOTE: totalNumberOfInvocations is initialized to MaxInt64 not to allow collector to complete before | ||
// the end signal is received on totalIssuedChannel, which deliver the total number of issued invocations. | ||
// This number is known once all the individual function drivers finish issuing invocations and | ||
// when all the invocations return | ||
var totalNumberOfInvocations int64 = math.MaxInt64 | ||
var currentlyWritten int64 | ||
|
||
file, err := os.Create(filename) | ||
common.Check(err) | ||
defer file.Close() | ||
|
||
signalReady.Done() | ||
|
||
records := make(chan interface{}, 100) | ||
writerDone := sync.WaitGroup{} | ||
writerDone.Add(1) | ||
go RunCSVWriter(records, filename, &writerDone) | ||
|
||
for { | ||
select { | ||
case record := <-collector: | ||
records <- record | ||
|
||
currentlyWritten++ | ||
case record := <-totalIssuedChannel: | ||
totalNumberOfInvocations = record | ||
} | ||
|
||
if currentlyWritten == totalNumberOfInvocations { | ||
close(records) | ||
writerDone.Wait() | ||
(*signalEverythingWritten).Done() | ||
|
||
return | ||
} | ||
} | ||
} |