google / autofdo

AutoFDO
https://groups.google.com/forum/#!forum/autofdo
Apache License 2.0
520 stars 109 forks source link

Unable to create profile with create_llvm_prof - Empty profile map error #230

Open cristianassaiante opened 2 days ago

cristianassaiante commented 2 days ago

Hi, I'm trying to compile clang using AutoFDO. In order, I'm running the following (adapted from the propeller script):

cmake -G Ninja "${COMMON_CMAKE_FLAGS[@]}"\ ${PATH_TO_SOURCES}/llvm-project/llvm ninja -j 40 clang


- Use perf to obtain branch data

ninja -t commands | head -100 >& ./perf_commands.sh chmod +x ./perf_commands.sh perf record -j any,u ./perf_commands.sh


- Use create_llvm_prof to generate the profile
`create_llvm_prof --binary $PATH_TO_BINARIES/clang.baseline --out baseline.prof`

Everything succeeds, until the very last command which gives the following output:

[WARNING:/home/autofdo/third_party/perf_data_converter/src/quipper/perf_reader.cc:1322] Skipping 492 bytes of metadata: HEADER_CPU_TOPOLOGY [WARNING:autofdo/third_party/perf_data_converter/src/quipper/perf_reader.cc:1069] Skipping unsupported event PERF_RECORD_CPU_MAP [INFO:/home/autofdo/third_party/perf_data_converter/src/quipper/perf_reader.cc:1060] Number of events stored: 8366776 [INFO:/home/autofdo/third_party/perf_data_converter/src/quipper/perf_parser.cc:272] Parser processed: 1221 MMAP/MMAP2 events, 112 COMM events, 110 FORK events, 111 EXIT events, 8336706 SAMPLE events, 8287979 of these were mapped, 0 SAMPLE events with a data address, 0 of these were mapped WARNING: Logging before InitGoogleLogging() is written to STDERR I20240926 10:32:30.280131 89010 sample_reader.cc:289] No buildid found in binary I20240926 10:32:34.213464 89010 symbol_map.cc:477] Adding loadable exec segment: offset=1597000 vaddr=1597000 W20240926 10:32:42.118443 89010 llvm_profile_writer.cc:50] Got an empty profile map. The output file might still be not empty (e.g., containing symbol list in binary format) but might be not helpful as a profile



I have tested several configurations and also tried to use different perf option, but the outcome does not seems to change.

Thanks in advance.
snehasish commented 1 day ago

Can you drop the "DLLVM_BUILD_INSTRUMENTED=ON" flag? That shouldn't be necessary.

Can you confirm that clang.baseline is the one obtained from the build step above? Also check that the binary was built with debug info.

cc: @shenhanc78 can you take a look? Any ideas / tips to debug further? Thanks

snehasish commented 1 day ago

Looking at the error log again, since you are using a script to invoke perf multiple times, I think a build id is necessary to aggregate the samples correctly. Can you try building clang itself with an additional linker flag -Wl,--build-id=sha1?

shenhanc78 commented 1 day ago

Yes, buildid is required. You may also use --ignore_build_id to skip this test. So all "clang" binary events (instead of only clang binary with the same buildid as recorded in perf.data file) in the perf will be processed.