| 1 | // Copyright (c) 2024 Felipe Pena and Delyan Angelov. All rights reserved. |
| 2 | // Use of this source code is governed by an MIT license |
| 3 | // that can be found in the LICENSE file. |
| 4 | module main |
| 5 | |
| 6 | // vcounter_*.csv files contain counter lines in a CSV format. They can get quite large, |
| 7 | // for big programs, since they contain all non zero coverage counters. |
| 8 | // Their names are timestamp (rand.ulid + clock_gettime) based, to minimise the chance that parallel runs |
| 9 | // will overwrite each other, but without the overhead of additional synchronisation/locks. |
| 10 | struct CounterLine { |
| 11 | mut: |
| 12 | file string // retrieved based on the loaded meta |
| 13 | line int // retrieved based on the loaded meta |
| 14 | |
| 15 | meta string // A filename in the sibling meta/ folder, should exist, to match the value from this field. The filename is a hash of both the path and the used build options, to facilitate merging coverage data from different builds/programs |
| 16 | point int // The index of a source point. Note that it is not a line number, but an index in the meta data file, keyed by the field `meta` above. |
| 17 | hits u64 // How many times the coverage point was executed. Only counters that are != 0 are recorded. |
| 18 | } |
| 19 | |
| 20 | // Source metadata files in meta/*.txt, contain JSON encoded fields (mappings from v source files to point line numbers). |
| 21 | // Their names are a result of a hashing function, applied over both the source file name, and the build options. |
| 22 | // This has several benefits: |
| 23 | // a) it makes sure, that the resulting path is normalised |
| 24 | // b) the meta data is deduplicated between runs that use the same source files |
| 25 | // c) coverage data from different runs can be merged by simply reusing the same -coverage folder, |
| 26 | // or by copy/pasting all files from 1 run, to the folder of another. |
| 27 | struct MetaData { |
| 28 | file string // V source file path |
| 29 | fhash string // fhash is the name of the meta file |
| 30 | v_version string // the V version, used to generate the coverage meta data file |
| 31 | build_options string // the build options for the program |
| 32 | npoints int // the number of stored coverage points |
| 33 | points []int // the line numbers corresponding to each point |
| 34 | } |
| 35 | |