cpu/subproc: better debugging strings
This commit is contained in:
parent
0d292e7be7
commit
8e3ca99c3f
@ -17,6 +17,7 @@ cwd: "/user"
|
||||
daemon: true
|
||||
|
||||
time_limit: 0
|
||||
max_cpus: 2
|
||||
|
||||
envar: "HOME=/user"
|
||||
envar: "DISPLAY"
|
||||
|
17
cpu.cc
17
cpu.cc
@ -34,17 +34,16 @@
|
||||
|
||||
namespace cpu {
|
||||
|
||||
static std::string listCpusInSet(cpu_set_t* mask) {
|
||||
std::string ret = "[";
|
||||
static const std::string listCpusInSet(cpu_set_t* mask) {
|
||||
std::string ret;
|
||||
for (size_t i = 0; i < CPU_SETSIZE; i++) {
|
||||
if (CPU_ISSET(i, mask)) {
|
||||
if (ret.length() != 1) {
|
||||
if (!ret.empty()) {
|
||||
ret.append(",");
|
||||
}
|
||||
ret.append(std::to_string(i));
|
||||
}
|
||||
}
|
||||
ret.append("]");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -57,7 +56,7 @@ static size_t getNthOnlineCpu(cpu_set_t* mask, size_t n) {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
LOG_F("No CPU #%zu found, yet there should be %zu left in the mask %s", n,
|
||||
LOG_F("No CPU #%zu found, yet there should be %zu left in the mask [%s]", n,
|
||||
(size_t)CPU_COUNT(mask), listCpusInSet(mask).c_str());
|
||||
return 0;
|
||||
}
|
||||
@ -72,7 +71,7 @@ static void setRandomCpu(cpu_set_t* orig_mask, cpu_set_t* new_mask) {
|
||||
n = getNthOnlineCpu(orig_mask, n);
|
||||
|
||||
CPU_SET(n, new_mask);
|
||||
LOG_D("Updating allowed CPU#:%zu from the set of %s (size=%zu), new mask %s (size=%zu)", n,
|
||||
LOG_D("Add CPU #%zu from the original set of [%s] (size=%zu), new mask [%s] (size=%zu)", n,
|
||||
listCpusInSet(orig_mask).c_str(), (size_t)CPU_COUNT(orig_mask),
|
||||
listCpusInSet(new_mask).c_str(), (size_t)CPU_COUNT(new_mask));
|
||||
CPU_CLR(n, orig_mask);
|
||||
@ -95,8 +94,8 @@ bool initCpu(nsjconf_t* nsjconf) {
|
||||
}
|
||||
size_t available_cpus = CPU_COUNT(orig_mask.get());
|
||||
|
||||
LOG_D("Original CPU set: %s, with %zu allowed CPUs", listCpusInSet(orig_mask.get()).c_str(),
|
||||
available_cpus);
|
||||
LOG_D("Original CPU set: [%s], with %zu allowed CPUs",
|
||||
listCpusInSet(orig_mask.get()).c_str(), available_cpus);
|
||||
|
||||
if (nsjconf->max_cpus > available_cpus) {
|
||||
LOG_W(
|
||||
@ -120,7 +119,7 @@ bool initCpu(nsjconf_t* nsjconf) {
|
||||
setRandomCpu(orig_mask.get(), new_mask.get());
|
||||
}
|
||||
|
||||
LOG_D("Setting new CPU mask: %s with %zu allowed CPUs",
|
||||
LOG_D("Setting new CPU mask: [%s] with %zu allowed CPUs",
|
||||
listCpusInSet(new_mask.get()).c_str(), (size_t)CPU_COUNT(new_mask.get()));
|
||||
|
||||
if (sched_setaffinity(0, CPU_ALLOC_SIZE(CPU_SETSIZE), new_mask.get()) == -1) {
|
||||
|
16
subproc.cc
16
subproc.cc
@ -139,6 +139,19 @@ static bool resetEnv(void) {
|
||||
static const char kSubprocDoneChar = 'D';
|
||||
static const char kSubprocErrorChar = 'E';
|
||||
|
||||
static const std::string contactArgs(const std::vector<const char*>& argv) {
|
||||
std::string ret;
|
||||
for (auto s : argv) {
|
||||
if (s) {
|
||||
if (!ret.empty()) {
|
||||
ret.append(", ");
|
||||
}
|
||||
ret.append("'").append(s).append("'");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void subprocNewProc(
|
||||
nsjconf_t* nsjconf, int netfd, int fd_in, int fd_out, int fd_err, int pipefd) {
|
||||
if (!contain::setupFD(nsjconf, fd_in, fd_out, fd_err)) {
|
||||
@ -187,10 +200,11 @@ static void subprocNewProc(
|
||||
std::vector<const char*> argv;
|
||||
for (const auto& s : nsjconf->argv) {
|
||||
argv.push_back(s.c_str());
|
||||
LOG_D(" Arg: '%s'", s.c_str());
|
||||
}
|
||||
argv.push_back(nullptr);
|
||||
|
||||
LOG_D("Exec: '%s', Args: [%s]", nsjconf->exec_file.c_str(), contactArgs(argv).c_str());
|
||||
|
||||
/* Should be the last one in the sequence */
|
||||
if (!sandbox::applyPolicy(nsjconf)) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user