static void handle_stats(client_t *client, parsed_url_t &url) { headers_t headers; headers["Cache-Control"] = "no-cache"; std::string body; char buff[2048]; char *b = buff; b += sprintf(b, "Answered %lu queries\n", nreq); b += sprintf(b, "Uptime: %s\n", get_uptime().c_str()); if (building) { b += sprintf(b, "Data Store is busy\n"); } else { b += sprintf(b, "Data store size: %d entries\n", pm.repr.size()); } b += sprintf(b, "Memory usage: %d MiB\n", get_memory_usage(getpid())/1024); body = buff; write_response(client, 200, "OK", headers, body); }
void get_increment() { MemoryInfo old_state = *this; get_memory_usage(); m_malloc_used -= old_state.m_malloc_used; m_malloc_footprint -= old_state.m_malloc_footprint; }
void set_state() { get_memory_usage(); }
MemoryInfo() { get_memory_usage(); }
// Finds all processes running the /proc/ filesystem and builds a graphical // user interface to display the information about each numbered process. int graphics_build_processes (GtkListStore* store) { GtkTreeIter iter; DIR* directory; struct dirent* current; directory = opendir ("/proc/"); if (directory) { while ((current = readdir (directory)) != NULL) { if (isdigit (current->d_name[0])) { // PID char* process_id = current->d_name; // File Name char process_name[64]; char file_name_path[64]; snprintf(file_name_path, 64, "/proc/%s/cmdline", process_id); FILE* file = fopen (file_name_path, "r"); if (file == NULL) break; fgets (process_name, 64, file); fclose (file); // User Name struct stat statistic; struct passwd* user; if (stat (file_name_path, &statistic)) return 0; user = getpwuid (statistic.st_uid); char* user_name = user->pw_name; // Memory Usage char* memory_use; if (get_memory_usage (process_id) == -1) memory_use = "N/A"; else memory_use = resolve_memory_format (get_memory_usage (process_id)); // CPU Usage char CPU_use[36]; snprintf(CPU_use, 36, "%.0f%%", floor (get_CPU_percentage (process_id))); // Build list store gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, PROCESS_NAME, process_name, USER_NAME, user_name, CPU_PERCENT, CPU_use, PROCESS_ID, atoi (process_id), MEMORY_USAGE, memory_use, -1); } } } closedir (directory); return 1; }
void reset_peak_memory_usage() { _peak_usage = get_memory_usage(); }
mreturn mod_stats_server(mapi m, void *arg) { xmlnode cur; int i; if (m->packet->type != JPACKET_IQ) return M_IGNORE; if (jpacket_subtype(m->packet) != JPACKET__GET) return M_PASS; if (!NSCHECK(m->packet->iq, NS_STATS)) return M_PASS; if (m->packet->to->resource) return M_PASS; /* get data from the config file */ i = 0; if (xmlnode_get_tag(js_config(m->si, "stats"), "allow_all") != NULL) i = 1; log_debug("handling stats get %s", jid_full(m->packet->from)); /* check if admin */ if ((i == 0) && (!js_admin_jid(m->si, jid_user(m->packet->from), ADMIN_READ))) { jutil_error(m->packet->x, TERROR_AUTH); jpacket_reset(m->packet); js_deliver(m->si, m->packet); return M_HANDLED; } /* check if any stat have given iq query */ cur = xmlnode_get_firstchild(m->packet->iq); for (; cur != NULL; cur = xmlnode_get_nextsibling(cur)) { if (xmlnode_get_type(cur) != NTYPE_TAG) continue; break; } if (cur != NULL) cur = xmlnode_get_firstchild(m->packet->iq); jutil_tofrom(m->packet->x); xmlnode_put_attrib(m->packet->x, "type", "result"); /* return available stats */ if (!cur) { for (i = 0; available_stats[i]; i++) { xmlnode_put_attrib(xmlnode_insert_tag (m->packet->iq, "stat"), "name", available_stats[i]); } jpacket_reset(m->packet); js_deliver(m->si, m->packet); return M_HANDLED; } /* return server stats */ /* cur is already first stat */ for (; cur != NULL; cur = xmlnode_get_nextsibling(cur)) { char *name; char buf[31]; int found; if (xmlnode_get_type(cur) != NTYPE_TAG) continue; if (j_strcmp(xmlnode_get_name(cur), "stat") != 0) continue; name = xmlnode_get_attrib(cur, "name"); if (!name) continue; log_debug("get stats for %s", name); found = 0; for (i = 0; available_stats[i]; i++) { if (j_strcmp(available_stats[i], name) != 0) continue; log_debug("stats for %s", name); /* give stats */ found = 1; /* time/uptime */ if (j_strcmp(name, "time/uptime") == 0) { snprintf(buf, 30, "%d", time(NULL) - m->si->stats->started); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "seconds"); } /* users/online */ if (j_strcmp(name, "users/online") == 0) { snprintf(buf, 30, "%d", m->si->stats->sessioncount); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "users"); } if (j_strcmp(name, "users/max_online_today") == 0) { snprintf(buf, 30, "%d", m->si->stats->session_max_today); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "users"); } if (j_strcmp(name, "users/max_online_yesterday") == 0) { snprintf(buf, 30, "%d", m->si->stats-> session_max_yesterday); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "users"); } if (j_strcmp(name, "users/registered_today") == 0) { snprintf(buf, 30, "%d", m->si->stats-> users_registered_today); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "users"); } if (j_strcmp(name, "users/registered_from_start") == 0) { snprintf(buf, 30, "%d", m->si->stats-> users_registered_from_start); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "users"); } if (j_strcmp(name, "bandwidth/packets-in") == 0) { snprintf(buf, 30, "%lu", m->si->stats->packets_in); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "packets"); } if (j_strcmp(name, "bandwidth/packets-out") == 0) { snprintf(buf, 30, "%lu", m->si->stats->packets_out); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "packets"); } #ifndef WIN32 if (j_strcmp(name, "memory/usage") == 0) { long mem = get_memory_usage(); if (mem > 0) { snprintf(buf, 30, "%lu", mem); xmlnode_put_attrib(cur, "value", buf); xmlnode_put_attrib(cur, "units", "bytes"); } else found = 0; } #endif break; } if (found <= 0) { xmlnode err; err = xmlnode_insert_tag(cur, "error"); xmlnode_put_attrib(err, "code", "404"); xmlnode_insert_cdata(err, "Not Found", -1); } } jpacket_reset(m->packet); js_deliver(m->si, m->packet); return M_HANDLED; }
UInt64 HawkProfiler::GetMemUsage() { m_iMemUsage = get_memory_usage(); return m_iMemUsage; }