Florian Ragwitz pushed to branch wip/rafl/hpc-tixdir at Glasgow Haskell Compiler / GHC

Commits:

4 changed files:

Changes:

  • .gitlab/ci.sh
    ... ... @@ -54,6 +54,7 @@ Common Modes:
    54 54
       clean             Clean the tree
    
    55 55
       shell             Run an interactive shell with a configured build environment.
    
    56 56
       save_test_output  Generate unexpected-test-output.tar.gz
    
    57
    +  save_hpc_coverage Generate ghc-hpc-coverage.tar.gz
    
    57 58
       save_cache        Preserve the cabal cache
    
    58 59
       build_hadrian     Build GHC via the Hadrian build system
    
    59 60
       test_hadrian      Test GHC via the Hadrian build system
    
    ... ... @@ -649,6 +650,13 @@ function install_bindist() {
    649 650
     }
    
    650 651
     
    
    651 652
     function test_hadrian() {
    
    653
    +  if [[ "${BUILD_FLAVOUR:-}" == *+coverage* ]]; then
    
    654
    +    export HPCTIX2=1
    
    655
    +    # GHC invocations run in per-test working directories.
    
    656
    +    export HPCTIXDIR="$TOP/_build/ghc-tix"
    
    657
    +    mkdir -p "$HPCTIXDIR"
    
    658
    +  fi
    
    659
    +
    
    652 660
       check_msys2_deps _build/stage1/bin/ghc --version
    
    653 661
       check_release_build
    
    654 662
     
    
    ... ... @@ -898,6 +906,16 @@ function save_test_output() {
    898 906
         tar -czf unexpected-test-output.tar.gz unexpected-test-output
    
    899 907
     }
    
    900 908
     
    
    909
    +function save_hpc_coverage() {
    
    910
    +  # Keep whatever has been generated even if the build or tests failed.
    
    911
    +  if [[ -d _build/ghc-hpc || -d _build/ghc-tix ]]; then
    
    912
    +    mkdir -p _build/ghc-hpc _build/ghc-tix
    
    913
    +    tar -czf ghc-hpc-coverage.tar.gz _build/ghc-hpc _build/ghc-tix
    
    914
    +  else
    
    915
    +    warn "No HPC coverage directories found"
    
    916
    +  fi
    
    917
    +}
    
    918
    +
    
    901 919
     function save_cache () {
    
    902 920
       info "Storing cabal cache from $CABAL_DIR to $CABAL_CACHE..."
    
    903 921
       rm -Rf "$CABAL_CACHE"
    
    ... ... @@ -934,7 +952,8 @@ function clean() {
    934 952
           --exclude=ci_timings.txt \
    
    935 953
           --exclude=ghc-*.tar.xz \
    
    936 954
           --exclude=junit.xml \
    
    937
    -      --exclude=unexpected-test-output.tar.gz
    
    955
    +      --exclude=unexpected-test-output.tar.gz \
    
    956
    +      --exclude=ghc-hpc-coverage.tar.gz
    
    938 957
       fi
    
    939 958
     }
    
    940 959
     
    

  • .gitlab/generate-ci/gen_ci.hs
    ... ... @@ -998,7 +998,21 @@ delVariable k j = j { jobVariables = MonoidalMap $ Map.delete k $ unMonoidalMap
    998 998
     
    
    999 999
     -- | Make a normal validate CI job
    
    1000 1000
     validate :: Arch -> Opsys -> BuildConfig -> NamedJob Job
    
    1001
    -validate = job
    
    1001
    +validate arch opsys bc =
    
    1002
    +  let NamedJob n j = job arch opsys bc
    
    1003
    +      covered = setVariable "BUILD_FLAVOUR"
    
    1004
    +                  (flavourString (mkJobFlavour bc) ++ "+coverage") j
    
    1005
    +      saveCoverage = (if opsys == Windows then "bash " else "")
    
    1006
    +                     ++ ".gitlab/ci.sh save_hpc_coverage"
    
    1007
    +  in NamedJob
    
    1008
    +       { name = n
    
    1009
    +       , jobInfo = covered
    
    1010
    +           { jobAfterScript = saveCoverage : jobAfterScript covered
    
    1011
    +           , jobArtifacts = (jobArtifacts covered)
    
    1012
    +               { artifactPaths = artifactPaths (jobArtifacts covered)
    
    1013
    +                                 ++ ["ghc-hpc-coverage.tar.gz"] }
    
    1014
    +           }
    
    1015
    +       }
    
    1002 1016
     
    
    1003 1017
     -- Nightly and release apply the FastCI configuration to all jobs so that they all run in
    
    1004 1018
     -- the pipeline (not conditional on the full-ci label)
    

  • hadrian/src/Flavour.hs
    ... ... @@ -86,6 +86,7 @@ flavourTransformers = M.fromList
    86 86
         , "dump_stg"         =: enableDumpStg
    
    87 87
         , "hash_unit_ids"    =: enableHashUnitIds
    
    88 88
         , "hie_files"        =: enableHieFiles
    
    89
    +    , "coverage"         =: enableCoverage
    
    89 90
         ]
    
    90 91
       where (=:) = (,)
    
    91 92
     
    
    ... ... @@ -383,6 +384,11 @@ enableHashUnitIds flavour = flavour { hashUnitIds = True }
    383 384
     enableHieFiles :: Flavour -> Flavour
    
    384 385
     enableHieFiles flavour = flavour { ghcHieFiles = (>= Stage1) }
    
    385 386
     
    
    387
    +enableCoverage :: Flavour -> Flavour
    
    388
    +enableCoverage =
    
    389
    +  addArgs $ stage1 ? builder (Ghc CompileHs) ? packageOneOf [compiler, ghc] ?
    
    390
    +    pure ["-fhpc", "-hpcdir", "_build/ghc-hpc"]
    
    391
    +
    
    386 392
     -- | Build stage2 compiler with -fomit-interface-pragmas to reduce
    
    387 393
     -- recompilation.
    
    388 394
     omitPragmas :: Flavour -> Flavour
    

  • rts/Hpc.c
    ... ... @@ -314,6 +314,57 @@ hs_hpc_module(char *modName,
    314 314
       }
    
    315 315
     }
    
    316 316
     
    
    317
    +static void writeULEB128(FILE *f, StgWord64 value) {
    
    318
    +  do {
    
    319
    +    unsigned int byte = (unsigned int)(value & 0x7f);
    
    320
    +    value >>= 7;
    
    321
    +    if (value != 0) byte |= 0x80;
    
    322
    +    fputc(byte, f);
    
    323
    +  } while (value != 0);
    
    324
    +}
    
    325
    +
    
    326
    +static void writeLE32(FILE *f, StgWord32 value) {
    
    327
    +  for (unsigned int shift = 0; shift < 32; shift += 8)
    
    328
    +    fputc((int)((value >> shift) & 0xff), f);
    
    329
    +}
    
    330
    +
    
    331
    +static void writeTix2(FILE *f) {
    
    332
    +  if (f == NULL) return;
    
    333
    +
    
    334
    +  StgWord64 moduleCount = 0;
    
    335
    +  for (HpcModuleInfo *m = modules; m != NULL; m = m->next)
    
    336
    +    moduleCount++;
    
    337
    +
    
    338
    +  fwrite("HPCTIX\0", 1, 7, f);
    
    339
    +  writeULEB128(f, moduleCount);
    
    340
    +
    
    341
    +  for (HpcModuleInfo *m = modules; m != NULL; m = m->next) {
    
    342
    +    size_t nameLength = strlen(m->modName);
    
    343
    +    writeULEB128(f, (StgWord64)nameLength);
    
    344
    +    fwrite(m->modName, 1, nameLength, f);
    
    345
    +    writeLE32(f, m->hashNo);
    
    346
    +    writeULEB128(f, m->tickCount);
    
    347
    +
    
    348
    +    const StgWord64 *counts = m->tixArr;
    
    349
    +    StgWord32 i = 0;
    
    350
    +
    
    351
    +    while (i < m->tickCount) {
    
    352
    +      StgWord32 zeroStart = i;
    
    353
    +      while (i < m->tickCount && (counts == NULL || counts[i] == 0)) i++;
    
    354
    +      StgWord32 nonzeroStart = i;
    
    355
    +      while (i < m->tickCount && counts != NULL && counts[i] != 0) i++;
    
    356
    +      writeULEB128(f, nonzeroStart - zeroStart);
    
    357
    +      writeULEB128(f, i - nonzeroStart);
    
    358
    +      for (StgWord32 j = nonzeroStart; j < i; j++)
    
    359
    +        writeULEB128(f, counts[j]);
    
    360
    +    }
    
    361
    +  }
    
    362
    +
    
    363
    +  bool writeFailed = ferror(f) != 0;
    
    364
    +  if (fclose(f) != 0 || writeFailed)
    
    365
    +    failure("could not write binary .tix file");
    
    366
    +}
    
    367
    +
    
    317 368
     static void
    
    318 369
     writeTix(FILE *f) {
    
    319 370
       HpcModuleInfo *tmpModule;
    
    ... ... @@ -387,7 +438,7 @@ static FILE *uniqueFile(const char *dir) {
    387 438
       FILE *f = NULL;
    
    388 439
       for (unsigned int i = 0; i < UINT_MAX; i++) {
    
    389 440
         snprintf(name, (size_t)len + 1, fmt, dir, prog_name, (int)hpc_pid, i);
    
    390
    -    f = __rts_fopen(name, "wx");
    
    441
    +    f = __rts_fopen(name, "wbx");
    
    391 442
         if (f != NULL || errno != EEXIST)
    
    392 443
           break;
    
    393 444
       }
    
    ... ... @@ -418,7 +469,8 @@ exitHpc(void) {
    418 469
     #endif
    
    419 470
       if (!is_subprocess && RtsFlags.HpcFlags.writeTixFile) {
    
    420 471
         FILE *f = tixDir != NULL ? uniqueFile(tixDir) : __rts_fopen(tixFilename, "w+");
    
    421
    -    writeTix(f);
    
    472
    +    if (getenv("HPCTIX2")) writeTix2(f);
    
    473
    +    else writeTix(f);
    
    422 474
       }
    
    423 475
     
    
    424 476
       freeStrHashTable(moduleHash, (void (*)(void *))freeHpcModuleInfo);