Skip to content

Commit 7c23f66

Browse files
committed
feat: log C file size
1 parent 5547b4d commit 7c23f66

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/util/shell.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Author: Leonardo de Moura
4646
#include "util/path.h"
4747
#include "stdlib_flags.h"
4848

49+
4950
#ifdef LEAN_TRACY
5051
#define TRACY_ENABLE
5152
#include "tracy/Tracy.hpp"
@@ -69,6 +70,21 @@ Author: Leonardo de Moura
6970
#include <dlfcn.h>
7071
#endif
7172

73+
std::streampos fileSize(const char* filePath) {
74+
75+
std::streampos fsize = 0;
76+
std::ifstream file( filePath, std::ios::binary );
77+
78+
fsize = file.tellg();
79+
file.seekg( 0, std::ios::end );
80+
fsize = file.tellg() - fsize;
81+
file.close();
82+
83+
return fsize;
84+
}
85+
86+
87+
7288
#ifdef _MSC_VER
7389
// extremely simple implementation of getopt.h
7490
enum arg_opt { no_argument, required_argument, optional_argument };
@@ -462,7 +478,7 @@ struct Profiler {
462478
: "reuse_across_ctor_disabled")
463479
<< "," << name << ", " << val << "\n";
464480
}
465-
void write_profiling_times(std::string src_path, std::string out_path, std::ostream &o) {
481+
void write_profiling_times(std::string src_path, std::string out_path, std::ostream &o, optional<std::string> c_file_path) {
466482
// if (research_isResearchLogVerbose()) {
467483
// std::cerr << "writing profiling information "
468484
// << "[reuseEnabled=" << (isReuseEnabled() ? "true" : "false")
@@ -493,10 +509,14 @@ struct Profiler {
493509
write_file_identifier<uint64_t>(o, src_path, "num_recycled_pages",
494510
lean::allocator::get_num_recycled_pages());
495511
#endif
512+
if (c_file_path) {
513+
write_file_identifier<uint64_t>(o, src_path, "c_file_size", uint64_t(fileSize((*c_file_path).c_str())));
514+
}
496515
write_file_identifier<uint64_t>(o, src_path, "time_elapsed_ms", time_elapsed_ms);
497516
}
498517
};
499518

519+
500520
extern "C" LEAN_EXPORT int lean_main(int argc, char ** argv) {
501521
Profiler profiler;
502522
#ifdef LEAN_EMSCRIPTEN
@@ -826,14 +846,14 @@ extern "C" LEAN_EXPORT int lean_main(int argc, char ** argv) {
826846

827847
const std::string profiling_path = LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH;
828848
if (profiling_path == "") {
829-
std::cerr << "WARN: '" << profiling_path << "' is empty";
830-
}
831-
832-
if (profiling_path == "-") {
833-
profiler.write_profiling_times(mod_fn, profiling_path, std::cerr);
849+
std::cerr << "WARN: LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH ('" << profiling_path << "') is empty";
834850
} else {
835-
std::ofstream profiler_out_file(profiling_path, std::ios::app);
836-
profiler.write_profiling_times(mod_fn, profiling_path, profiler_out_file);
851+
if (profiling_path == "-") {
852+
profiler.write_profiling_times(mod_fn, profiling_path, std::cerr, c_output);
853+
} else {
854+
std::ofstream profiler_out_file(profiling_path, std::ios::app);
855+
profiler.write_profiling_times(mod_fn, profiling_path, profiler_out_file, c_output);
856+
}
837857
}
838858
#ifdef LEAN_SMALL_ALLOCATOR
839859
// If the small allocator is not enabled, then we assume we are not using the sanitizer.

0 commit comments

Comments
 (0)