From cd143578fd6d35f45f98dc8b3539f9a92e35fc2c Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 10 Jan 2022 20:24:59 -0500 Subject: [PATCH] rename structs to match Julia style --- src/gc-alloc-profiler.cpp | 34 +++++++++++++++++----------------- src/gc-alloc-profiler.h | 10 +++++----- stdlib/Profile/src/Allocs.jl | 8 ++++---- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/gc-alloc-profiler.cpp b/src/gc-alloc-profiler.cpp index ca5b8f1e445ec..57337a20772a3 100644 --- a/src/gc-alloc-profiler.cpp +++ b/src/gc-alloc-profiler.cpp @@ -11,42 +11,42 @@ using std::string; using std::vector; -struct RawBacktrace { +struct jl_raw_backtrace_t { jl_bt_element_t *data; size_t size; }; -struct RawAlloc { +struct jl_raw_alloc_t { jl_datatype_t *type_address; - RawBacktrace backtrace; + jl_raw_backtrace_t backtrace; size_t size; }; // == These structs define the global singleton profile buffer that will be used by // callbacks to store profile results. == -struct PerThreadAllocProfile { - vector allocs; +struct jl_per_thread_alloc_profile_t { + vector allocs; }; -struct AllocProfile { +struct jl_alloc_profile_t { double sample_rate; - vector per_thread_profiles; + vector per_thread_profiles; }; -struct CombinedResults { - vector combined_allocs; +struct jl_combined_results { + vector combined_allocs; }; // == Global variables manipulated by callbacks == -AllocProfile g_alloc_profile; +jl_alloc_profile_t g_alloc_profile; int g_alloc_profile_enabled = false; -CombinedResults g_combined_results; // Will live forever. +jl_combined_results g_combined_results; // Will live forever. // === stack stuff === -RawBacktrace get_raw_backtrace() { +jl_raw_backtrace_t get_raw_backtrace() { // A single large buffer to record backtraces onto static jl_bt_element_t static_bt_data[JL_MAX_BT_SIZE]; @@ -57,7 +57,7 @@ RawBacktrace get_raw_backtrace() { jl_bt_element_t *bt_data = (jl_bt_element_t*) malloc(bt_bytes); memcpy(bt_data, static_bt_data, bt_bytes); - return RawBacktrace{ + return jl_raw_backtrace_t{ bt_data, bt_size }; @@ -70,14 +70,14 @@ extern "C" { // Needed since these functions doesn't take any arguments. JL_DLLEXPORT void jl_start_alloc_profile(double sample_rate) { // We only need to do this once, the first time this is called. while (g_alloc_profile.per_thread_profiles.size() < jl_n_threads) { - g_alloc_profile.per_thread_profiles.push_back(PerThreadAllocProfile{}); + g_alloc_profile.per_thread_profiles.push_back(jl_per_thread_alloc_profile_t{}); } g_alloc_profile.sample_rate = sample_rate; g_alloc_profile_enabled = true; } -JL_DLLEXPORT struct RawAllocResults jl_fetch_alloc_profile() { +JL_DLLEXPORT jl_raw_alloc_results_t jl_fetch_alloc_profile() { // combine allocs // TODO: interleave to preserve ordering for (auto& profile : g_alloc_profile.per_thread_profiles) { @@ -88,7 +88,7 @@ JL_DLLEXPORT struct RawAllocResults jl_fetch_alloc_profile() { profile.allocs.clear(); } - return RawAllocResults{ + return jl_raw_alloc_results_t{ g_combined_results.combined_allocs.data(), g_combined_results.combined_allocs.size(), }; @@ -129,7 +129,7 @@ void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size) JL_NOTSAFEPOIN } auto type = (jl_datatype_t*)jl_typeof(val); - profile.allocs.emplace_back(RawAlloc{ + profile.allocs.emplace_back(jl_raw_alloc_t{ type, get_raw_backtrace(), size diff --git a/src/gc-alloc-profiler.h b/src/gc-alloc-profiler.h index 7413ac4d019d5..cf363c3543fcd 100644 --- a/src/gc-alloc-profiler.h +++ b/src/gc-alloc-profiler.h @@ -15,15 +15,15 @@ extern "C" { // --------------------------------------------------------------------- // Forward-declaration to avoid depenency in header file. -struct RawAlloc; // Defined in gc-alloc-profiler.cpp +struct jl_raw_alloc_t; // Defined in gc-alloc-profiler.cpp -struct RawAllocResults { - struct RawAlloc *allocs; +typedef struct { + struct jl_raw_alloc_t *allocs; size_t num_allocs; -}; +} jl_raw_alloc_results_t; JL_DLLEXPORT void jl_start_alloc_profile(double sample_rate); -JL_DLLEXPORT struct RawAllocResults jl_fetch_alloc_profile(void); +JL_DLLEXPORT jl_raw_alloc_results_t jl_fetch_alloc_profile(void); JL_DLLEXPORT void jl_stop_alloc_profile(void); JL_DLLEXPORT void jl_free_alloc_profile(void); diff --git a/stdlib/Profile/src/Allocs.jl b/stdlib/Profile/src/Allocs.jl index b8e3e7e7b09a0..bb75ef3e40da2 100644 --- a/stdlib/Profile/src/Allocs.jl +++ b/stdlib/Profile/src/Allocs.jl @@ -8,20 +8,20 @@ using Base: InterpreterIP # The C jl_bt_element_t object contains either an IP pointer (size_t) or a void*. const BTElement = Csize_t; -# matches RawBacktrace on the C side +# matches jl_raw_backtrace_t on the C side struct RawBacktrace data::Ptr{BTElement} # in C: *jl_bt_element_t size::Csize_t end -# matches RawAlloc on the C side +# matches jl_raw_alloc_t on the C side struct RawAlloc type::Ptr{Type} backtrace::RawBacktrace size::Csize_t end -# matches RawAllocResults on the C side +# matches jl_raw_alloc_results_t on the C side struct RawAllocResults allocs::Ptr{RawAlloc} num_allocs::Csize_t @@ -115,7 +115,7 @@ struct AllocResults allocs::Vector{Alloc} end -# Without this, the Alloc's stacktrace prints for lines and lines and lines.. +# Without this, the Alloc's stacktrace prints for lines and lines and lines... function Base.show(io::IO, a::Alloc) stacktrace_sample = length(a.stacktrace) >= 1 ? "$(a.stacktrace[1]), ..." : "" print(io, "$Alloc($(a.type), $StackFrame[$stacktrace_sample], $(a.size))")