void SmoothRefresh::load_settings_value(const gchar *key) { this->active = g_settings_get_boolean(settings, key); if (this->active) procman_debug("smooth_refresh is enabled"); }
gboolean load_symbols(const char *module, ...) { GModule *mod; gboolean found_all = TRUE; va_list args; mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); if (!mod) return FALSE; procman_debug("Found %s", module); va_start(args, module); while (1) { const char *name; void **symbol; name = va_arg(args, char*); if (!name) break; symbol = va_arg(args, void**); if (g_module_symbol(mod, name, symbol)) { procman_debug("Loaded %s from %s", name, module); } else { procman_debug("Could not load %s from %s", name, module); found_all = FALSE; break; } } va_end(args); if (found_all) g_module_make_resident(mod); else g_module_close(mod); return found_all; }
void update(GtkSpinButton* spin) { int new_value = int(1000 * gtk_spin_button_get_value(spin)); g_settings_set_int(ProcData::get_instance()->settings, this->key.c_str(), new_value); procman_debug("set %s to %d", this->key.c_str(), new_value); }
bool SmoothRefresh::get(guint &new_interval) { const unsigned config_interval = ProcData::get_instance()->config.update_interval; g_assert(this->interval >= config_interval); if (not this->active) return false; const unsigned pcpu = this->get_own_cpu_usage(); /* invariant: MAX_UPDATE_INTERVAL >= interval >= config_interval >= MIN_UPDATE_INTERVAL i see 3 cases: a) interval is too big (CPU usage < 10%) -> increase interval b) interval is too small (CPU usage > 10%) AND interval != config_interval > -> decrease interval c) interval is config_interval (start or interval is perfect) */ if (pcpu > PCPU_HI && this->last_pcpu > PCPU_HI) new_interval = this->interval * 11 / 10; else if (this->interval != config_interval && pcpu < PCPU_LO && this->last_pcpu < PCPU_LO) new_interval = this->interval * 9 / 10; else new_interval = this->interval; new_interval = CLAMP(new_interval, config_interval, config_interval * 2); new_interval = CLAMP(new_interval, MIN_UPDATE_INTERVAL, MAX_UPDATE_INTERVAL); bool changed = this->interval != new_interval; if (changed) this->interval = new_interval; this->last_pcpu = pcpu; if (changed) { procman_debug("CPU usage is %3u%%, changed refresh_interval to %u (config %u)", this->last_pcpu, this->interval, config_interval); } g_assert(this->interval == new_interval); g_assert(this->interval >= config_interval); return changed; }
void update(GtkSpinButton* spin) { int new_value = int(1000 * gtk_spin_button_get_value(spin)); GError* e = 0; if (not mateconf_client_set_int(ProcData::get_instance()->client, this->mateconf_key.c_str(), new_value, &e)) { g_warning("Failed to mateconf_client_set_int %s %d : %s\n", this->mateconf_key.c_str(), new_value, e->message); g_error_free(e); } procman_debug("set %s to %d", this->mateconf_key.c_str(), new_value); }
void SmoothRefresh::load_gconf_value(GConfValue* value) { bool own_value = false; if (not value) { value = gconf_client_get(gconf_client_get_default(), KEY.c_str(), NULL); } this->active = value ? gconf_value_get_bool(value) : KEY_DEFAULT_VALUE; if (this->active) procman_debug("smooth_refresh is enabled"); if (own_value and value) gconf_value_free(value); }
/* * type determines whether if dialog is for killing process or renice. * type == PROCMAN_ACTION_KILL, extra_value -> signal to send * type == PROCMAN_ACTION_RENICE, extra_value -> new priority. */ gboolean procdialog_create_root_password_dialog(ProcmanActionType type, ProcData *procdata, gint pid, gint extra_value) { char * command; gboolean ret = FALSE; command = procman_action_to_command(type, pid, extra_value); procman_debug("Trying to run '%s' as root", command); if (procman_has_gksu()) ret = procman_gksu_create_root_password_dialog(command); else if (procman_has_matesu()) ret = procman_matesu_create_root_password_dialog(command); g_free(command); return ret; }
/* * type determines whether if dialog is for killing process or renice. * type == PROCMAN_ACTION_KILL, extra_value -> signal to send * type == PROCMAN_ACTION_RENICE, extra_value -> new priority. */ gboolean procdialog_create_root_password_dialog(ProcmanActionType type, GsmApplication *app, gint pid, gint extra_value) { char * command; gboolean ret = FALSE; command = procman_action_to_command(type, pid, extra_value); procman_debug("Trying to run '%s' as root", command); if (procman_has_pkexec()) ret = gsm_pkexec_create_root_password_dialog(command); else if (procman_has_gksu()) ret = gsm_gksu_create_root_password_dialog(command); else if (procman_has_gnomesu()) ret = gsm_gnomesu_create_root_password_dialog(command); g_free(command); return ret; }
static void net_scale (LoadGraph *g, unsigned din, unsigned dout) { g->data[0][0] = 1.0f * din / g->net.max; g->data[0][1] = 1.0f * dout / g->net.max; unsigned dmax = std::max(din, dout); g->net.values[g->net.cur] = dmax; g->net.cur = (g->net.cur + 1) % LoadGraph::NUM_POINTS; unsigned new_max; // both way, new_max is the greatest value if (dmax >= g->net.max) new_max = dmax; else new_max = *std::max_element(&g->net.values[0], &g->net.values[LoadGraph::NUM_POINTS]); // // Round network maximum // const unsigned bak_max(new_max); // round up to get some extra space new_max = 11U * new_max / 10U; // make sure max is not 0 to avoid / 0 // default to 1 KiB new_max = std::max(new_max, 1024U); // decompose new_max = coef10 * 2**(base10 * 10) // where coef10 and base10 are integers and coef10 < 2**10 // // e.g: ceil(100.5 KiB) = 101 KiB = 101 * 2**(1 * 10) // where base10 = 1, coef10 = 101, pow2 = 16 unsigned pow2 = std::floor(log2(new_max)); unsigned base10 = pow2 / 10; unsigned coef10 = std::ceil(new_max / double(1UL << (base10 * 10))); g_assert(new_max <= (coef10 * (1UL << (base10 * 10)))); // then decompose coef10 = x * 10**factor10 // where factor10 is integer and x < 10 // so we new_max has only 1 significant digit unsigned factor10 = std::pow(10.0, std::floor(std::log10(coef10))); coef10 = std::ceil(coef10 / double(factor10)) * factor10; // then make coef10 divisible by num_bars if (coef10 % g->num_bars() != 0) coef10 = coef10 + (g->num_bars() - coef10 % g->num_bars()); g_assert(coef10 % g->num_bars() == 0); new_max = coef10 * (1UL << (base10 * 10)); procman_debug("bak %u new_max %u pow2 %u coef10 %u", bak_max, new_max, pow2, coef10); g_assert(bak_max <= new_max); if (new_max == g->net.max) return; // if max has decreased but not so much, don't do anything // to avoid rescaling if ((8U * g->net.max / 10U) < new_max && new_max < g->net.max) return; const float scale = 1.0f * g->net.max / new_max; for (size_t i = 0; i < LoadGraph::NUM_POINTS; i++) { if (g->data[i][0] >= 0.0f) { g->data[i][0] *= scale; g->data[i][1] *= scale; } } procman_debug("dmax = %u max = %u new_max = %u", dmax, g->net.max, new_max); g->net.max = new_max; // force the graph background to be redrawn now that scale has changed if (g->background) { g_object_unref (g->background); g->background = NULL; } }