Add timings.

This commit is contained in:
Christoffer Lerno
2022-03-12 02:35:07 +01:00
parent 55598b2de8
commit 60d7c8aa14
4 changed files with 53 additions and 2 deletions

View File

@@ -5,6 +5,8 @@
#include "compiler_internal.h"
#ifndef _MSC_VER
#include <unistd.h>
#include <compiler_tests/benchmark.h>
#endif
#define MAX_OUTPUT_FILES 1000000
@@ -16,11 +18,22 @@ Vmem ast_arena;
Vmem expr_arena;
Vmem decl_arena;
Vmem type_info_arena;
double compiler_init_time;
double compiler_parsing_time;
double compiler_sema_time;
double compiler_ir_gen_time;
double compiler_codegen_time;
double compiler_link_time;
void compiler_init(const char *std_lib_dir)
{
compiler_init_time = -1;
compiler_parsing_time = -1;
compiler_sema_time = -1;
compiler_ir_gen_time = -1;
compiler_codegen_time = -1;
compiler_link_time = -1;
DEBUG_LOG("Version: %s", COMPILER_VERSION);
global_context = (GlobalContext ){ .in_panic_mode = false };
@@ -155,6 +168,20 @@ static void free_arenas(void)
if (debug_stats) print_arena_status();
}
static void compiler_print_bench(void)
{
if (debug_stats)
{
printf("Timings\n");
printf("-------\n");
if (compiler_init_time >= 0) printf("Initialization took: %.4f ms\n", compiler_init_time * 1000);
if (compiler_parsing_time >= 0) printf("Parsing took: %.4f ms\n", (compiler_parsing_time - compiler_init_time) * 1000);
if (compiler_sema_time >= 0) printf("Analysis took: %.4f ms\n", (compiler_sema_time - compiler_parsing_time) * 1000);
if (compiler_ir_gen_time >= 0) printf("Ir gen took: %.4f ms\n", (compiler_ir_gen_time - compiler_sema_time) * 1000);
if (compiler_codegen_time >= 0) printf("Codegen took: %.4f ms\n", (compiler_codegen_time - compiler_ir_gen_time) * 1000);
if (compiler_link_time >= 0) printf("Linking took: %.4f ms\n", (compiler_link_time - compiler_codegen_time) * 1000);
}
}
void compiler_compile(void)
{
@@ -213,6 +240,7 @@ void compiler_compile(void)
default:
UNREACHABLE
}
compiler_ir_gen_time = bench_mark();
free_arenas();
@@ -273,6 +301,7 @@ void compiler_compile(void)
output_file_count += cfiles;
free(compile_data);
compiler_codegen_time = bench_mark();
if (create_exe)
{
@@ -280,9 +309,12 @@ void compiler_compile(void)
if (active_target.arch_os_target == default_target)
{
platform_linker(output_name, obj_files, output_file_count);
compiler_link_time = bench_mark();
compiler_print_bench();
}
else
{
compiler_print_bench();
if (!obj_format_linking_supported(platform_target.object_format) || !linker(output_name, obj_files,
output_file_count))
{
@@ -290,6 +322,7 @@ void compiler_compile(void)
active_target.run_after_compile = false;
}
}
if (active_target.run_after_compile)
{
printf("Launching %s...\n", output_name);
@@ -482,15 +515,20 @@ void compile()
type_init_cint();
compiler_init_time = bench_mark();
if (!vec_size(active_target.sources)) error_exit("No files to compile.");
if (active_target.lex_only)
{
compiler_lex();
compiler_parsing_time = bench_mark();
return;
}
if (active_target.parse_only)
{
compiler_parse();
compiler_parsing_time = bench_mark();
return;
}
compiler_compile();

View File

@@ -15,3 +15,10 @@ void init_default_build_target(BuildTarget *target, BuildOptions *options);
void symtab_init(uint32_t max_size);
void symtab_destroy();
void print_syntax(BuildOptions *options);
extern double compiler_init_time;
extern double compiler_parsing_time;
extern double compiler_sema_time;
extern double compiler_ir_gen_time;
extern double compiler_codegen_time;
extern double compiler_link_time;

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by the GNU LGPLv3.0 license
// a copy of which can be found in the LICENSE file.
#include <compiler_tests/benchmark.h>
#include "sema_internal.h"
void sema_shadow_error(Decl *decl, Decl *old)
@@ -286,6 +287,7 @@ void sema_analysis_run(void)
if (!parse_file(file)) has_error = true;
}
if (has_error) exit_compiler(EXIT_FAILURE);
compiler_parsing_time = bench_mark();
// All global defines are added to the std module
global_context.std_module_path = (Path) { .module = kw_std, .span = INVALID_SPAN, .len = (uint32_t) strlen(kw_std) };
@@ -316,6 +318,7 @@ void sema_analysis_run(void)
{
sema_analyze_to_stage(stage);
}
compiler_sema_time = bench_mark();
}

View File

@@ -1,3 +1,4 @@
#include <compiler_tests/benchmark.h>
#include "compiler/compiler.h"
#include "build/build_options.h"
#include "build/project_creation.h"
@@ -24,6 +25,8 @@ static void cleanup()
int main_real(int argc, const char *argv[])
{
bench_begin();
int result = setjmp(on_error_jump);
if (result)
{