How to use bench method of main Package

Best Syzkaller code snippet using main.bench

bench.go

Source:bench.go Github

copy

Full Screen

...15 "runtime"16 "sort"17 "strings"18 "time"19 "bench"20 "bench/counter"21 "bench/parameter"22 "github.com/comail/colog"23)24var (25 benchDuration time.Duration = time.Minute26 preTestOnly bool27 noLevelup bool28 checkFuncs []benchFunc // also preTestFuncs29 everyCheckFuncs []benchFunc30 loadFuncs []benchFunc31 loadLevelUpFuncs []benchFunc32 postTestFuncs []benchFunc33 loadLogs []string34 pprofPort int = 1606035)36type benchFunc struct {37 Name string38 Func func(ctx context.Context, state *bench.State) error39}40func addCheckFunc(f benchFunc) {41 checkFuncs = append(checkFuncs, f)42}43func addEveryCheckFunc(f benchFunc) {44 everyCheckFuncs = append(everyCheckFuncs, f)45}46func addLoadFunc(weight int, f benchFunc) {47 for i := 0; i < weight; i++ {48 loadFuncs = append(loadFuncs, f)49 }50}51func addLoadAndLevelUpFunc(weight int, f benchFunc) {52 for i := 0; i < weight; i++ {53 loadFuncs = append(loadFuncs, f)54 loadLevelUpFuncs = append(loadLevelUpFuncs, f)55 }56}57func addPostTestFunc(f benchFunc) {58 postTestFuncs = append(postTestFuncs, f)59}60func requestInitialize(targetHost string) error {61 u, _ := url.Parse("/initialize")62 u.Scheme = "http"63 u.Host = targetHost64 req, err := http.NewRequest("GET", u.String(), nil)65 if err != nil {66 return err67 }68 req.Header.Set("User-Agent", bench.UserAgent)69 req.Host = bench.TorbAppHost70 client := &http.Client{71 Timeout: bench.InitializeTimeout,72 }73 res, err := client.Do(req)74 if err != nil {75 return err76 }77 defer res.Body.Close()78 _, err = io.Copy(ioutil.Discard, res.Body)79 if err != nil {80 return err81 }82 if !(200 <= res.StatusCode && res.StatusCode < 300) {83 return fmt.Errorf("Unexpected status code: %d", res.StatusCode)84 }85 return nil86}87// 負荷を掛ける前にアプリが最低限動作しているかをチェックする88// エラーが発生したら負荷をかけずに終了する89func preTest(ctx context.Context, state *bench.State) error {90 funcs := make([]benchFunc, len(checkFuncs)+len(everyCheckFuncs))91 copy(funcs, checkFuncs)92 copy(funcs[len(checkFuncs):], everyCheckFuncs)93 for _, checkFunc := range funcs {94 t := time.Now()95 err := checkFunc.Func(ctx, state)96 log.Println("preTest:", checkFunc.Name, time.Since(t))97 if err != nil {98 return err99 }100 }101 return nil102}103func postTest(ctx context.Context, state *bench.State) error {104 for _, postTestFunc := range postTestFuncs {105 t := time.Now()106 err := postTestFunc.Func(ctx, state)107 log.Println("postTest:", postTestFunc.Name, time.Since(t))108 if err != nil {109 return err110 }111 }112 return nil113}114func checkMain(ctx context.Context, state *bench.State) error {115 // Inserts CheckEventReport and CheckReport on every the specified interval116 checkEventReportTicker := time.NewTicker(parameter.CheckEventReportInterval)117 defer checkEventReportTicker.Stop()118 checkReportTicker := time.NewTicker(parameter.CheckReportInterval)119 defer checkReportTicker.Stop()120 everyCheckerTicker := time.NewTicker(parameter.EveryCheckerInterval)121 defer everyCheckerTicker.Stop()122 randCheckFuncIndices := []int{}123 popRandomPermCheckFunc := func() benchFunc {124 n := len(randCheckFuncIndices)125 if n == 0 {126 randCheckFuncIndices = rand.Perm(len(checkFuncs))127 n = len(randCheckFuncIndices)128 }129 i := randCheckFuncIndices[n-1]130 randCheckFuncIndices = randCheckFuncIndices[:n-1]131 return checkFuncs[i]132 }133 for {134 select {135 case <-checkEventReportTicker.C:136 if ctx.Err() != nil {137 return nil138 }139 t := time.Now()140 err := bench.CheckEventReport(ctx, state)141 log.Println("checkMain(checkEventReport): CheckEventReport", time.Since(t))142 // fatalError以外は見逃してあげる143 if err != nil && bench.IsFatal(err) {144 return err145 }146 case <-checkReportTicker.C:147 if ctx.Err() != nil {148 return nil149 }150 t := time.Now()151 err := bench.CheckReport(ctx, state)152 log.Println("checkMain(checkReport): CheckReport", time.Since(t))153 // fatalError以外は見逃してあげる154 if err != nil && bench.IsFatal(err) {155 return err156 }157 case <-everyCheckerTicker.C:158 for _, checkFunc := range everyCheckFuncs {159 t := time.Now()160 err := checkFunc.Func(ctx, state)161 log.Println("checkMain(every):", checkFunc.Name, time.Since(t))162 // fatalError以外は見逃してあげる163 if err != nil && bench.IsFatal(err) {164 return err165 }166 if err != nil {167 // バリデーションシナリオを悪用してスコアブーストさせないためエラーのときは少し待つ168 time.Sleep(parameter.WaitOnError)169 }170 }171 case <-ctx.Done():172 // benchmarker timeout173 return nil174 default:175 if ctx.Err() != nil {176 return nil177 }178 // Sequentially runs the check functions in randomly permuted order179 checkFunc := popRandomPermCheckFunc()180 t := time.Now()181 err := checkFunc.Func(ctx, state)182 log.Println("checkMain:", checkFunc.Name, time.Since(t))183 // fatalError以外は見逃してあげる184 if err != nil && bench.IsFatal(err) {185 return err186 }187 if err != nil {188 // バリデーションシナリオを悪用してスコアブーストさせないためエラーのときは少し待つ189 time.Sleep(parameter.WaitOnError)190 }191 }192 }193}194func goLoadFuncs(ctx context.Context, state *bench.State, n int) {195 sumWait := (n - 1) * n / 2196 waits := rand.Perm(n)197 var sumDelay time.Duration198 for i := 0; i < n; i++ {199 // add delay not to fire all goroutines at same time200 delay := time.Duration(float64(waits[i])/float64(sumWait)*parameter.LoadStartupTotalWait) * time.Microsecond201 time.Sleep(delay)202 sumDelay += delay203 go func() {204 for {205 if ctx.Err() != nil {206 return207 }208 loadFunc := loadFuncs[rand.Intn(len(loadFuncs))]209 t := time.Now()210 err := loadFunc.Func(ctx, state)211 log.Println("debug: loadFunc:", loadFunc.Name, time.Since(t))212 if err != nil {213 // バリデーションシナリオを悪用してスコアブーストさせないためエラーのときは少し待つ214 time.Sleep(parameter.WaitOnError)215 }216 // no fail217 }218 }()219 }220 log.Println("debug: goLoadLevelUpFuncs wait totally", sumDelay)221}222func goLoadLevelUpFuncs(ctx context.Context, state *bench.State, n int) {223 sumWait := (n - 1) * n / 2224 waits := rand.Perm(n)225 var sumDelay time.Duration226 for i := 0; i < n; i++ {227 // add delay not to fire all goroutines at same time228 delay := time.Duration(float64(waits[i])/float64(sumWait)*parameter.LoadStartupTotalWait) * time.Microsecond229 time.Sleep(delay)230 sumDelay += delay231 go func() {232 for {233 if ctx.Err() != nil {234 return235 }236 loadFunc := loadLevelUpFuncs[rand.Intn(len(loadLevelUpFuncs))]237 t := time.Now()238 err := loadFunc.Func(ctx, state)239 log.Println("debug: levelUpFunc:", loadFunc.Name, time.Since(t))240 if err != nil {241 // バリデーションシナリオを悪用してスコアブーストさせないためエラーのときは少し待つ242 time.Sleep(parameter.WaitOnError)243 }244 // no fail245 }246 }()247 }248 log.Println("debug: goLoadLevelUpFuncs wait totally", sumDelay)249}250func loadMain(ctx context.Context, state *bench.State) {251 levelUpRatio := parameter.LoadLevelUpRatio252 numGoroutines := parameter.LoadInitialNumGoroutines253 goLoadFuncs(ctx, state, int(numGoroutines))254 levelUpTicker := time.NewTicker(parameter.LoadLevelUpInterval)255 defer levelUpTicker.Stop()256 for {257 select {258 case <-levelUpTicker.C:259 log.Printf("debug: loadLevel:%d numGoroutines:%d runtime.NumGoroutines():%d\n", counter.GetKey("load-level-up"), int(numGoroutines), runtime.NumGoroutine())260 if noLevelup {261 continue262 }263 e, et := bench.GetLastCheckerError()264 hasRecentErr := e != nil && time.Since(et) < 5*time.Second265 path, st := bench.GetLastSlowPath()266 hasRecentSlowPath := path != "" && time.Since(st) < 5*time.Second267 now := time.Now().Format("01/02 15:04:05")268 if hasRecentErr {269 loadLogs = append(loadLogs, fmt.Sprintf("%v エラーが発生したため負荷レベルを上げられませんでした。%v", now, e))270 log.Println("Cannot increase Load Level. Reason: RecentErr", e, "Before", time.Since(et))271 } else if hasRecentSlowPath {272 loadLogs = append(loadLogs, fmt.Sprintf("%v レスポンスが遅いため負荷レベルを上げられませんでした。%v", now, path))273 log.Println("Cannot increase Load Level. Reason: SlowPath", path, "Before", time.Since(st))274 } else {275 loadLogs = append(loadLogs, fmt.Sprintf("%v 負荷レベルが上昇しました。", now))276 counter.IncKey("load-level-up")277 nextNumGoroutines := numGoroutines * levelUpRatio278 log.Println("Increase Load Level", counter.GetKey("load-level-up"))279 goLoadLevelUpFuncs(ctx, state, int(nextNumGoroutines-numGoroutines))280 numGoroutines = nextNumGoroutines281 }282 case <-ctx.Done():283 // ベンチ終了、このタイミングでエラーの収集をやめる。284 bench.GuardCheckerError(true)285 return286 }287 }288}289func printCounterSummary() {290 m := map[string]int64{}291 for key, count := range counter.GetMap() {292 if strings.HasPrefix(key, "GET|/api/events/") {293 key = "GET|/api/events/*"294 } else if strings.HasPrefix(key, "POST|/api/events/") {295 key = "POST|/api/events/*/actions/reserve"296 } else if strings.HasPrefix(key, "DELETE|/api/events/") {297 key = "DELETE|/api/events/*/sheets/*/*/reservation"298 } else if strings.HasPrefix(key, "GET|/admin/api/events/") {299 key = "GET|/admin/api/events/*"300 } else if strings.HasPrefix(key, "GET|/api/users/") {301 key = "GET|/api/users/*"302 } else if strings.HasPrefix(key, "POST|/admin/api/events/") {303 key = "POST|/admin/api/events/*/actions/edit"304 } else if strings.HasPrefix(key, "GET|/admin/api/reports/events/") {305 key = "GET|/admin/api/reports/events/*/sales"306 }307 m[key] += count308 }309 type p struct {310 Key string311 Value int64312 }313 var s []p314 for key, count := range m {315 s = append(s, p{key, count})316 }317 sort.Slice(s, func(i, j int) bool { return s[i].Value > s[j].Value })318 log.Println("----- Request counts -----")319 for _, kv := range s {320 if strings.HasPrefix(kv.Key, "GET|") || strings.HasPrefix(kv.Key, "POST|") || strings.HasPrefix(kv.Key, "DELETE|") {321 log.Println(kv.Key, kv.Value)322 }323 }324 log.Println("----- Other counts ------")325 for _, kv := range s {326 if strings.HasPrefix(kv.Key, "GET|") || strings.HasPrefix(kv.Key, "POST|") || strings.HasPrefix(kv.Key, "DELETE|") {327 } else {328 log.Println(kv.Key, kv.Value)329 }330 }331 log.Println("-------------------------")332}333func startBenchmark(remoteAddrs []string) *BenchResult {334 addLoadFunc(10, benchFunc{"LoadCreateUser", bench.LoadCreateUser})335 addLoadFunc(10, benchFunc{"LoadMyPage", bench.LoadMyPage})336 addLoadFunc(10, benchFunc{"LoadEventReport", bench.LoadEventReport})337 addLoadFunc(10, benchFunc{"LoadAdminTopPage", bench.LoadAdminTopPage})338 addLoadFunc(1, benchFunc{"LoadReport", bench.LoadReport})339 addLoadAndLevelUpFunc(30, benchFunc{"LoadTopPage", bench.LoadTopPage})340 addLoadAndLevelUpFunc(10, benchFunc{"LoadReserveCancelSheet", bench.LoadReserveCancelSheet})341 addLoadAndLevelUpFunc(20, benchFunc{"LoadReserveSheet", bench.LoadReserveSheet})342 addLoadAndLevelUpFunc(30, benchFunc{"LoadGetEvent", bench.LoadGetEvent})343 addCheckFunc(benchFunc{"CheckStaticFiles", bench.CheckStaticFiles})344 addCheckFunc(benchFunc{"CheckCreateUser", bench.CheckCreateUser})345 addCheckFunc(benchFunc{"CheckLogin", bench.CheckLogin})346 addCheckFunc(benchFunc{"CheckTopPage", bench.CheckTopPage})347 addCheckFunc(benchFunc{"CheckAdminTopPage", bench.CheckAdminTopPage})348 addCheckFunc(benchFunc{"CheckReserveSheet", bench.CheckReserveSheet})349 addCheckFunc(benchFunc{"CheckAdminLogin", bench.CheckAdminLogin})350 addCheckFunc(benchFunc{"CheckCreateEvent", bench.CheckCreateEvent})351 addCheckFunc(benchFunc{"CheckMyPage", bench.CheckMyPage})352 addCheckFunc(benchFunc{"CheckCancelReserveSheet", bench.CheckCancelReserveSheet})353 addCheckFunc(benchFunc{"CheckGetEvent", bench.CheckGetEvent})354 addEveryCheckFunc(benchFunc{"CheckSheetReservationEntropy", bench.CheckSheetReservationEntropy})355 addPostTestFunc(benchFunc{"CheckReport", bench.CheckReport})356 result := new(BenchResult)357 result.StartTime = time.Now()358 defer func() {359 result.EndTime = time.Now()360 }()361 getErrorsString := func() []string {362 var errors []string363 for _, err := range bench.GetCheckerErrors() {364 errors = append(errors, err.Error())365 }366 return errors367 }368 state := new(bench.State)369 log.Println("State.Init()")370 state.Init()371 log.Println("State.Init() Done")372 log.Println("requestInitialize()")373 err := requestInitialize(bench.GetRandomTargetHost())374 if err != nil {375 result.Score = 0376 result.Errors = getErrorsString()377 result.Message = fmt.Sprint("/initialize へのリクエストに失敗しました。", err)378 return result379 }380 log.Println("requestInitialize() Done")381 ctx, cancel := context.WithTimeout(context.Background(), benchDuration)382 defer cancel()383 log.Println("preTest()")384 err = preTest(ctx, state)385 if err != nil {386 result.Score = 0387 result.Errors = getErrorsString()388 result.Message = fmt.Sprint("負荷走行前のバリデーションに失敗しました。", err)389 return result390 }391 log.Println("preTest() Done")392 if preTestOnly {393 result.Score = 0394 result.Errors = getErrorsString()395 result.Message = fmt.Sprint("preTest passed.")396 return result397 }398 go loadMain(ctx, state)399 log.Println("checkMain()")400 err = checkMain(ctx, state)401 if err != nil {402 result.Score = 0403 result.Errors = getErrorsString()404 result.Message = fmt.Sprint("負荷走行中のバリデーションに失敗しました。", err)405 return result406 }407 log.Println("checkMain() Done")408 time.Sleep(parameter.AllowableDelay)409 // If backlog, the queue length for completely established sockets waiting to be accepted,410 // are too large or not configured well, postTest may timeout because of the remained requests.411 log.Println("postTest()")412 err = postTest(context.Background(), state)413 if err != nil {414 result.Score = 0415 result.Errors = getErrorsString()416 result.Message = fmt.Sprint("負荷走行後のバリデーションに失敗しました。", err)417 return result418 }419 log.Println("postTest() Done")420 printCounterSummary()421 getEventCount := counter.SumPrefix("GET|/api/events/")422 reserveCount := counter.SumPrefix("POST|/api/events/")423 cancelCount := counter.SumPrefix("DELETE|/api/events/")424 topCount := counter.SumEqual("GET|/")425 getCount := counter.SumPrefix(`GET|/`)426 postCount := counter.SumPrefix(`POST|/`)427 deleteCount := counter.SumPrefix(`DELETE|/`) // == cancelCount428 staticCount := counter.GetKey("staticfile-304") + counter.GetKey("staticfile-200")429 score := parameter.Score(getCount, postCount, deleteCount, staticCount, reserveCount, cancelCount, topCount, getEventCount)430 log.Println("get", getCount)431 log.Println("post", postCount)432 log.Println("delete", deleteCount)433 log.Println("static", staticCount)434 log.Println("top", topCount)435 log.Println("reserve", reserveCount)436 log.Println("cancel", cancelCount)437 log.Println("get_event", getEventCount)438 log.Println("score", score)439 result.LoadLevel = int(counter.GetKey("load-level-up"))440 result.Pass = true441 result.Score = score442 result.Errors = getErrorsString()443 result.Message = "ok"444 return result445}446func main() {447 rand.Seed(time.Now().UnixNano())448 log.SetFlags(log.LstdFlags | log.Lmicroseconds | log.Lshortfile)449 log.SetPrefix("[isu8q-bench] ")450 colog.Register()451 colog.SetDefaultLevel(colog.LInfo)452 colog.SetMinLevel(colog.LInfo)453 var (454 workermode bool455 portalUrl string456 dataPath string457 remotes string458 output string459 jobid string460 tempdir string461 test bool462 debugMode bool463 debugLog bool464 nolevelup bool465 duration time.Duration466 )467 flag.BoolVar(&workermode, "workermode", false, "workermode")468 flag.StringVar(&portalUrl, "portal", "http://localhost:8888", "portal site url (only used at workermode)")469 flag.StringVar(&dataPath, "data", "./data", "path to data directory")470 flag.StringVar(&remotes, "remotes", "localhost:8080", "remote addrs to benchmark")471 flag.StringVar(&output, "output", "", "path to write result json")472 flag.StringVar(&jobid, "jobid", "", "job id")473 flag.StringVar(&tempdir, "tempdir", "", "path to temp dir")474 flag.BoolVar(&test, "test", false, "run pretest only")475 flag.BoolVar(&debugMode, "debug-mode", false, "add debugging info into request header")476 flag.BoolVar(&debugLog, "debug-log", false, "print debug log")477 flag.DurationVar(&duration, "duration", time.Minute, "benchamrk duration")478 flag.BoolVar(&nolevelup, "nolevelup", false, "dont increase load level")479 flag.Parse()480 if debugLog {481 colog.SetMinLevel(colog.LDebug)482 }483 bench.DebugMode = debugMode484 bench.DataPath = dataPath485 bench.PrepareDataSet()486 preTestOnly = test487 noLevelup = nolevelup488 benchDuration = duration489 if workermode {490 runWorkerMode(tempdir, portalUrl)491 return492 }493 go func() {494 log.Println(http.ListenAndServe(fmt.Sprintf(":%d", pprofPort), nil))495 }()496 remoteAddrs := strings.Split(remotes, ",")497 if 0 == len(remoteAddrs) {498 log.Fatalln("invalid remotes")499 }500 log.Println("Remotes", remoteAddrs)501 bench.SetTargetHosts(remoteAddrs)502 result := startBenchmark(remoteAddrs)503 result.IPAddrs = remotes504 result.JobID = jobid505 result.Logs = loadLogs506 b, err := json.Marshal(result)507 if err != nil {508 log.Fatalln(err)509 }510 log.Println(string(b))511 if output != "" {512 err := ioutil.WriteFile(output, b, 0644)513 if err != nil {514 log.Fatalln(err)515 }...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "fmt"4 "sync"5 "time"6 "../../tracer"7)8var x = 09func reader(m *sync.Mutex, c chan struct {10 threadId uint6411 value int12}) {13 myTIDCache := tracer.GetGID()14 for i := 0; i < 100; i++ {15 myTIDCache := tracer.GetGID()16 time.Sleep(1 * time.Second)17 tracer.PreLock(&m, "perfBench\\ex1\\main.go:14", myTIDCache)18 m.Lock()19 tracer.ReadAcc(&x, "perfBench\\ex1\\main.go:15", myTIDCache)20 fmt.Sprint(x)21 tracer.PostLock(&m, "perfBench\\ex1\\main.go:16", myTIDCache)22 m.Unlock()23 }24 tracer.PreSend(c, "perfBench\\ex1\\main.go:18", myTIDCache)25 c <- struct {26 threadId uint6427 value int28 }{myTIDCache, 1}29 tracer.PostSend(c, "perfBench\\ex1\\main.go:18", myTIDCache)30}31func writer(a, b, c, d *sync.Mutex, y chan struct {32 threadId uint6433 value int34}) {35 myTIDCache := tracer.GetGID()36 for i := 0; i < 100; i++ {37 time.Sleep(1 * time.Second)38 tracer.PreLock(&a, "perfBench\\ex1\\main.go:23", myTIDCache)39 a.Lock()40 tracer.PreLock(&b, "perfBench\\ex1\\main.go:24", myTIDCache)41 b.Lock()42 tracer.PreLock(&c, "perfBench\\ex1\\main.go:25", myTIDCache)43 c.Lock()44 tracer.PreLock(&d, "perfBench\\ex1\\main.go:26", myTIDCache)45 d.Lock()46 tracer.WriteAcc(&x, "perfBench\\ex1\\main.go:27", myTIDCache)47 x++48 tracer.PostLock(&d, "perfBench\\ex1\\main.go:28", myTIDCache)49 d.Unlock()50 tracer.PostLock(&c, "perfBench\\ex1\\main.go:29", myTIDCache)51 c.Unlock()52 tracer.PostLock(&b, "perfBench\\ex1\\main.go:30", myTIDCache)53 b.Unlock()54 tracer.PostLock(&a, "perfBench\\ex1\\main.go:31", myTIDCache)55 a.Unlock()56 }57 tracer.PreSend(y, "perfBench\\ex1\\main.go:33", myTIDCache)58 y <- struct {59 threadId uint6460 value int61 }{myTIDCache, 1}62 tracer.PostSend(y, "perfBench\\ex1\\main.go:33", myTIDCache)63}64func main() {65 tracer.Start()66 myTIDCache := tracer.GetGID()67 tracer.RegisterThread("main")68 a := &sync.Mutex{}69 tracer.WriteAcc(&a, "perfBench\\ex1\\main.go:37", myTIDCache)70 b := &sync.Mutex{}71 tracer.WriteAcc(&b, "perfBench\\ex1\\main.go:38", myTIDCache)72 c := &sync.Mutex{}73 tracer.WriteAcc(&c, "perfBench\\ex1\\main.go:39", myTIDCache)74 d := &sync.Mutex{}75 tracer.WriteAcc(&d, "perfBench\\ex1\\main.go:40", myTIDCache)76 ch := make(chan struct {77 threadId uint6478 value int79 })80 tracer.RegisterChan(ch, cap(ch))81 tmp1 := tracer.GetWaitSigID()82 tracer.Signal(tmp1, myTIDCache)83 go func(m *sync.Mutex, c chan struct {84 threadId uint6485 value int86 }) {87 tracer.RegisterThread("reader0")88 tracer.Wait(tmp1, tracer.GetGID())89 reader(m, c)90 }(a, ch)91 tmp2 := tracer.GetWaitSigID()92 tracer.Signal(tmp2, myTIDCache)93 go func(m *sync.Mutex, c chan struct {94 threadId uint6495 value int96 }) {97 tracer.RegisterThread("reader1")98 tracer.Wait(tmp2, tracer.GetGID())99 reader(m, c)100 }(b, ch)101 tmp3 := tracer.GetWaitSigID()102 tracer.Signal(tmp3, myTIDCache)103 go func(m *sync.Mutex, c chan struct {104 threadId uint64105 value int106 }) {107 tracer.RegisterThread("reader2")108 tracer.Wait(tmp3, tracer.GetGID())109 reader(m, c)110 }(c, ch)111 tmp4 := tracer.GetWaitSigID()112 tracer.Signal(tmp4, myTIDCache)113 go func(m *sync.Mutex, c chan struct {114 threadId uint64115 value int116 }) {117 tracer.RegisterThread("reader3")118 tracer.Wait(tmp4, tracer.GetGID())119 reader(m, c)120 }(d, ch)121 tmp5 := tracer.GetWaitSigID()122 tracer.Signal(tmp5, myTIDCache)123 go func(a, b, c, d *sync.Mutex, y chan struct {124 threadId uint64125 value int126 }) {127 tracer.RegisterThread("writer4")128 tracer.Wait(tmp5, tracer.GetGID())129 writer(a, b, c, d, y)130 }(a, b, c, d, ch)131 tmp6 := tracer.GetWaitSigID()132 tracer.Signal(tmp6, myTIDCache)133 go func(a, b, c, d *sync.Mutex, y chan struct {134 threadId uint64135 value int136 }) {137 tracer.RegisterThread("writer5")138 tracer.Wait(tmp6, tracer.GetGID())139 writer(a, b, c, d, y)140 }(a, b, c, d, ch)141 tracer.PreRcv(ch, "perfBench\\ex1\\main.go:52", myTIDCache)142 tmp7 := <-ch143 tracer.PostRcv(ch, "perfBench\\ex1\\main.go:52", tmp7.threadId, myTIDCache)144 tracer.PreRcv(ch, "perfBench\\ex1\\main.go:53", myTIDCache)145 tmp8 := <-ch146 tracer.PostRcv(ch, "perfBench\\ex1\\main.go:53", tmp8.threadId, myTIDCache)147 tracer.PreRcv(ch, "perfBench\\ex1\\main.go:54", myTIDCache)148 tmp9 := <-ch149 tracer.PostRcv(ch, "perfBench\\ex1\\main.go:54", tmp9.threadId, myTIDCache)150 tracer.PreRcv(ch, "perfBench\\ex1\\main.go:55", myTIDCache)151 tmp10 := <-ch152 tracer.PostRcv(ch, "perfBench\\ex1\\main.go:55", tmp10.threadId, myTIDCache)153 tracer.PreRcv(ch, "perfBench\\ex1\\main.go:56", myTIDCache)154 tmp11 := <-ch155 tracer.PostRcv(ch, "perfBench\\ex1\\main.go:56", tmp11.threadId, myTIDCache)156 tracer.PreRcv(ch, "perfBench\\ex1\\main.go:57", myTIDCache)157 tmp12 := <-ch158 tracer.PostRcv(ch, "perfBench\\ex1\\main.go:57", tmp12.threadId, myTIDCache)159 tracer.Stop()160}...

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1import (2func Benchmark(b *testing.B) {3 for i := 0; i < b.N; i++ {4 fmt.Println("Hello")5 }6}7import (8func main() {9 fmt.Println("Hello")10}

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4}5import "testing"6func BenchmarkHello(b *testing.B) {7 for i := 0; i < b.N; i++ {8 Hello()9 }10}11import "fmt"12func main() {13 fmt.Println("Hello, playground")14}15import "testing"16func BenchmarkHello(b *testing.B) {17 for i := 0; i < b.N; i++ {18 Hello()19 }20}21import "fmt"22func main() {23 fmt.Println("Hello, playground")24}25import "testing"26func BenchmarkHello(b *testing.B) {27 for i := 0; i < b.N; i++ {28 Hello()29 }30}31import "fmt"32func main() {33 fmt.Println("Hello, playground")34}35import "testing"36func BenchmarkHello(b *testing.B) {37 for i := 0; i < b.N; i++ {38 Hello()39 }40}41import "fmt"42func main() {43 fmt.Println("Hello, playground")44}45import "testing"46func BenchmarkHello(b *testing.B) {47 for i := 0; i < b.N; i++ {48 Hello()49 }50}51import "fmt"52func main() {53 fmt.Println("Hello, playground")54}55import "testing"56func BenchmarkHello(b *testing.B) {57 for i := 0; i < b.N; i++ {58 Hello()59 }60}61import "fmt"62func main() {63 fmt.Println("Hello, playground")64}65import "testing"66func BenchmarkHello(b *testing.B) {67 for i := 0; i < b.N; i++ {68 Hello()69 }70}

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Welcome to the playground!")4 fmt.Println("The time is", time.Now())5}6import (7func main() {8 fmt.Println("Welcome to the playground!")9 fmt.Println("The time is", time.Now())10}11import (12func main() {13 fmt.Println("Welcome to the playground!")14 fmt.Println("The time is", time.Now())15}16import (17func main() {18 fmt.Println("Welcome to the playground!")19 fmt.Println("The time is", time.Now())20}21import (22func main() {23 fmt.Println("Welcome to the playground!")24 fmt.Println("The time is", time.Now())25}26import (27func main() {28 fmt.Println("Welcome to the playground!")29 fmt.Println("The time is", time.Now())30}31import (32func main() {33 fmt.Println("Welcome to the playground!")34 fmt.Println("The time is", time.Now())35}36import (37func main() {38 fmt.Println("Welcome to the playground!")39 fmt.Println("The time is", time.Now())40}41import (42func main() {43 fmt.Println("Welcome to the playground!")44 fmt.Println("The time is", time.Now())45}

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4}5import (6func main() {7 fmt.Println("Hello, playground")8}9import (10func main() {11 fmt.Println("Hello, playground")12}13import (14func main() {15 fmt.Println("Hello, playground")16}17import (18func main() {19 fmt.Println("Hello, playground")20}21import (22func main() {23 fmt.Println("Hello, playground")24}25import (26func main() {27 fmt.Println("Hello, playground")28}29import (30func main() {31 fmt.Println("Hello, playground")32}33import (34func main() {35 fmt.Println("Hello, playground")36}37import (38func main() {39 fmt.Println("Hello, playground")40}41import (42func main() {43 fmt.Println("Hello, playground")44}45import (46func main() {47 fmt.Println("Hello, playground")48}49import (50func main() {51 fmt.Println("Hello, playground")52}53import (54func main() {55 fmt.Println("Hello, playground")56}57import (58func main() {59 fmt.Println("Hello, playground")60}61import (62func main() {63 fmt.Println("Hello, playground")64}

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1func main() {2 var arr = [5]int{1, 2, 3, 4, 5}3 var l = len(arr)4 for i := 0; i < l; i++ {5 }6 fmt.Println(sum)7}8import "testing"9func BenchmarkSum(b *testing.B) {10 var arr = [5]int{1, 2, 3, 4, 5}11 var l = len(arr)12 for i := 0; i < l; i++ {13 }14 fmt.Println(sum)15}16import "testing"17func BenchmarkSum(b *testing.B) {18 var arr = [5]int{1, 2, 3, 4, 5}19 var l = len(arr)20 for i := 0; i < l; i++ {21 }22 fmt.Println(sum)23}24import "testing"25func BenchmarkSum(b *testing.B) {26 var arr = [5]int{1, 2, 3, 4, 5}27 var l = len(arr)28 for i := 0; i < l; i++ {29 }30 fmt.Println(sum)31}32import "testing"33func BenchmarkSum(b *testing.B) {34 var arr = [5]int{1, 2, 3, 4, 5}35 var l = len(arr)36 for i := 0; i < l; i++ {37 }38 fmt.Println(sum)39}40import "testing"41func BenchmarkSum(b *testing.B) {42 var arr = [5]int{1, 2, 3, 4, 5}43 var l = len(arr)44 for i := 0; i < l; i++ {45 }46 fmt.Println(sum)47}48import "testing"49func BenchmarkSum(b *

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("NumCPU:", runtime.NumCPU())4 fmt.Println("NumGoroutine:", runtime.NumGoroutine())5 fmt.Println("GOMAXPROCS:", runtime.GOMAXPROCS(0))6 fmt.Println("NumCPU:", runtime.NumCPU())7 fmt.Println("NumGoroutine:", runtime.NumGoroutine())8 fmt.Println("GOMAXPROCS:", runtime.GOMAXPROCS(0))9 runtime.GOMAXPROCS(1)10 go func() {11 runtime.GOMAXPROCS(1)12 for {13 fmt.Println("Hello from new goroutine")14 }15 }()16 runtime.GOMAXPROCS(1)17 time.Sleep(1 * time.Second)18}19import (20func main() {21 fmt.Println("NumCPU:", runtime.NumCPU())22 fmt.Println("NumGoroutine:", runtime.NumGoroutine())23 fmt.Println("GOMAXPROCS:", runtime.GOMAXPROCS(0))24 fmt.Println("NumCPU:", runtime.NumCPU())25 fmt.Println("NumGoroutine:", runtime.NumGoroutine())26 fmt.Println("GOMAXPROCS:", runtime.GOMAXPROCS(0))27 runtime.GOMAXPROCS(1)28 fmt.Println("NumCPU:", runtime.NumCPU())29 fmt.Println("NumGoroutine:", runtime.NumGoroutine())30 fmt.Println("GOMAXPROCS:", runtime.GOMAXPROCS(0))31 fmt.Println("NumCPU:", runtime.NumCPU())32 fmt.Println("NumGoroutine:", runtime.NumGoroutine())

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3fmt.Println("main class")4bench()5}6func bench() {7fmt.Println("bench method")8}9import "fmt"10func main() {11fmt.Println("main class")12bench()13}14func bench() {15fmt.Println("bench method")16}17import "fmt"18func main() {19fmt.Println("main class")20bench()21}22func bench() {23fmt.Println("bench method")24}25import "fmt"26func main() {27fmt.Println("main class")28bench()29}30func bench() {31fmt.Println("bench method")32}33import "fmt"34func main() {35fmt.Println("main class")36bench()37}38func bench() {39fmt.Println("bench method")40}41import "fmt"42func main() {43fmt.Println("main class")44bench()45}46func bench() {47fmt.Println("bench method")48}49import "fmt"50func main() {51fmt.Println("main class")52bench()53}54func bench() {55fmt.Println("bench method")56}57import "fmt"58func main() {59fmt.Println("main class")60bench()61}62func bench() {63fmt.Println("bench method")64}

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 bench()5}6func bench() {7 fmt.Println("bench method")8}9import "fmt"10func main() {11 fmt.Println("Hello, playground")12 bench()13}14func bench() {15 fmt.Println("bench method")16}17import "fmt"18func main() {19 fmt.Println("Hello, playground")20 bench()21}22func bench() {23 fmt.Println("bench method")24}25import "fmt"26func main() {27 fmt.Println("Hello, playground")28 bench()29}30func bench() {31 fmt.Println("bench method")32}33import "fmt"34func main() {35 fmt.Println("Hello, playground")36 bench()37}38func bench() {39 fmt.Println("bench method")40}41import "fmt"42func main() {43 fmt.Println("Hello, playground")44 bench()45}46func bench() {47 fmt.Println("bench method")48}49import "fmt"50func main() {51 fmt.Println("Hello, playground")52 bench()53}54func bench() {55 fmt.Println("bench method")56}57import

Full Screen

Full Screen

bench

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 example22()5}6import (7func main() {8 fmt.Println("Hello, playground")9 example22()10}11import (12func main() {13 fmt.Println("Hello, playground")14 example22()15}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful