// 记录摘要信息。 func recordSummary( scheduler sched.Scheduler, detailSummary bool, record Record, stopNotifier <-chan byte) { go func() { // 等待调度器开启 waitForSchedulerStart(scheduler) // 准备 var prevSchedSummary sched.SchedSummary var prevNumGoroutine int var recordCount uint64 = 1 startTime := time.Now() for { // 查看监控停止通知器 select { case <-stopNotifier: return default: } // 获取摘要信息的各组成部分 currNumGoroutine := runtime.NumGoroutine() currSchedSummary := scheduler.Summary(" ") // 比对前后两份摘要信息的一致性。只有不一致时才会予以记录。 if currNumGoroutine != prevNumGoroutine || !currSchedSummary.Same(prevSchedSummary) { schedSummaryStr := func() string { if detailSummary { return currSchedSummary.Detail() } else { return currSchedSummary.String() } }() // 记录摘要信息 info := fmt.Sprintf(summaryForMonitoring, recordCount, currNumGoroutine, schedSummaryStr, time.Since(startTime).String(), ) record(0, info) prevNumGoroutine = currNumGoroutine prevSchedSummary = currSchedSummary recordCount++ } time.Sleep(time.Microsecond) } }() }