Remove temporary files (#223)

* config updates

- remove temporary file when destroyed
- extend parse_numeric_range: support vector, increment, better delimit
- git version info in omnitrace banner
- use OMNITRACE_BASIC_VERBOSE instead of OMNITRACE_VERBOSE

* Fix array-bounds warning in openmp lu.cpp

* Bump version to 1.7.4

* Update run-ci.py

- options to repeat
  - until-pass (default: 3)
  - until-fail (default: None)
  - after-timeout (default: 2)

[ROCm/rocprofiler-systems commit: 2096f1f0c2]
This commit is contained in:
Jonathan R. Madsen
2023-01-10 01:06:12 -06:00
committed by GitHub
orang tua 7f73cf67bb
melakukan 1cdf67257e
5 mengubah file dengan 145 tambahan dan 47 penghapusan
+1 -1
Melihat File
@@ -1 +1 @@
1.7.3 1.7.4
@@ -1851,7 +1851,7 @@ jacu(int k)
*/ */
void void
l2norm(int nx0, int ny0, int nz0, int ist, int iend, int jst, int jend, l2norm(int nx0, int ny0, int nz0, int ist, int iend, int jst, int jend,
double v[][ISIZ2 / 2 * 2 + 1][ISIZ1 / 2 * 2 + 1][5], double sum[]) double v[][ISIZ2 / 2 * 2 + 1][ISIZ1 / 2 * 2 + 1][5], double sum[5])
{ {
/* /*
* --------------------------------------------------------------------- * ---------------------------------------------------------------------
@@ -181,6 +181,21 @@ def parse_cdash_args(args):
parser.add_argument( parser.add_argument(
"--submit-url", help="CDash submission site", default=SUBMIT_URL, type=str "--submit-url", help="CDash submission site", default=SUBMIT_URL, type=str
) )
parser.add_argument(
"--repeat-until-pass", help="<N> for --repeat until-pass:<N>", default=3, type=int
)
parser.add_argument(
"--repeat-until-fail",
help="<N> for --repeat until-fail:<N>",
default=None,
type=int,
)
parser.add_argument(
"--repeat-after-timeout",
help="<N> for --repeat after-timeout:<N>",
default=2,
type=int,
)
return parser.parse_args(args) return parser.parse_args(args)
@@ -208,6 +223,17 @@ def parse_args(args=None):
if cdash_args.coverage: if cdash_args.coverage:
cmake_args += ["-DOMNITRACE_BUILD_CODECOV=ON", "-DOMNITRACE_STRIP_LIBRARIES=OFF"] cmake_args += ["-DOMNITRACE_BUILD_CODECOV=ON", "-DOMNITRACE_STRIP_LIBRARIES=OFF"]
def get_repeat_val(_param):
_value = getattr(cdash_args, f"repeat_{_param}".replace("-", "_"))
return [f"{_param}:{_value}"] if _value is not None and _value > 1 else []
repeat_args = (
get_repeat_val("until-pass")
+ get_repeat_val("until-fail")
+ get_repeat_val("after-timeout")
)
ctest_args += ["--repeat"] + repeat_args if len(repeat_args) > 0 else []
return [cdash_args, cmake_args, ctest_args] return [cdash_args, cmake_args, ctest_args]
@@ -21,6 +21,7 @@
// SOFTWARE. // SOFTWARE.
#include "library/config.hpp" #include "library/config.hpp"
#include "common/defines.h"
#include "library/debug.hpp" #include "library/debug.hpp"
#include "library/defines.hpp" #include "library/defines.hpp"
#include "library/gpu.hpp" #include "library/gpu.hpp"
@@ -42,6 +43,7 @@
#include <timemory/settings/types.hpp> #include <timemory/settings/types.hpp>
#include <timemory/utility/argparse.hpp> #include <timemory/utility/argparse.hpp>
#include <timemory/utility/declaration.hpp> #include <timemory/utility/declaration.hpp>
#include <timemory/utility/join.hpp>
#include <timemory/utility/signals.hpp> #include <timemory/utility/signals.hpp>
#include <algorithm> #include <algorithm>
@@ -64,12 +66,22 @@ using settings = tim::settings;
namespace namespace
{ {
TIMEMORY_NOINLINE bool&
_settings_are_configured()
{
static bool _v = false;
return _v;
}
auto auto
get_config() get_config()
{ {
static auto _once = (configure_settings(), true); if(!_settings_are_configured())
{
static auto _once = (configure_settings(), true);
(void) _once;
}
return settings::shared_instance(); return settings::shared_instance();
(void) _once;
} }
std::string std::string
@@ -93,14 +105,21 @@ get_available_perfetto_categories()
return _v; return _v;
} }
template <typename Tp = int64_t> template <typename Tp = int64_t, typename ContainerT = std::set<Tp>, typename Up = Tp>
std::set<Tp> ContainerT
parse_numeric_range(std::string _input_string, const std::string& _label) parse_numeric_range(std::string _input_string, const std::string& _label, Up _incr)
{ {
auto _get_value = [](const std::string& _inp) {
std::stringstream iss{ _inp };
auto var = Tp{};
iss >> var;
return var;
};
for(auto& itr : _input_string) for(auto& itr : _input_string)
itr = tolower(itr); itr = tolower(itr);
auto _result = std::set<Tp>{}; auto _result = ContainerT{};
for(const auto& _v : tim::delimit(_input_string, ",; \t")) for(const auto& _v : tim::delimit(_input_string, ",; \t\n\r"))
{ {
if(_v.find_first_not_of("0123456789-") != std::string::npos) if(_v.find_first_not_of("0123456789-") != std::string::npos)
{ {
@@ -118,12 +137,23 @@ parse_numeric_range(std::string _input_string, const std::string& _label)
_vv.size() != 2, _vv.size() != 2,
"Invalid %s range specification: %s. Required format N-M, e.g. 0-4", "Invalid %s range specification: %s. Required format N-M, e.g. 0-4",
_label.c_str(), _v.c_str()); _label.c_str(), _v.c_str());
for(int64_t i = std::stol(_vv.at(0)); i <= std::stol(_vv.at(1)); ++i) Tp _vn = _get_value(_vv.at(0));
_result.emplace(i); Tp _vN = _get_value(_vv.at(1));
do
{
if constexpr(std::is_same<ContainerT, std::set<Tp>>::value)
_result.emplace(_vn);
else
_result.emplace_back(_vn);
_vn += _incr;
} while(_vn <= _vN);
} }
else else
{ {
_result.emplace(std::stol(_v)); if constexpr(std::is_same<ContainerT, std::set<Tp>>::value)
_result.emplace(std::stol(_v));
else
_result.emplace_back(std::stol(_v));
} }
} }
return _result; return _result;
@@ -178,13 +208,8 @@ inline namespace config
{ {
namespace namespace
{ {
TIMEMORY_NOINLINE bool& auto cfg_fini_callbacks = std::vector<std::function<void()>>{};
_settings_are_configured()
{
static bool _v = false;
return _v;
} }
} // namespace
void void
finalize() finalize()
@@ -192,6 +217,8 @@ finalize()
OMNITRACE_DEBUG("[omnitrace_finalize] Disabling signal handling...\n"); OMNITRACE_DEBUG("[omnitrace_finalize] Disabling signal handling...\n");
tim::signals::disable_signal_detection(); tim::signals::disable_signal_detection();
_settings_are_configured() = false; _settings_are_configured() = false;
for(const auto& itr : cfg_fini_callbacks)
if(itr) itr();
} }
bool bool
@@ -823,8 +850,8 @@ configure_settings(bool _init)
} }
if(!_iss.str().empty()) if(!_iss.str().empty())
{ {
OMNITRACE_BASIC_PRINT("config file '%s':\n%s\n", fitr.c_str(), OMNITRACE_BASIC_VERBOSE(1, "config file '%s':\n%s\n", fitr.c_str(),
_iss.str().c_str()); _iss.str().c_str());
} }
} }
} }
@@ -898,14 +925,14 @@ configure_mode_settings()
auto _set = [](const std::string& _name, bool _v) { auto _set = [](const std::string& _name, bool _v) {
if(!set_setting_value(_name, _v)) if(!set_setting_value(_name, _v))
{ {
OMNITRACE_VERBOSE( OMNITRACE_BASIC_VERBOSE(
4, "[configure_mode_settings] No configuration setting named '%s'...\n", 4, "[configure_mode_settings] No configuration setting named '%s'...\n",
_name.data()); _name.data());
} }
else else
{ {
bool _changed = get_setting_value<bool>(_name).second != _v; bool _changed = get_setting_value<bool>(_name).second != _v;
OMNITRACE_VERBOSE( OMNITRACE_BASIC_VERBOSE(
1 && _changed, 1 && _changed,
"[configure_mode_settings] Overriding %s to %s in %s mode...\n", "[configure_mode_settings] Overriding %s to %s in %s mode...\n",
_name.c_str(), JOIN("", std::boolalpha, _v).c_str(), _name.c_str(), JOIN("", std::boolalpha, _v).c_str(),
@@ -938,8 +965,8 @@ configure_mode_settings()
if(gpu::device_count() == 0) if(gpu::device_count() == 0)
{ {
OMNITRACE_VERBOSE(1, "No HIP devices were found: disabling roctracer, " OMNITRACE_BASIC_VERBOSE(1, "No HIP devices were found: disabling roctracer, "
"rocprofiler, and rocm_smi...\n"); "rocprofiler, and rocm_smi...\n");
_set("OMNITRACE_USE_ROCPROFILER", false); _set("OMNITRACE_USE_ROCPROFILER", false);
_set("OMNITRACE_USE_ROCTRACER", false); _set("OMNITRACE_USE_ROCTRACER", false);
_set("OMNITRACE_USE_ROCM_SMI", false); _set("OMNITRACE_USE_ROCM_SMI", false);
@@ -961,8 +988,8 @@ configure_mode_settings()
_message = _message =
JOIN("", " (forced. Previous value: '", _current_kokkosp_lib, "')"); JOIN("", " (forced. Previous value: '", _current_kokkosp_lib, "')");
} }
OMNITRACE_VERBOSE_F(1, "Setting KOKKOS_PROFILE_LIBRARY=%s%s\n", OMNITRACE_BASIC_VERBOSE_F(1, "Setting KOKKOS_PROFILE_LIBRARY=%s%s\n",
"libomnitrace.so", _message.c_str()); "libomnitrace.so", _message.c_str());
tim::set_env("KOKKOS_PROFILE_LIBRARY", "libomnitrace.so", _force); tim::set_env("KOKKOS_PROFILE_LIBRARY", "libomnitrace.so", _force);
} }
} }
@@ -1069,14 +1096,14 @@ configure_disabled_settings()
auto _disabled = _config->disable_category(_category); auto _disabled = _config->disable_category(_category);
_config->enable(_opt); _config->enable(_opt);
for(auto&& itr : _disabled) for(auto&& itr : _disabled)
OMNITRACE_VERBOSE(3, "[%s=OFF] disabled option :: '%s'\n", OMNITRACE_BASIC_VERBOSE(3, "[%s=OFF] disabled option :: '%s'\n",
_opt.c_str(), itr.c_str()); _opt.c_str(), itr.c_str());
return false; return false;
} }
auto _enabled = _config->enable_category(_category); auto _enabled = _config->enable_category(_category);
for(auto&& itr : _enabled) for(auto&& itr : _enabled)
OMNITRACE_VERBOSE(3, "[%s=ON] enabled option :: '%s'\n", _opt.c_str(), OMNITRACE_BASIC_VERBOSE(3, "[%s=ON] enabled option :: '%s'\n",
itr.c_str()); _opt.c_str(), itr.c_str());
return true; return true;
}; };
@@ -1197,13 +1224,13 @@ handle_deprecated_setting(const std::string& _old, const std::string& _new, int
std::array<char, 79> _v = {}; std::array<char, 79> _v = {};
_v.fill('='); _v.fill('=');
_v.back() = '\0'; _v.back() = '\0';
OMNITRACE_VERBOSE(_verbose, "#%s#\n", _v.data()); OMNITRACE_BASIC_VERBOSE(_verbose, "#%s#\n", _v.data());
}; };
_separator(); _separator();
OMNITRACE_VERBOSE(_verbose, "#\n"); OMNITRACE_BASIC_VERBOSE(_verbose, "#\n");
OMNITRACE_VERBOSE(_verbose, "# DEPRECATION NOTICE:\n"); OMNITRACE_BASIC_VERBOSE(_verbose, "# DEPRECATION NOTICE:\n");
OMNITRACE_VERBOSE(_verbose, "# %s is deprecated!\n", _old.c_str()); OMNITRACE_BASIC_VERBOSE(_verbose, "# %s is deprecated!\n", _old.c_str());
OMNITRACE_VERBOSE(_verbose, "# Use %s instead!\n", _new.c_str()); OMNITRACE_BASIC_VERBOSE(_verbose, "# Use %s instead!\n", _new.c_str());
if(!_new_setting->second->get_environ_updated() && if(!_new_setting->second->get_environ_updated() &&
!_new_setting->second->get_config_updated()) !_new_setting->second->get_config_updated())
@@ -1216,15 +1243,15 @@ handle_deprecated_setting(const std::string& _old, const std::string& _new, int
{ {
std::string _cause = std::string _cause =
(_old_setting->second->get_environ_updated()) ? "environ" : "config"; (_old_setting->second->get_environ_updated()) ? "environ" : "config";
OMNITRACE_VERBOSE(_verbose, "#\n"); OMNITRACE_BASIC_VERBOSE(_verbose, "#\n");
OMNITRACE_VERBOSE(_verbose, "# %s :: '%s' -> '%s'\n", _new.c_str(), OMNITRACE_BASIC_VERBOSE(_verbose, "# %s :: '%s' -> '%s'\n", _new.c_str(),
_before.c_str(), _after.c_str()); _before.c_str(), _after.c_str());
OMNITRACE_VERBOSE(_verbose, "# via %s (%s)\n", _old.c_str(), OMNITRACE_BASIC_VERBOSE(_verbose, "# via %s (%s)\n", _old.c_str(),
_cause.c_str()); _cause.c_str());
} }
} }
OMNITRACE_VERBOSE(_verbose, "#\n"); OMNITRACE_BASIC_VERBOSE(_verbose, "#\n");
_separator(); _separator();
} }
} }
@@ -1242,7 +1269,23 @@ print_banner(std::ostream& _os)
\______/ |__| |__| |__| \__| |__| |__| | _| `._____/__/ \__\ \______||_______| \______/ |__| |__| |__| \__| |__| |__| | _| `._____/__/ \__\ \______||_______|
)banner"; )banner";
tim::log::stream(_os, tim::log::color::info()) << _banner; auto _tag = std::string_view{ OMNITRACE_GIT_DESCRIBE };
auto _rev = std::string_view{ OMNITRACE_GIT_REVISION };
std::stringstream _version_info{};
_version_info << "omnitrace v" << OMNITRACE_VERSION_STRING;
if(!_tag.empty() || !_rev.empty())
{
_version_info << " (";
if(!_tag.empty())
{
_version_info << "tag: " << OMNITRACE_GIT_DESCRIBE;
if(!_rev.empty()) _version_info << ", ";
}
if(!_rev.empty()) _version_info << "rev: " << OMNITRACE_GIT_REVISION;
_version_info << ")";
}
tim::log::stream(_os, tim::log::color::info()) << _banner << _version_info.str();
_os << std::endl; _os << std::endl;
} }
@@ -1906,7 +1949,7 @@ get_sampling_tids()
{ {
static auto _v = get_config()->find("OMNITRACE_SAMPLING_TIDS"); static auto _v = get_config()->find("OMNITRACE_SAMPLING_TIDS");
return parse_numeric_range<>( return parse_numeric_range<>(
static_cast<tim::tsettings<std::string>&>(*_v->second).get(), "thread IDs"); static_cast<tim::tsettings<std::string>&>(*_v->second).get(), "thread IDs", 1);
} }
std::set<int64_t> std::set<int64_t>
@@ -1914,7 +1957,7 @@ get_sampling_cpu_tids()
{ {
static auto _v = get_config()->find("OMNITRACE_SAMPLING_CPUTIME_TIDS"); static auto _v = get_config()->find("OMNITRACE_SAMPLING_CPUTIME_TIDS");
return parse_numeric_range<>( return parse_numeric_range<>(
static_cast<tim::tsettings<std::string>&>(*_v->second).get(), "thread IDs"); static_cast<tim::tsettings<std::string>&>(*_v->second).get(), "thread IDs", 1);
} }
std::set<int64_t> std::set<int64_t>
@@ -1922,7 +1965,7 @@ get_sampling_real_tids()
{ {
static auto _v = get_config()->find("OMNITRACE_SAMPLING_REALTIME_TIDS"); static auto _v = get_config()->find("OMNITRACE_SAMPLING_REALTIME_TIDS");
return parse_numeric_range<>( return parse_numeric_range<>(
static_cast<tim::tsettings<std::string>&>(*_v->second).get(), "thread IDs"); static_cast<tim::tsettings<std::string>&>(*_v->second).get(), "thread IDs", 1);
} }
bool bool
@@ -2066,12 +2109,16 @@ tmp_file::tmp_file(std::string _v)
: filename{ std::move(_v) } : filename{ std::move(_v) }
{} {}
tmp_file::~tmp_file() { close(); } tmp_file::~tmp_file()
{
close();
remove();
}
void void
tmp_file::open(std::ios::openmode _mode) tmp_file::open(std::ios::openmode _mode)
{ {
OMNITRACE_VERBOSE_F(2, "Opening temporary file '%s'...\n", filename.c_str()); OMNITRACE_BASIC_VERBOSE(2, "Opening temporary file '%s'...\n", filename.c_str());
if(!filepath::exists(filename)) if(!filepath::exists(filename))
{ {
@@ -2089,6 +2136,17 @@ tmp_file::close()
if(stream.is_open()) stream.close(); if(stream.is_open()) stream.close();
} }
void
tmp_file::remove()
{
close();
if(filepath::exists(filename))
{
OMNITRACE_BASIC_VERBOSE(2, "Removing temporary file '%s'...\n", filename.c_str());
::remove(filename.c_str());
}
}
std::shared_ptr<tmp_file> std::shared_ptr<tmp_file>
get_tmp_file(std::string _basename, std::string _ext) get_tmp_file(std::string _basename, std::string _ext)
{ {
@@ -2099,6 +2157,19 @@ get_tmp_file(std::string _basename, std::string _ext)
static std::mutex _mutex{}; static std::mutex _mutex{};
std::unique_lock<std::mutex> _lk{ _mutex }; std::unique_lock<std::mutex> _lk{ _mutex };
cfg_fini_callbacks.emplace_back([]() {
for(auto itr : _existing_files)
{
if(itr.second)
{
itr.second->close();
itr.second->remove();
itr.second.reset();
}
}
_existing_files.clear();
});
auto _cfg = settings::compose_filename_config{}; auto _cfg = settings::compose_filename_config{};
_cfg.use_suffix = true; _cfg.use_suffix = true;
_cfg.suffix = "%pid%"; _cfg.suffix = "%pid%";
@@ -357,6 +357,7 @@ struct tmp_file
void open(std::ios::openmode = std::ios::binary | std::ios::in | std::ios::out); void open(std::ios::openmode = std::ios::binary | std::ios::in | std::ios::out);
void close(); void close();
void remove();
operator bool() const { return stream.is_open() && stream.good(); } operator bool() const { return stream.is_open() && stream.good(); }