Skip to content

Commit

Permalink
Merge pull request #5870 from BOINC/dpa_docker_rsc
Browse files Browse the repository at this point in the history
client/API/docker_wrapper: get CPU and mem usage of Docker apps
  • Loading branch information
AenBleidd authored Oct 30, 2024
2 parents fc7ecbf + 984d0ab commit 26bc981
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 47 deletions.
9 changes: 7 additions & 2 deletions api/boinc_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,8 @@ int boinc_report_app_status_aux(
double _fraction_done,
int other_pid,
double _bytes_sent,
double _bytes_received
double _bytes_received,
double wss
) {
char msg_buf[MSG_CHANNEL_SIZE], buf[1024];
if (standalone) return 0;
Expand Down Expand Up @@ -1081,6 +1082,10 @@ int boinc_report_app_status_aux(
sprintf(buf, "<sporadic_ac>%d</sporadic_ac>\n", ac_state);
strlcat(msg_buf, buf, sizeof(msg_buf));
}
if (wss) {
sprintf(buf, "<wss>%f</wss>\n", wss);
strlcat(msg_buf, buf, sizeof(msg_buf));
}
#ifdef MSGS_FROM_FILE
if (fout) {
fputs(msg_buf, fout);
Expand All @@ -1100,7 +1105,7 @@ int boinc_report_app_status(
double _fraction_done
){
return boinc_report_app_status_aux(
cpu_time, checkpoint_cpu_time, _fraction_done, 0, 0, 0
cpu_time, checkpoint_cpu_time, _fraction_done, 0, 0, 0, 0
);
}

Expand Down
3 changes: 2 additions & 1 deletion api/boinc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ extern int boinc_upload_status(std::string& name);
extern char* boinc_msg_prefix(char*, int);
extern int boinc_report_app_status_aux(
double cpu_time, double checkpoint_cpu_time, double _fraction_done,
int other_pid, double bytes_sent, double bytes_received
int other_pid, double bytes_sent, double bytes_received,
double wss
);
extern int boinc_temporary_exit(
int delay, const char* reason=NULL, bool is_notice=false
Expand Down
3 changes: 3 additions & 0 deletions client/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ ACTIVE_TASK::ACTIVE_TASK() {
peak_disk_usage = 0;
once_ran_edf = false;

wss_from_app = 0;
fraction_done = 0;
fraction_done_elapsed_time = 0;
first_fraction_done = 0;
Expand Down Expand Up @@ -420,6 +421,8 @@ void ACTIVE_TASK_SET::get_memory_usage() {
// at least on Windows. Use the VM size instead.
//
pi.working_set_size_smoothed = atp->wup->rsc_memory_bound;
} else if (atp->wss_from_app > 0) {
pi.working_set_size_smoothed = .5*(pi.working_set_size_smoothed + atp->wss_from_app);
} else {
pi.working_set_size_smoothed = .5*(pi.working_set_size_smoothed + pi.working_set_size);
}
Expand Down
14 changes: 10 additions & 4 deletions client/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ typedef int PROCESS_ID;

// Represents a job in progress.

// When an active task is created, it is assigned a "slot"
// When a job is started, it is assigned a "slot"
// which determines the directory it runs in.
// This doesn't change over the life of the active task;
// thus the task can use the slot directory for temp files
// This doesn't change over the life of the job;
// so it can use the slot directory for temp files
// that BOINC doesn't know about.

// If you add anything, initialize it in the constructor
//
struct ACTIVE_TASK {
#ifdef _WIN32
HANDLE process_handle, shm_handle;
Expand Down Expand Up @@ -100,8 +102,12 @@ struct ACTIVE_TASK {
// most recent CPU time reported by app
bool once_ran_edf;

// END OF ITEMS SAVED IN STATE FILE
// END OF ITEMS SAVED IN STATE FILES

double wss_from_app;
// work set size reported by the app
// (e.g. docker_wrapper does this).
// If nonzero, use this instead of procinfo data
double fraction_done;
// App's estimate of how much of the work unit is done.
// Passed from the application via an API call;
Expand Down
31 changes: 17 additions & 14 deletions client/app_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,8 +1439,23 @@ bool ACTIVE_TASK::get_app_status_msg() {
}
}
}
parse_double(msg_buf, "<current_cpu_time>", current_cpu_time);
parse_double(msg_buf, "<checkpoint_cpu_time>", checkpoint_cpu_time);
if (parse_double(msg_buf, "<current_cpu_time>", current_cpu_time)) {
if (current_cpu_time < 0) {
msg_printf(result->project, MSG_INFO,
"app reporting negative CPU: %f", current_cpu_time
);
current_cpu_time = 0;
}
}
if (parse_double(msg_buf, "<checkpoint_cpu_time>", checkpoint_cpu_time)) {
if (checkpoint_cpu_time < 0) {
msg_printf(result->project, MSG_INFO,
"app reporting negative checkpoint CPU: %f", checkpoint_cpu_time
);
checkpoint_cpu_time = 0;
}
}
parse_double(msg_buf, "<wss>", wss_from_app);
parse_double(msg_buf, "<fpops_per_cpu_sec>", result->fpops_per_cpu_sec);
parse_double(msg_buf, "<fpops_cumulative>", result->fpops_cumulative);
parse_double(msg_buf, "<intops_per_cpu_sec>", result->intops_per_cpu_sec);
Expand Down Expand Up @@ -1470,18 +1485,6 @@ bool ACTIVE_TASK::get_app_status_msg() {
if (parse_int(msg_buf, "<sporadic_ac>", i)) {
sporadic_ac_state = (SPORADIC_AC_STATE)i;
}
if (current_cpu_time < 0) {
msg_printf(result->project, MSG_INFO,
"app reporting negative CPU: %f", current_cpu_time
);
current_cpu_time = 0;
}
if (checkpoint_cpu_time < 0) {
msg_printf(result->project, MSG_INFO,
"app reporting negative checkpoint CPU: %f", checkpoint_cpu_time
);
checkpoint_cpu_time = 0;
}
return true;
}

Expand Down
29 changes: 27 additions & 2 deletions client/app_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// input/output files, attributes, etc.
// It currently has several test cases, selected with #ifdef
// - build the BOINC client with these changes
// - make a BOINC data directory, say 'test'
// - Linux: make a BOINC data directory, say 'test'
// (or you can use an existing BOINC data directory,
// in which case the client will also run existing jobs)
// - make a directory test/slots/app_test
Expand Down Expand Up @@ -224,6 +224,20 @@ void CLIENT_STATE::app_test_init() {
*make_file(app->project, "Dockerfile_copy", "Dockerfile", INPUT_FILE, true)
);
#endif
#ifdef APP_DOCKER_WRAPPER_MOUNT
av->app_files.push_back(
*make_file(app->project, "docker_wrapper.exe", NULL, MAIN_PROG, false)
);
av->app_files.push_back(
*make_file(app->project, "worker", NULL, INPUT_FILE, false)
);
av->app_files.push_back(
*make_file(app->project, "job_copy.toml", "job.toml", INPUT_FILE, true)
);
av->app_files.push_back(
*make_file(app->project, "Dockerfile_copy", "Dockerfile", INPUT_FILE, true)
);
#endif

// can put other stuff here like
#if 0
Expand All @@ -243,11 +257,17 @@ void CLIENT_STATE::app_test_init() {
);
#endif
#ifdef APP_DOCKER_WRAPPER_COPY
wu->command_line = "--verbose";
wu->input_files.push_back(
*make_file(proj, "infile", "in", INPUT_FILE, true)
);
#endif

#ifdef APP_DOCKER_WRAPPER_MOUNT
wu->command_line = "--verbose";
wu->input_files.push_back(
*make_file(proj, "infile", "in", INPUT_FILE, false)
);
#endif
RESULT *result = make_result(av, wu);

////////////// OUTPUT FILES /////////////////
Expand All @@ -262,6 +282,11 @@ void CLIENT_STATE::app_test_init() {
*make_file(proj, "outfile", "out", OUTPUT_FILE, true)
);
#endif
#ifdef APP_DOCKER_WRAPPER_MOUNT
result->output_files.push_back(
*make_file(proj, "outfile", "out", OUTPUT_FILE, false)
);
#endif

// tell the client not to get work or run benchmarks
//
Expand Down
Loading

0 comments on commit 26bc981

Please sign in to comment.