Add basic stats

This commit is contained in:
Ryan Dahl 2018-05-25 17:14:56 -04:00
parent 59534fb9e3
commit a1c0862047
2 changed files with 26 additions and 7 deletions

View File

@ -10,6 +10,14 @@ var resChan = make(chan *BaseMsg, 10)
var doneChan = make(chan bool) var doneChan = make(chan bool)
var wg sync.WaitGroup var wg sync.WaitGroup
var stats struct {
v8workerSend int
v8workerRespond int
v8workerRecv int
v8workerBytesSent int
v8workerBytesRecv int
}
// There is a single global worker for this process. // There is a single global worker for this process.
// This file should be the only part of deno that directly access it, so that // This file should be the only part of deno that directly access it, so that
// all interaction with V8 can go through a single point. // all interaction with V8 can go through a single point.
@ -24,6 +32,9 @@ func createWorker() {
} }
func recv(buf []byte) (response []byte) { func recv(buf []byte) (response []byte) {
stats.v8workerRecv++
stats.v8workerBytesRecv += len(buf)
msg := &BaseMsg{} msg := &BaseMsg{}
check(proto.Unmarshal(buf, msg)) check(proto.Unmarshal(buf, msg))
assert(len(msg.Payload) > 0, "BaseMsg has empty payload.") assert(len(msg.Payload) > 0, "BaseMsg has empty payload.")
@ -38,6 +49,10 @@ func recv(buf []byte) (response []byte) {
response = r response = r
} }
} }
if response != nil {
stats.v8workerRespond++
stats.v8workerBytesSent += len(response)
}
return response return response
} }
@ -79,6 +94,8 @@ func DispatchLoop() {
case msg := <-resChan: case msg := <-resChan:
out, err := proto.Marshal(msg) out, err := proto.Marshal(msg)
err = worker.SendBytes(out) err = worker.SendBytes(out)
stats.v8workerSend++
stats.v8workerBytesSent += len(out)
exitOnError(err) exitOnError(err)
case <-doneChan: case <-doneChan:
// All goroutines have completed. Now we can exit main(). // All goroutines have completed. Now we can exit main().

View File

@ -85,15 +85,17 @@ func deno(inputFn string) (actual []byte, cachedir string, err error) {
} }
func integrationTestSetup() { func integrationTestSetup() {
startServer() if denoFn == "" {
cwd, err := os.Getwd() startServer()
if err != nil { cwd, err := os.Getwd()
panic(err) if err != nil {
panic(err)
}
denoFn = path.Join(cwd, "deno")
} }
denoFn = path.Join(cwd, "deno")
} }
func TestIntegration(t *testing.T) { func TestIntegrationFiles(t *testing.T) {
integrationTestSetup() integrationTestSetup()
outFiles := listTestFiles() outFiles := listTestFiles()
for _, outFile := range outFiles { for _, outFile := range outFiles {
@ -103,7 +105,7 @@ func TestIntegration(t *testing.T) {
} }
} }
func TestUrlArgs(t *testing.T) { func TestIntegrationUrlArgs(t *testing.T) {
integrationTestSetup() integrationTestSetup()
// Using good port 4545 // Using good port 4545