// getCovCounterList returns a list of counter-data blobs registered // for the currently executing instrumented program. It is defined in the // runtime. // //go:linkname getCovCounterList func getCovCounterList() []rtcov.CovCounterBlob type emitState … var finalHash … var finalHashComputed … var finalMetaLen … var metaDataEmitAttempted … var cmode … var cgran … var goCoverDir … var capturedOsArgs … var covProfileAlreadyEmitted … type fileType … const noFile … const metaDataFile … const counterDataFile … // emitMetaData emits the meta-data output file for this coverage run. // This entry point is intended to be invoked by the compiler from // an instrumented program's main package init func. func emitMetaData() { … } func modeClash(m coverage.CounterMode) bool { … } func granClash(g coverage.CounterGranularity) bool { … } // prepareForMetaEmit performs preparatory steps needed prior to // emitting a meta-data file, notably computing a final hash of // all meta-data blobs and capturing os args. func prepareForMetaEmit() ([]rtcov.CovMetaBlob, error) { … } // emitMetaDataToDirectory emits the meta-data output file to the specified // directory, returning an error if something went wrong. func emitMetaDataToDirectory(outdir string, ml []rtcov.CovMetaBlob) error { … } // emitCounterData emits the counter data output file for this coverage run. // This entry point is intended to be invoked by the runtime when an // instrumented program is terminating or calling os.Exit(). func emitCounterData() { … } // emitCounterDataToDirectory emits the counter-data output file for this coverage run. func emitCounterDataToDirectory(outdir string) error { … } // emitCounterDataToWriter emits counter data for this coverage run to an io.Writer. func (s *emitState) emitCounterDataToWriter(w io.Writer) error { … } // openMetaFile determines whether we need to emit a meta-data output // file, or whether we can reuse the existing file in the coverage out // dir. It updates mfname/mftmp/mf fields in 's', returning an error // if something went wrong. See the comment on the emitState type // definition above for more on how file opening is managed. func (s *emitState) openMetaFile(metaHash [16]byte, metaLen uint64) error { … } // openCounterFile opens an output file for the counter data portion // of a test coverage run. If updates the 'cfname' and 'cf' fields in // 's', returning an error if something went wrong. func (s *emitState) openCounterFile(metaHash [16]byte) error { … } // openOutputFiles opens output files in preparation for emitting // coverage data. In the case of the meta-data file, openOutputFiles // may determine that we can reuse an existing meta-data file in the // outdir, in which case it will leave the 'mf' field in the state // struct as nil. If a new meta-file is needed, the field 'mfname' // will be the final desired path of the meta file, 'mftmp' will be a // temporary file, and 'mf' will be an open os.File pointer for // 'mftmp'. The idea is that the client/caller will write content into // 'mf', close it, and then rename 'mftmp' to 'mfname'. This function // also opens the counter data output file, setting 'cf' and 'cfname' // in the state struct. func (s *emitState) openOutputFiles(metaHash [16]byte, metaLen uint64, which fileType) error { … } // emitMetaDataFile emits coverage meta-data to a previously opened // temporary file (s.mftmp), then renames the generated file to the // final path (s.mfname). func (s *emitState) emitMetaDataFile(finalHash [16]byte, tlen uint64) error { … } // needMetaDataFile returns TRUE if we need to emit a meta-data file // for this program run. It should be used only after // openOutputFiles() has been invoked. func (s *emitState) needMetaDataFile() bool { … } func writeMetaData(w io.Writer, metalist []rtcov.CovMetaBlob, cmode coverage.CounterMode, gran coverage.CounterGranularity, finalHash [16]byte) error { … } func (s *emitState) VisitFuncs(f encodecounter.CounterVisitorFn) error { … } // captureOsArgs converts os.Args() into the format we use to store // this info in the counter data file (counter data file "args" // section is a generic key-value collection). See the 'args' section // in internal/coverage/defs.go for more info. The args map // is also used to capture GOOS + GOARCH values as well. func captureOsArgs() map[string]string { … } // emitCounterDataFile emits the counter data portion of a // coverage output file (to the file 's.cf'). func (s *emitState) emitCounterDataFile(finalHash [16]byte, w io.Writer) error { … } // MarkProfileEmitted signals the coverage machinery that // coverage data output files have already been written out, and there // is no need to take any additional action at exit time. This // function is called from the coverage-related boilerplate code in _testmain.go // emitted for go unit tests. func MarkProfileEmitted(val bool) { … } func reportErrorInHardcodedList(slot, pkgID int32, fnID, nCtrs uint32) { … }