Last active
February 11, 2022 19:24
-
-
Save WhisperingChaos/da17b8cb06d66d5d95a5285109b5af93 to your computer and use it in GitHub Desktop.
Trace Latency Gaps
This file contains hidden or 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 hidden or 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
package main | |
import ( | |
"net/http" | |
_ "net/http/pprof" | |
"time" | |
) | |
func init() { | |
go proListener() | |
} | |
func proListener() { | |
http.ListenAndServe(":2112", nil) | |
} | |
func main() { | |
sr := make(chan naught) | |
go msgSend(sr) | |
go msgReceive(sr) | |
select {} | |
} | |
func msgSend( | |
msg chan<- naught, | |
) { | |
for { | |
msg <- naught{} | |
} | |
} | |
func msgReceive( | |
msg <-chan naught, | |
) { | |
tkr := time.NewTicker(1 * time.Millisecond) | |
for { | |
<-msg | |
<-tkr.C | |
} | |
} | |
type naught struct{} | |
This file contains hidden or 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
//go:build latencycompute | |
package main | |
import ( | |
"fmt" | |
"path/filepath" | |
"runtime" | |
"strings" | |
"time" | |
) | |
func main() { | |
programVersion() | |
sr := make(chan naught) | |
go msgSend(sr) | |
go msgReceive(sr) | |
select {} | |
} | |
var eBUILD_TAG string | |
func programVersion() { | |
gover := runtime.Version() | |
_, filePath, _, _ := runtime.Caller(0) | |
fileNm := filepath.Base(filePath) | |
fileNm = strings.TrimPrefix(strings.TrimSuffix(fileNm, ".go"), "main_") | |
fmt.Printf("GO_COMPILER_VERSION=%s\nBUILD_TAG=%s\n", gover, eBUILD_TAG) | |
} | |
func msgSend( | |
msg chan<- naught, | |
) { | |
for { | |
msg <- naught{} | |
} | |
} | |
func msgReceive( | |
msg <-chan naught, | |
) { | |
tkr := time.NewTicker(1 * time.Millisecond) | |
tkprior := time.Now() | |
for { | |
<-msg | |
tkcurr := <-tkr.C | |
tkdiff := tkcurr.Sub(tkprior) | |
if tkdiff > time.Duration(5*time.Millisecond) { | |
fmt.Printf("Latency %d \n", tkdiff) | |
} | |
tkprior = tkcurr | |
} | |
} | |
type naught struct{} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment