// StartGoTrace turns on tracing, writing to the given file.
4562
func (h *HandlerT) StartGoTrace(file string) error {
	h.mu.Lock()
	defer h.mu.Unlock()
	if h.traceW != nil {
		return errors.New("trace already in progress")
	}
	f, err := os.Create(expandHome(file))
	if err != nil {
		return err
	}
	if err := trace.Start(f); err != nil {
		f.Close()
		return err
	}
	h.traceW = f
	h.traceFile = file
	log.Info("Go tracing started", "dump", h.traceFile)
	return nil
}
520256
func stopHTTPTrace() {
	if globalHTTPTraceFile != nil {
		reqInfo := (&logger.ReqInfo{}).AppendTags("traceFile", globalHTTPTraceFile.Name())
		ctx := logger.SetReqInfo(context.Background(), reqInfo)
		logger.LogIf(ctx, globalHTTPTraceFile.Close())
		globalHTTPTraceFile = nil
	}
}
159102
func (b *PlanBuilder) buildTrace(trace *ast.TraceStmt) (Plan, error) {
	if _, ok := trace.Stmt.(*ast.SelectStmt); !ok && trace.Format == "row" {
		return nil, errors.New("trace only supports select query when format is row")
	}

	p := &Trace{StmtNode: trace.Stmt, Format: trace.Format}

	switch trace.Format {
	case "row":
		retFields := []string{"operation", "duration", "spanID"}
		schema := expression.NewSchema(make([]*expression.Column, 0, len(retFields))...)
		schema.Append(buildColumn("", "operation", mysql.TypeString, mysql.MaxBlobWidth))
		schema.Append(buildColumn("", "startTS", mysql.TypeString, mysql.MaxBlobWidth))
		schema.Append(buildColumn("", "duration", mysql.TypeString, mysql.MaxBlobWidth))
		p.SetSchema(schema)
	case "json":
		retFields := []string{"json"}
		schema := expression.NewSchema(make([]*expression.Column, 0, len(retFields))...)
		schema.Append(buildColumn("", "operation", mysql.TypeString, mysql.MaxBlobWidth))
		p.SetSchema(schema)
	default:
		return nil, errors.New("trace format should be one of 'row' or 'json'")
	}
	return p, nil
}
649394
func PrintTrace(w io.Writer, r *Rego) {
	if r == nil || r.tracebuf == nil {
		return
	}
	topdown.PrettyTrace(w, *r.tracebuf)
}
1141338
func (writer *baseFileWriter) Tracef(format string, args ...interface{}) {
	if nil == writer.blog || TRACE < writer.blog.Level() {
		return
	}

	writer.writef(TRACE, format, args...)
}
1207329
func (t *CliLogBoxTask) Start(wg *sync.WaitGroup) golib.StopChan {
	if t.Update == nil {
		return golib.NewStoppedChan(errors.New("CliLogBoxTask.Update cannot be nil"))
	}
	t.InterceptLoggers()
	t.updateTask = &golib.LoopTask{
		Description: "CliLogBoxTask",
		StopHook: func() {
			err := t.updateBox() // One last screen refresh to make sure no messages get lost.
			t.RestoreLoggers()
			golib.Printerr(err)
		},
		Loop: func(stop golib.StopChan) (err error) {
			err = t.updateBox()
			if err == nil {
				// Wait between t.MinUpdateInterval and t.UpdateInterval,
				// but wake up from stop.WaitChan() and t.updateTrigger.
				sleepStart := time.Now()
				select {
				case <-time.After(t.UpdateInterval):
				case <-stop.WaitChan():
				case <-t.updateTrigger:
				}
				sleepTime := time.Now().Sub(sleepStart)
				if diff := t.MinUpdateInterval - sleepTime; diff > 0 {
					select {
					// Don't wait for t.updateTrigger here
					case <-time.After(diff):
					case <-stop.WaitChan():
					}
				}
			}
			return
		},
	}
	return t.updateTask.Start(wg)
}
1155097
func (h *HandlerT) StartCPUProfile(file string) error {
	h.mu.Lock()
	defer h.mu.Unlock()
	if h.cpuW != nil {
		return errors.New("CPU profiling already in progress")
	}
	f, err := os.Create(expandHome(file))
	if err != nil {
		return err
	}
	if err := pprof.StartCPUProfile(f); err != nil {
		f.Close()
		return err
	}
	h.cpuW = f
	h.cpuFile = file
	log.Info("CPU profiling started", "dump", h.cpuFile)
	return nil
}
1044969
func (x *XRaySpanSink) Start(cl *trace.Client) error {
	x.traceClient = cl

	xrayDaemon, err := net.ResolveUDPAddr("udp", x.daemonAddr)
	if err != nil {
		return err
	}
	conn, err := net.DialUDP("udp", nil, xrayDaemon)
	if err != nil {
		return err
	}
	x.conn = conn

	return nil
}
862987
func (s *EventStore) StartTracing() {
	s.traceMu.Lock()
	defer s.traceMu.Unlock()

	s.tracing = true
}
627369
func (c *Gcd) StartProcessCustom(cmd *exec.Cmd, userDir, port string) error {
	c.port = port
	c.addr = fmt.Sprintf("%s:%s", c.host, c.port)
	c.profileDir = userDir
	c.apiEndpoint = fmt.Sprintf("http://%s/json", c.addr)
	c.chromeCmd = cmd

	return c.startProcess()
}
979487
func (mt MongoTail) Start(dbSession *DbSession) {
	// nil options get initialized to gtm.DefaultOptions()
	bd := time.Duration(750) * time.Millisecond
	options := &gtm.Options{
		After:               nil,        // if nil defaults to LastOpTimestamp
		Filter:              nil,        // only receive inserts in this collection
		OpLogDatabaseName:   nil,        // defaults to "local"
		OpLogCollectionName: nil,        // defaults to a collection prefixed "oplog."
		CursorTimeout:       nil,        // defaults to 100s
		ChannelSize:         20,         // defaults to 20
		BufferSize:          20,         // defaults to 50. used to batch fetch documents on bursts of activity
		BufferDuration:      bd,         // defaults to 750 ms. after this timeout the batch is force fetched
		WorkerCount:         5,          // defaults to 1. number of go routines batch fetching concurrently
		Ordering:            gtm.Oplog,  // defaults to gtm.Oplog. ordering guarantee of events on the output channel
		UpdateDataAsDelta:   false,      // set to true to only receive delta information in the Data field on updates (info straight from oplog)
		DirectReadNs:        []string{}, // set to a slice of namespaces to read data directly from bypassing the oplog
		DirectReadFilter:    nil,
	}
	ctx := gtm.Start(dbSession.Session, options)
	// ctx.OpC is a channel to read ops from
	// ctx.ErrC is a channel to read errors from
	// ctx.Stop() stops all go routines started by gtm.Start
	go func() {
		ctx.DirectReadWg.Wait()
		fmt.Println("[GMGO] imported all the collections")
	}()

	mt.listen(ctx)
}
248597
func trace(message string, err error) {
	pc := make([]uintptr, 10)
	runtime.Callers(2, pc)
	f := runtime.FuncForPC(pc[0])
	file, line := f.FileLine(pc[0])
	if err != nil {
		log.Printf("%s:%d %s: %s\n", file, line, f.Name(), err)
	} else {
		log.Printf("%s:%d %s: %s\n", file, line, f.Name(), message)
	}
}
780069
func getTrace(errs ...error) string {
	for _, err := range errs {
		if err != nil {
			terr, ok := err.(stackTracer)
			if ok {
				return fmt.Sprintf("%+v", terr.StackTrace())
			}
		}
	}
	return E_EMPTY_TRACE
}
246582
func Start() {
	connect()
	go startBatcher(commonBatchStream)

	for i := range registry {
		debug("starting", registry[i])
		go registry[i].StartLoop()
	}
}
576385
func (q *Queryx) Trace(trace gocql.Tracer) *Queryx {
	q.Query.Trace(trace)
	return q
}
967274
func (c Configuration) InitGlobalTracer(
	serviceName string,
	options ...Option,
) (io.Closer, error) {
	if c.Disabled {
		return &nullCloser{}, nil
	}
	tracer, closer, err := c.New(serviceName, options...)
	if err != nil {
		return nil, err
	}
	opentracing.SetGlobalTracer(tracer)
	return closer, nil
}
315242
func stopTracing(ctx context.Context) {
	// Handle scenario where die() is called early in startup
	if ctx == nil {
		return
	}

	if !tracing {
		return
	}

	span := opentracing.SpanFromContext(ctx)
	if span != nil {
		span.Finish()
	}

	// report all possible spans to the collector
	tracerCloser.Close()

	tracing = false
	startTracingCalled = false
	stopTracingCalled = false
}