Files
rocm-systems/source/lib/omnitrace/library/components/pthread_gotcha.cpp
T

124 righe
3.3 KiB
C++

2022-01-26 23:25:00 -06:00
// 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
2022-01-26 23:25:00 -06:00
// 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:
//
2022-01-26 23:25:00 -06:00
// 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
2022-01-26 23:25:00 -06:00
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2022-01-26 23:25:00 -06:00
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "library/components/pthread_gotcha.hpp"
#include "core/config.hpp"
#include "core/debug.hpp"
#include "core/utility.hpp"
2022-05-08 04:40:10 -05:00
#include "library/components/pthread_create_gotcha.hpp"
#include "library/components/pthread_mutex_gotcha.hpp"
2022-04-25 17:00:52 -05:00
#include "library/runtime.hpp"
#include "library/thread_data.hpp"
2022-02-23 06:59:32 -06:00
#include <timemory/backends/threading.hpp>
2022-08-31 01:24:31 -05:00
#include <timemory/utility/macros.hpp>
#include <timemory/utility/types.hpp>
#include <pthread.h>
2022-05-08 04:40:10 -05:00
#include <array>
#include <vector>
2022-08-31 01:24:31 -05:00
namespace tim
{
namespace operation
{
template <>
struct stop<omnitrace::component::pthread_create_gotcha_t>
{
using type = omnitrace::component::pthread_create_gotcha_t;
2023-02-03 14:10:42 -06:00
OMNITRACE_DEFAULT_OBJECT(stop)
2022-08-31 01:24:31 -05:00
template <typename... Args>
explicit stop(type&, Args&&...)
{}
template <typename... Args>
void operator()(type&, Args&&...)
{}
};
} // namespace operation
} // namespace tim
namespace omnitrace
{
2022-02-08 17:42:17 -06:00
namespace
{
2022-08-31 01:24:31 -05:00
using bundle_t = tim::lightweight_tuple<component::pthread_create_gotcha_t,
component::pthread_mutex_gotcha_t>;
auto&
2022-05-08 04:40:10 -05:00
get_bundle()
{
2022-05-08 04:40:10 -05:00
static auto _v = std::unique_ptr<bundle_t>{};
if(!_v) _v = std::make_unique<bundle_t>("pthread_gotcha");
return _v;
}
2022-08-31 01:24:31 -05:00
bool is_configured = false;
2022-02-08 17:42:17 -06:00
} // namespace
2022-04-27 16:56:38 -05:00
//--------------------------------------------------------------------------------------//
void
pthread_gotcha::configure()
{
2022-08-31 01:24:31 -05:00
if(!is_configured)
{
::omnitrace::component::pthread_create_gotcha::configure();
::omnitrace::component::pthread_mutex_gotcha::configure();
is_configured = true;
}
}
2022-02-08 17:42:17 -06:00
void
pthread_gotcha::shutdown()
{
2022-08-31 01:24:31 -05:00
if(is_configured)
{
::omnitrace::component::pthread_mutex_gotcha::shutdown();
2023-10-16 18:04:47 -05:00
::omnitrace::component::pthread_create_gotcha::shutdown();
2022-08-31 01:24:31 -05:00
is_configured = false;
}
2022-02-08 17:42:17 -06:00
}
2022-05-08 04:40:10 -05:00
void
pthread_gotcha::start()
{
2022-08-31 01:24:31 -05:00
configure();
2022-05-08 04:40:10 -05:00
get_bundle()->start();
}
2022-05-08 04:40:10 -05:00
void
pthread_gotcha::stop()
{
get_bundle()->stop();
}
2023-06-14 11:55:22 -05:00
std::set<pthread_gotcha::native_handle_t>
pthread_gotcha::get_native_handles()
{
return ::omnitrace::component::pthread_create_gotcha::get_native_handles();
}
} // namespace omnitrace