code: func (c *context) emit(e *event) {
  	if e.Timestamp == 0 {
  		e.Timestamp = fromDuration(time.Since(consts.start))
  	}
  	// sync.WaitGroup.Add() use atomic.AddUint64().
  	globals.wg.Add(1)
  	go func() {
  		defer globals.wg.Done()
  		e.Pid = c.pid
  		e.Tid = 1
  		// Locking is done in a goroutine to not create implicit synchronization
  		// when tracing.
  		globals.lockWriter.Lock()
  		defer globals.lockWriter.Unlock()
  		if globals.out != nil {
  			if globals.first {
  				globals.first = false
  			} else {
  				// Writing is done in a goroutine to reduce cost.
  				if _, err := globals.out.Write([]byte(",")); err != nil {
  					log.Printf("failed writing to trace: %s", err)
  					go Stop()
  					return
  				}
  			}
  			if err := globals.encoder.Encode(e); err != nil {
  				log.Printf("failed writing to trace: %s", err)
  				go Stop()
  			}
  		}
  	}()
  }
docs: // emit asynchronously emits a trace event.