Skip to content

Commit

Permalink
Resetting the static tree node count after each dump, needed for merg…
Browse files Browse the repository at this point in the history
…ing common tree of tasktree data.
  • Loading branch information
khuck committed Feb 7, 2024
1 parent 8ddf39b commit 7d5f067
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/apex/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,79 @@ void rank0_print(const char * fmt, ...) {
va_end(args);
}

std::string getCpusAllowed(const char * filename) {
//std::cout << std::endl << filename << std::endl;
FILE *f = fopen(filename, "r");
std::string allowed_string{""};
if (!f) { return(allowed_string); }
const std::string allowed("Cpus_allowed_list");
char line[4097] = {0};
while ( fgets( line, 4096, f)) {
std::string tmp(line);
//std::cout << tmp << std::flush;
if (!tmp.compare(0,allowed.size(),allowed)) {
const std::regex separator(":");
std::sregex_token_iterator token(tmp.begin(),
tmp.end(), separator, -1);
std::sregex_token_iterator end;
std::string name = *token++;
if (token != end) {
allowed_string = *token;
allowed_string.erase(
std::remove_if(
allowed_string.begin(), allowed_string.end(),
::isspace),
allowed_string.end());
}
}
}
fclose(f);
return(allowed_string);
}

std::vector<uint32_t> parseDiscreteValues(std::string inputString) {
std::vector<uint32_t> result;

// Split the input string by comma
size_t pos = 0;
std::string token;
while ((pos = inputString.find(',')) != std::string::npos) {
token = inputString.substr(0, pos);

// Split each token by hyphen
size_t hyphenPos = token.find('-');
if (hyphenPos != std::string::npos) {
int start = std::stoi(token.substr(0, hyphenPos));
int end = std::stoi(token.substr(hyphenPos + 1));
for (int i = start; i <= end; ++i) {
result.push_back(i);
}
} else {
result.push_back(std::stoi(token));
}

// Trim the processed token from the input string
inputString.erase(0, (pos + 1));
}

// Process the last token after the last comma
if (!inputString.empty()) {
size_t hyphenPos = inputString.find('-');
if (hyphenPos != std::string::npos) {
int start = std::stoi(inputString.substr(0, hyphenPos));
int end = std::stoi(inputString.substr(hyphenPos + 1));
for (int i = start; i <= end; ++i) {
result.push_back(i);
}
} else {
result.push_back(std::stoi(inputString));
}
}

return result;
}


} // namespace apex

extern "C" void __cyg_profile_func_enter(void *this_fn, void *call_site) __attribute__((no_instrument_function));
Expand Down
9 changes: 9 additions & 0 deletions src/apex/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cxxabi.h>
#endif
#include <atomic>
#include <regex>

#include "apex_types.h"
#include "apex_options.hpp"
Expand Down Expand Up @@ -231,13 +232,21 @@ class reference_counter {
#define APEX_UTIL_REPORT_STATS
#endif

std::vector<uint32_t> parseDiscreteValues(std::string inputString);
std::string getCpusAllowed(const char * filename);

inline unsigned int my_hardware_concurrency()
{
#if defined(_MSC_VER)
return std::thread::hardware_concurrency();
#else
/*
unsigned int cores = std::thread::hardware_concurrency();
return cores ? cores : sysconf(_SC_NPROCESSORS_ONLN);
*/
static std::vector<uint32_t>
cores{parseDiscreteValues(getCpusAllowed("/proc/self/status"))};
return cores.size();
#endif
}

Expand Down

0 comments on commit 7d5f067

Please sign in to comment.