846301bcaf
* Address and thread sanitizer fixes - Fix compilation with clang - Tweak perfetto copy to build tree - Added suppression files to scripts - fix LD_PRELOAD support in omnitrace-causal and omnitrace-sample - use spin_mutex and spin_lock from timemory instead of atomic_mutex and atomic_lock - state uses atomic - fix some memory leaks - tweak testing - mpi tests do not use preload - increase timeout when using sanitizers - add env LD_PRELOAD when using sanitizers * Tweak perfetto build * Update timemory submodule * Update version to 1.8.1 * Update omnitrace-leak.supp * Update timemory submodule - fixed spin_mutex implementation * Remove previously added addr_space->allowTraps(instr_traps) - this appears to cause errors during binary rewrite * causal testing updates - relaxed causal validation on CI systems (to account for hyperthreading decreasing prediction) - improved impact calculation - other general improvements to validate-causal-json.py * Improve fork handling for perfetto - numerous updates changing perfetto:: to ::perfetto:: - added perfetto_fwd.hpp * Updated fork example - user API for validation that stopping/starting perfetto is valid * Misc fixes to perfetto + fork support - tweak regions in fork example - handle disabling tmp files - get rid of stop/start with perfetto before/after fork - fixed sampling support during fork - tweak env of fork test * Fix find_package in build-tree * Fix buildtree export * Fix buildtree export * Restructured ConfigInstall before adding examples * Guard against creating tmp file in sampling when disabled * Fix buildtree package * formatting * exit handlers on child processes - quick exit to avoid perfetto cleanup * Further tweaking of causal tests for reliability - enable PROCESSOR_AFFINITY - decrease to 5 iterations * Further tweaking of causal tests for reliability - disable PROCESSOR_AFFINITY for fast func e2e tests - enabling affinity results in (valid) speedup predictions greater than zero * Fixes to fork handling - use pthread_atfork for redundancy if fork_gotcha fails * cmake formatting * Fix fork init settings + install components - remove dl from PROJECT_BUILD_TARGETS * Testing tweaks - fix mpi-binary-rewrite-run regex when OMNITRACE_VERBOSE set > 1 in env - increase causal e2e iterations to 8 * Fix "Test User API" - test-find-package.sh included dl component * Further tweaks to causal validation - further considerations of variance
176 خطوط
4.6 KiB
C++
176 خطوط
4.6 KiB
C++
// MIT License
|
|
//
|
|
// Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
// copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
// SOFTWARE.
|
|
|
|
#include "state.hpp"
|
|
#include "config.hpp"
|
|
#include "debug.hpp"
|
|
#include "utility.hpp"
|
|
|
|
#include <atomic>
|
|
#include <string>
|
|
|
|
namespace omnitrace
|
|
{
|
|
namespace
|
|
{
|
|
auto&
|
|
get_state_value()
|
|
{
|
|
static auto _v = std::atomic<State>{ State::PreInit };
|
|
return _v;
|
|
}
|
|
|
|
ThreadState&
|
|
get_thread_state_value()
|
|
{
|
|
static thread_local auto _v = ThreadState{ ThreadState::Enabled };
|
|
return _v;
|
|
}
|
|
|
|
auto&
|
|
get_thread_state_history(int64_t _idx = utility::get_thread_index())
|
|
{
|
|
static auto _v = utility::get_filled_array<OMNITRACE_MAX_THREADS>(
|
|
[]() { return utility::get_reserved_vector<ThreadState>(32); });
|
|
|
|
if(_idx >= OMNITRACE_MAX_THREADS)
|
|
{
|
|
static thread_local auto _tl_v = utility::get_reserved_vector<ThreadState>(32);
|
|
return _tl_v;
|
|
}
|
|
|
|
return _v.at(_idx);
|
|
}
|
|
} // namespace
|
|
|
|
State
|
|
get_state()
|
|
{
|
|
return get_state_value().load(std::memory_order_relaxed);
|
|
}
|
|
|
|
ThreadState
|
|
get_thread_state()
|
|
{
|
|
return get_thread_state_value();
|
|
}
|
|
|
|
State
|
|
set_state(State _n)
|
|
{
|
|
OMNITRACE_CONDITIONAL_PRINT_F(get_debug_init(), "Setting state :: %s -> %s\n",
|
|
std::to_string(get_state()).c_str(),
|
|
std::to_string(_n).c_str());
|
|
// state should always be increased, not decreased
|
|
OMNITRACE_CI_BASIC_THROW(
|
|
_n < get_state(), "State is being assigned to a lesser value :: %s -> %s",
|
|
std::to_string(get_state()).c_str(), std::to_string(_n).c_str());
|
|
auto _v = get_state();
|
|
get_state_value().store(_n, std::memory_order_relaxed);
|
|
// std::swap(get_state_value(), _n);
|
|
return _v;
|
|
}
|
|
|
|
ThreadState
|
|
set_thread_state(ThreadState _n)
|
|
{
|
|
std::swap(get_thread_state_value(), _n);
|
|
return _n;
|
|
}
|
|
|
|
ThreadState
|
|
push_thread_state(ThreadState _v)
|
|
{
|
|
if(get_thread_state() >= ThreadState::Completed) return get_thread_state();
|
|
|
|
return get_thread_state_history().emplace_back(set_thread_state(_v));
|
|
}
|
|
|
|
ThreadState
|
|
pop_thread_state()
|
|
{
|
|
if(get_thread_state() >= ThreadState::Completed) return get_thread_state();
|
|
|
|
auto& _hist = get_thread_state_history();
|
|
if(!_hist.empty())
|
|
{
|
|
set_thread_state(_hist.back());
|
|
_hist.pop_back();
|
|
}
|
|
return get_thread_state();
|
|
}
|
|
} // namespace omnitrace
|
|
|
|
namespace std
|
|
{
|
|
std::string
|
|
to_string(omnitrace::State _v)
|
|
{
|
|
switch(_v)
|
|
{
|
|
case omnitrace::State::PreInit: return "PreInit";
|
|
case omnitrace::State::Init: return "Init";
|
|
case omnitrace::State::Active: return "Active";
|
|
case omnitrace::State::Disabled: return "Disabled";
|
|
case omnitrace::State::Finalized: return "Finalized";
|
|
}
|
|
return {};
|
|
}
|
|
|
|
std::string
|
|
to_string(omnitrace::ThreadState _v)
|
|
{
|
|
switch(_v)
|
|
{
|
|
case omnitrace::ThreadState::Enabled: return "Enabled";
|
|
case omnitrace::ThreadState::Internal: return "Internal";
|
|
case omnitrace::ThreadState::Completed: return "Completed";
|
|
case omnitrace::ThreadState::Disabled: return "Disabled";
|
|
}
|
|
return {};
|
|
}
|
|
|
|
std::string
|
|
to_string(omnitrace::Mode _v)
|
|
{
|
|
switch(_v)
|
|
{
|
|
case omnitrace::Mode::Trace: return "Trace";
|
|
case omnitrace::Mode::Sampling: return "Sampling";
|
|
case omnitrace::Mode::Causal: return "Causal";
|
|
case omnitrace::Mode::Coverage: return "Coverage";
|
|
}
|
|
return {};
|
|
}
|
|
|
|
std::string
|
|
to_string(omnitrace::CausalMode _v)
|
|
{
|
|
switch(_v)
|
|
{
|
|
case omnitrace::CausalMode::Line: return "Line";
|
|
case omnitrace::CausalMode::Function: return "Function";
|
|
}
|
|
return {};
|
|
}
|
|
} // namespace std
|