Coverage for deamon

To the best of my knowledge, it’s advisable to have goc installed on the compilation machine.

The mechanism behind goc operates as follows: the compiler (goc) inserts coverage-related statements into your code before feeding them into the compiler.

  1. It copies the project into /tmp/goc-build-${hash}/. This folder will be deleted after compilation, but you can use goc build --debug to retain it for further investigation.
  2. It parses the source code into an AST (abstract syntax tree).
  3. Coverage counting statements are added at the beginning of every Basic Block.
  4. The source code of the dedicated web server (http_cover_apis_auto_generated.go) is copied and imported into your project, responsible for collecting coverage data.
  5. Finally, it compiles the modified project.

This process is similar to how coverage data is collected when using go test -cover. You can read more about it in this blog post.

You can observe the modified source code under /tmp/goc-build-${hash}. The modified source code will resemble the following (notice the counter variable, e.g., GoCover_0_373131613736336566316238.Count):

func main() { GoCover_0_373131613736336566316238.Count[2]++;
    total := 256
    scheduler := gojob.New().Start()
    for i := 0; i < total; i++ { GoCover_0_373131613736336566316238.Count[4]++;
        scheduler.Submit(New(i, rand.Intn(10)))
    }
    GoCover_0_373131613736336566316238.Count[3]++; scheduler.Wait()
}

Regarding your question, is there a way to modify the output binaries to use goc?

The answer is yes, but it would be tricky and ungraceful, especially if you need to send the modified project to the compilation machine.