|
|
@@ -11,6 +11,9 @@ extern "C" {
|
|
|
|
|
|
#include <set>
|
|
|
#include <map>
|
|
|
+#ifdef LOG_MEM
|
|
|
+#include <stdio.h>
|
|
|
+#endif
|
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
#include <errno.h>
|
|
|
@@ -44,6 +47,51 @@ static struct DPControllerState {
|
|
|
listener(NULL) {}
|
|
|
} dpctrlstate;
|
|
|
|
|
|
+#ifdef LOG_MEM
|
|
|
+
|
|
|
+/* Log the amount of memory used by the process. It turns out each DP
|
|
|
+ consumes about 338 bytes of heap. Also, memory is not deallocated when
|
|
|
+ the table is cleared. */
|
|
|
+static void logmemusage(const char *label)
|
|
|
+{
|
|
|
+ FILE *smaps;
|
|
|
+ FILE *logoutput;
|
|
|
+
|
|
|
+ char logfilename[256];
|
|
|
+
|
|
|
+ sprintf(logfilename, "mem-%05d", getpid());
|
|
|
+
|
|
|
+ smaps = fopen("/proc/self/smaps", "r");
|
|
|
+ if (!smaps) return;
|
|
|
+ logoutput = fopen(logfilename, "a");
|
|
|
+ if (!logoutput) {
|
|
|
+ fclose(smaps);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ char *line = NULL;
|
|
|
+ size_t n = 0;
|
|
|
+ while(getline(&line, &n, smaps) > -1) {
|
|
|
+ if (!strstr(line, "[heap]")) {
|
|
|
+ free(line);
|
|
|
+ line = NULL;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // Read and parse the next line
|
|
|
+ if (getline(&line, &n, smaps) > -1 && !strncmp(line, "Size:", 5)) {
|
|
|
+ unsigned long usage;
|
|
|
+ if (sscanf(line+5, "%lu", &usage) == 1) {
|
|
|
+ fprintf(logoutput, "%s %lu %lu %lu\n", label,
|
|
|
+ dpctrlstate.table.size(), dpctrlstate.table.max_size(),
|
|
|
+ usage);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fclose(logoutput);
|
|
|
+ fclose(smaps);
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
static void dpnode_event_cb(struct bufferevent *bev, short events,
|
|
|
void *ctx)
|
|
|
{
|
|
|
@@ -88,6 +136,11 @@ static void dpnode_reader(struct bufferevent *bev, void *ctx)
|
|
|
pair<ZZ,ZZ> ab(zz_a,zz_b);
|
|
|
pair<DTable::iterator, bool> res =
|
|
|
dpctrlstate.table.insert(DTable::value_type(x,ab));
|
|
|
+#ifdef LOG_MEM
|
|
|
+ if (dpctrlstate.table.size() % 1000 == 0) {
|
|
|
+ logmemusage("insert");
|
|
|
+ }
|
|
|
+#endif
|
|
|
|
|
|
if (!res.second) {
|
|
|
const ZZ& order = dpctrlstate.current_problem->order;
|
|
|
@@ -181,7 +234,13 @@ static void stop_problem(void)
|
|
|
bufferevent_free(*wit);
|
|
|
}
|
|
|
dpctrlstate.workers.clear();
|
|
|
+#ifdef LOG_MEM
|
|
|
+ logmemusage("preclear");
|
|
|
+#endif
|
|
|
dpctrlstate.table.clear();
|
|
|
+#ifdef LOG_MEM
|
|
|
+ logmemusage("postclear");
|
|
|
+#endif
|
|
|
dpctrlstate.numdps = 0;
|
|
|
}
|
|
|
|