Skip to content

Commit 0295b50

Browse files
committed
feat: print profiling information into a folder per-file, instead of one large file
1 parent 3893b21 commit 0295b50

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ enable_testing()
4141
# Lean research options
4242
set (LEAN_RESEARCH_IS_REUSE_ACROSS_CONSTRUCTORS_ENABLED "0" CACHE STRING "research: enable reuse across constructors")
4343
message(STATUS "Research: reuse across ctor LEAN_RESEARCH_IS_REUSE_ACROSS_CONSTRUCTORS_ENABLED(${LEAN_RESEARCH_IS_REUSE_ACROSS_CONSTRUCTORS_ENABLED})")
44-
set (LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH "" CACHE STRING "research: path where compiler dumps info")
44+
set (LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH "/tmp/" CACHE STRING "research: folder where compiler dumps info")
4545
message(STATUS "Research: compiler profile CSV path LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH(${LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH})")
4646

4747
option(MULTI_THREAD "MULTI_THREAD" ON)

src/util/shell.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Author: Leonardo de Moura
4747
#include "util/path.h"
4848
#include "stdlib_flags.h"
4949

50-
namespace fs = std::filesystem;
50+
namespace fs = std::__fs::filesystem;
5151

5252

5353
#ifdef LEAN_TRACY
@@ -847,23 +847,31 @@ extern "C" LEAN_EXPORT int lean_main(int argc, char ** argv) {
847847
display_cumulative_profiling_times(std::cerr);
848848

849849

850-
fs::path profile_filename = std::string(fs::current_path() / *c_output);
850+
// take the output C path, normalize it, and use the normalized path for dumping CSV info.
851+
const fs::path canonical_c_outpath = [&]() {
852+
fs::path c_outpath = fs::absolute(fs::current_path() / (std::string(*c_output)));
853+
std::error_code ec;
854+
fs::path out = fs::canonical(c_outpath, ec);
855+
if (ec) { return c_outpath; }
856+
return out;
857+
}
858+
std::string profile_filename(std::string(canonical_c_outpath) + ".profile.csv");
851859
// replace all '/' with '+' in filepath to avoid creating subdirectories
852860
std::replace(profile_filename.begin(), profile_filename.end(), '/', '+');
853-
fs::path outdir = LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH;
861+
const fs::path outdir(LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH);
854862
assert(outdir.is_directory() && "LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH must be a directory");
855863
assert(outdir.is_absolute() && "LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH must be an absolute path");
856864
// make outdir if necessary
857865
if (!fs::exists(outdir)) { fs::create_directories(outdir); }
858-
fs::path profiling_path = outdir / profile_filename;
866+
const fs::path profiling_path = outdir / profile_filename;
859867

860868
if (profiling_path == "") {
861869
std::cerr << "WARN: LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH ('" << profiling_path << "') is empty";
862870
} else {
863871
if (profiling_path == "-") {
864872
profiler.write_profiling_times(mod_fn, profiling_path, std::cerr, c_output);
865873
} else {
866-
std::ofstream profiler_out_file(profiling_path, std::ios::app);
874+
std::ofstream profiler_out_file(profiling_path);
867875
profiler.write_profiling_times(mod_fn, profiling_path, profiler_out_file, c_output);
868876
}
869877
}

0 commit comments

Comments
 (0)