Ejemplo n.º 1
0
double thinkpad_fan::power_usage(struct result_bundle *result, struct parameter_bundle *bundle)
{
	double power;
	double factor;
	double util;


	power = 0;
	util = get_result_value(r_index, result);

	if (util < 0)
		util = 0;


	/* physics dictact that fan power goes cubic with the rpms, but there's also a linear component for friction*/
	factor = get_parameter_value(fancub_index, bundle);
	power += factor * pow(util / 3600.0, 3);

	factor = get_parameter_value(fansqr_index, bundle) - 5.0;
	power += factor * pow(util / 3600.0, 2);

	factor = get_parameter_value(fan_index, bundle) - 10.0;
	power += util / 5000.0 * factor;

	if (power <= 0.0)
		power = 0.0;

	return power;
}
double logarithmic_function::f( double x ) const {
	double logarg( x + get_parameter_value( 1 ) );
	if( logarg == 0 ) {
		logarg = std::numeric_limits<double>::epsilon();
	}
	return get_parameter_value( 0 ) * std::log( logarg ) + get_parameter_value( 2 );
}
double hyperbola_function::f( double x ) const {
	double denominator( x + get_parameter_value( 1 ) );
	if( denominator == 0 ) {
		denominator = std::numeric_limits<double>::epsilon();
	}
	return get_parameter_value( 0 ) / denominator + get_parameter_value( 2 );
}
std::vector<double> exponential_function::df( double x ) const {
	std::vector<double> value( num_parameters() );
	double exponential( std::exp( get_parameter_value( 1 ) * x ) );
	value.at( 0 ) = exponential;
	value.at( 1 ) = get_parameter_value( 0 ) * x * exponential;
	value.at( 2 ) = 1;
	return value;
}
std::vector<double> logarithmic_function::df( double x ) const {
	std::vector<double> value( num_parameters() );
	double logarg( x + get_parameter_value( 1 ) );
	if( logarg == 0 ) {
		logarg = std::numeric_limits<double>::epsilon();
	}
	value.at( 0 ) = std::log( logarg );
	value.at( 1 ) = get_parameter_value( 0 ) / logarg;
	value.at( 2 ) = 1;
	return value;
}
std::vector<double> hyperbola_function::df( double x ) const {
	std::vector<double> value( num_parameters() );
	double denominator( get_parameter_value( 1 ) + x );
	if( denominator == 0 ) {
		denominator = std::numeric_limits<double>::epsilon();
	}
	value.at( 0 ) = 1 / denominator;
	value.at( 1 ) = - get_parameter_value( 0 ) / (denominator * denominator);
	value.at( 2 ) = 1;
	return value;
}
Ejemplo n.º 7
0
	bool operator()(SerializedCall const &serialized_call_, FusionVector &fusion_vector, ParamValueIter iter, ParamValueIter end) const
	{
		if (iter == end)
		{
			typename serialized_call_traits < SerializedCall > ::parameters_t parameters = get_parameters(serialized_call_);
			throw missing_call_parameters(get_function_name(serialized_call_), std::distance(parameters.begin(), parameters.end()));
		}

		typedef typename boost::remove_cv < typename boost::fusion::result_of::value_of < FusionVectorIter > ::type > ::type param_type_t;

		// Retrieve the value from the current element parameter sequence. The current element is (*iter).

		param_type_t param_value;
		if (get_parameter_value(serialized_call_, *iter, param_value))
		{
			// Store the value in the fusion vector
			// TODO: use fusion iterators instead of an index (if it makes sense; run-time fusion iterators need to be used here)
			boost::fusion::at_c < Index > (fusion_vector) = param_value;

			// Move to the next element
			ParamValueIter next_iter = iter;
			std::advance(next_iter, 1);

			// Next iteration (using recursion)
			return set_parameter_fusion_vector_value < SerializedCall, FusionVector, typename boost::fusion::result_of::next < FusionVectorIter > ::type, ParamValueIter, Index + 1 > ()(serialized_call_, fusion_vector, next_iter, end);
		}
		else
			return false;
	}
Ejemplo n.º 8
0
/*!	\brief Constructs a PPP protocol.
	
	If you are creating a normal protocol use a level of \c PPP_PROTOCOL_LEVEL.
	Encapsulators like compression protocols should use a different level. \n
	Authenticators are identified by a type string equal to "Authenticator" and they
	have an optionHandler that implements only the following methods:
	- AddToRequest
	- ParseRequest
	
	\param name The protocol name.
	\param activationPhase Our activation phase.
	\param protocolNumber Our protocol number.
	\param level The level at which we get inserted into the list of protocols.
	\param addressFamily The address family.  Values < 0 and > 0xFF are ignored.
	\param overhead The protocol's header size.
	\param interface The owner.
	\param settings Our settings.
	\param flags Optional flags. See \c ppp_protocol_flags for more information.
	\param type Optional type string. Used by authenticators, for example.
	\param optionHandler Optional handler associated with this protocol.
*/
KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase,
	uint16 protocolNumber, ppp_level level, int32 addressFamily,
	uint32 overhead, KPPPInterface& interface,
	driver_parameter *settings, int32 flags,
	const char *type, KPPPOptionHandler *optionHandler)
	:
	KPPPLayer(name, level, overhead),
	fActivationPhase(activationPhase),
	fProtocolNumber(protocolNumber),
	fAddressFamily(addressFamily),
	fInterface(interface),
	fSettings(settings),
	fFlags(flags),
	fOptionHandler(optionHandler),
	fNextProtocol(NULL),
	fEnabled(true),
	fUpRequested(true),
	fConnectionPhase(PPP_DOWN_PHASE)
{
	if (type)
		fType = strdup(type);
	else
		fType = NULL;
	
	const char *sideString = get_parameter_value("side", settings);
	if (sideString)
		fSide = get_side_string_value(sideString, PPP_LOCAL_SIDE);
	else {
		if (interface.Mode() == PPP_CLIENT_MODE)
			fSide = PPP_LOCAL_SIDE;
		else
			fSide = PPP_PEER_SIDE;
	}
}
Ejemplo n.º 9
0
double cpudevice::power_usage(struct result_bundle *result, struct parameter_bundle *bundle)
{
	double power;
	double factor;
	double _utilization;

	power = 0;
	factor = get_parameter_value(wake_index, bundle);
	_utilization = get_result_value(r_wake_index, result);

	power += _utilization * factor / 10000.0;

	factor = get_parameter_value(consumption_index, bundle);
	_utilization = get_result_value(r_consumption_index, result);

	power += _utilization * factor;

	return power;
}
Ejemplo n.º 10
0
/*
Parses the 'settings' file under the program data folder 
and sets the corresponding 'global' variables appropriately.

@param data_path The absolute path of the program's data folder.
*/
void fetch_settings(char* data_path){
	char* settings_path = (char*)malloc(sizeof(char)*50);
	if(settings_path == NULL){
		log_event("<fetch_settings>", "Error allocating memory",ERRO);
		exit(EXIT_ERR_ALLOC_MEM);
	}
	strcat_mult_str(4, settings_path, data_path, SETTINGSFOLD_NAME);
	FILE* settings_file = fopen(settings_path, "r");
	
	if(settings_file == NULL){
		log_event("<fetch_settings>", "Error opening settings file", ERRO);
		exit(EXIT_ERR_OPEN_SETTINGS); // document this
	}

	int c;
	char variable_string[40];
	while((c = fscanf(settings_file,"%s",variable_string)) != -1){
		int value = get_parameter_value(variable_string);
		switch(variable_string[0]){
			case 'N':
				NR_MAX_DISCOVERED_DEVICES = value;
				break;

			case 'M':
				MAX_HISTORY_LEN = value;
				break;

			case 'S':
				SLEEP_TIME = value;
				break;

			case 'T':
				TIME_PER_SCAN = value;
				break;

			case 'G':
				GREET_USER = value;
				break;

			default:
				log_event("<fetch_settings>", "Unkown setting in settings file",WARN);
				break;
		}
	}

	fclose(settings_file);
	free(settings_path);
}
std::ostream & exponential_function::print( std::ostream & os ) const {
	return os << "f(x) = " << get_parameter_value( 0 ) << " * exp(" << get_parameter_value( 1 ) << " * x) + " << get_parameter_value( 2 );
}
double exponential_function::f( double x ) const {
	return get_parameter_value( 0 ) * std::exp( get_parameter_value( 1 ) * x ) + get_parameter_value( 2 );
}
std::ostream & logarithmic_function::print( std::ostream & os ) const {
	return os << "f(x) = " << get_parameter_value( 0 ) << " * log(x + " << get_parameter_value( 1 ) << ") + " << get_parameter_value( 2 );
}
Ejemplo n.º 14
0
/*%
 * Create an instance of the module.
 */
isc_result_t
dlz_create(const char *dlzname, unsigned int argc, char *argv[],
	   void **dbdata, ...)
{
	isc_result_t result = ISC_R_FAILURE;
	mysql_instance_t *mysql = NULL;
	dbinstance_t *dbi = NULL;
	MYSQL *dbc;
	char *tmp = NULL;
	char *endp;
	int j;
	const char *helper_name;
#if MYSQL_VERSION_ID >= 50000
        my_bool auto_reconnect = 1;
#endif
#if PTHREADS
	int dbcount;
	int i;
#endif /* PTHREADS */
	va_list ap;

	UNUSED(dlzname);

	/* allocate memory for MySQL instance */
	mysql = calloc(1, sizeof(mysql_instance_t));
	if (mysql == NULL)
		return (ISC_R_NOMEMORY);
	memset(mysql, 0, sizeof(mysql_instance_t));

	/* Fill in the helper functions */
	va_start(ap, dbdata);
	while ((helper_name = va_arg(ap, const char*)) != NULL)
		b9_add_helper(mysql, helper_name, va_arg(ap, void*));
	va_end(ap);

#if PTHREADS
	/* if debugging, let user know we are multithreaded. */
	mysql->log(ISC_LOG_DEBUG(1), "MySQL module running multithreaded");
#else /* PTHREADS */
	/* if debugging, let user know we are single threaded. */
	mysql->log(ISC_LOG_DEBUG(1), "MySQL module running single threaded");
#endif /* PTHREADS */

	/* verify we have at least 4 arg's passed to the module */
	if (argc < 4) {
		mysql->log(ISC_LOG_ERROR,
			   "MySQL module requires "
			   "at least 4 command line args.");
		return (ISC_R_FAILURE);
	}

	/* no more than 8 arg's should be passed to the module */
	if (argc > 8) {
		mysql->log(ISC_LOG_ERROR,
			   "MySQL module cannot accept "
			   "more than 7 command line args.");
		return (ISC_R_FAILURE);
	}

	/* get db name - required */
	mysql->dbname = get_parameter_value(argv[1], "dbname=");
	if (mysql->dbname == NULL) {
		mysql->log(ISC_LOG_ERROR,
			   "MySQL module requires a dbname parameter.");
		result = ISC_R_FAILURE;
		goto cleanup;
	}

	/* get db port.  Not required, but must be > 0 if specified */
	tmp = get_parameter_value(argv[1], "port=");
	if (tmp == NULL)
		mysql->port = 0;
	else {
		mysql->port = strtol(tmp, &endp, 10);
		if (*endp != '\0' || mysql->port < 0) {
			mysql->log(ISC_LOG_ERROR,
				   "Mysql module: port "
				   "must be a positive number.");
			free(tmp);
			result = ISC_R_FAILURE;
			goto cleanup;
		}
		free(tmp);
	}

	mysql->host = get_parameter_value(argv[1], "host=");
	mysql->user = get_parameter_value(argv[1], "user="******"pass="******"socket=");

	mysql->flags = CLIENT_REMEMBER_OPTIONS;

	tmp = get_parameter_value(argv[1], "compress=");
	if (tmp != NULL) {
		if (strcasecmp(tmp, "true") == 0)
			mysql->flags |= CLIENT_COMPRESS;
		free(tmp);
	}

	tmp = get_parameter_value(argv[1], "ssl=");
	if (tmp != NULL) {
		if (strcasecmp(tmp, "true") == 0)
			mysql->flags |= CLIENT_SSL;
		free(tmp);
	}

	tmp = get_parameter_value(argv[1], "space=");
	if (tmp != NULL) {
		if (strcasecmp(tmp, "ignore") == 0)
			mysql->flags |= CLIENT_IGNORE_SPACE;
		free(tmp);
	}

#if PTHREADS
	/* multithreaded build can have multiple DB connections */
	tmp = get_parameter_value(argv[1], "threads=");
	if (tmp == NULL)
		dbcount = 1;
	else {
		dbcount = strtol(tmp, &endp, 10);
		if (*endp != '\0' || dbcount < 1) {
			mysql->log(ISC_LOG_ERROR,
				   "MySQL database connection count "
				   "must be positive.");
			free(tmp);
			result = ISC_R_FAILURE;
			goto cleanup;
		}
		free(tmp);
	}

	/* allocate memory for database connection list */
	mysql->db = calloc(1, sizeof(db_list_t));
	if (mysql->db == NULL) {
		result = ISC_R_NOMEMORY;
		goto cleanup;
	}

	/* initialize DB connection list */
	DLZ_LIST_INIT(*(mysql->db));

	/*
	 * create the appropriate number of database instances (DBI)
	 * append each new DBI to the end of the list
	 */
	for (i = 0; i < dbcount; i++) {
#endif /* PTHREADS */
		switch(argc) {
		case 4:
			result = build_dbinstance(NULL, NULL, NULL,
						  argv[2], argv[3], NULL,
						  &dbi, mysql->log);
			break;
		case 5:
			result = build_dbinstance(NULL, NULL, argv[4],
						  argv[2], argv[3], NULL,
						  &dbi, mysql->log);
			break;
		case 6:
			result = build_dbinstance(argv[5], NULL, argv[4],
						  argv[2], argv[3], NULL,
						  &dbi, mysql->log);
			break;
		case 7:
			result = build_dbinstance(argv[5], argv[6], argv[4],
						  argv[2], argv[3], NULL,
						  &dbi, mysql->log);
			break;
		case 8:
			result = build_dbinstance(argv[5], argv[6], argv[4],
						  argv[2], argv[3], argv[7],
						  &dbi, mysql->log);
			break;
		default:
			result = ISC_R_FAILURE;
		}


		if (result != ISC_R_SUCCESS) {
			mysql->log(ISC_LOG_ERROR,
				   "MySQL module could not create "
				   "database instance object.");
			result = ISC_R_FAILURE;
			goto cleanup;
		}

#if PTHREADS
		/* when multithreaded, build a list of DBI's */
		DLZ_LINK_INIT(dbi, link);
		DLZ_LIST_APPEND(*(mysql->db), dbi, link);
#else
		/*
		 * when single threaded, hold onto the one connection
		 * instance.
		 */
		mysql->db = dbi;
#endif

		/* create and set db connection */
		dbi->dbconn = mysql_init(NULL);
		if (dbi->dbconn == NULL) {
			mysql->log(ISC_LOG_ERROR,
				   "MySQL module could not allocate "
				   "memory for database connection");
			result = ISC_R_FAILURE;
			goto cleanup;
		}

		dbc = NULL;

#if MYSQL_VERSION_ID >= 50000
		/* enable automatic reconnection. */
		if (mysql_options((MYSQL *) dbi->dbconn, MYSQL_OPT_RECONNECT,
				  &auto_reconnect) != 0) {
			mysql->log(ISC_LOG_WARNING,
				   "MySQL module failed to set "
				   "MYSQL_OPT_RECONNECT option, continuing");
		}
#endif

		for (j = 0; dbc == NULL && j < 4; j++) {
			dbc = mysql_real_connect((MYSQL *) dbi->dbconn,
						 mysql->host, mysql->user,
						 mysql->pass, mysql->dbname,
						 mysql->port, mysql->socket,
						 mysql->flags);
			if (dbc == NULL)
				mysql->log(ISC_LOG_ERROR,
					   "MySQL connection failed: %s",
					   mysql_error((MYSQL *) dbi->dbconn));
		}

		if (dbc == NULL) {
			mysql->log(ISC_LOG_ERROR,
				   "MySQL module failed to create "
				   "database connection after 4 attempts");
			result = ISC_R_FAILURE;
			goto cleanup;
		}

#if PTHREADS
		/* set DBI = null for next loop through. */
		dbi = NULL;
	}
#endif /* PTHREADS */

	*dbdata = mysql;

	return (ISC_R_SUCCESS);

 cleanup:
	dlz_destroy(mysql);

	return (result);
}
Ejemplo n.º 15
0
void process_update_display(void)
{
#ifndef DISABLE_NCURSES
	unsigned int i;
	WINDOW *win;
	double pw;
	int tl;
	int tlt; 
	int tlr;

	int show_power;
	int need_linebreak = 0;

	sort(all_power.begin(), all_power.end(), power_cpu_sort);

	show_power = global_power_valid();

	win = get_ncurses_win("Overview");
	if (!win)
		return;

	wclear(win);

	wmove(win, 1,0);

#if 0
	double sum;
	calculate_params();
	sum = 0.0;
	sum += get_parameter_value("base power");
	for (i = 0; i < all_power.size(); i++) {
		sum += all_power[i]->Witts();
	}

	wprintw(win, _("Estimated power: %5.1f    Measured power: %5.1f    Sum: %5.1f\n\n"),
				all_parameters.guessed_power, global_joules_consumed(), sum);
#endif

	pw = global_joules_consumed();
	tl = global_time_left() / 60;
	tlt = (tl /60);
	tlr = tl % 60;

	if (pw > 0.0001) {
		char buf[32];
		wprintw(win, _("The battery reports a discharge rate of %sW\n"),
				fmt_prefix(pw, buf));
		need_linebreak = 1;
	}
	if (tl > 0 && pw > 0.0001) {
		wprintw(win, _("The estimated remaining time is %i hours, %i minutes\n"), tlt, tlr);
		need_linebreak = 1;
	}

	if (need_linebreak)
		wprintw(win, "\n");


	wprintw(win, "%s: %3.1f %s,  %3.1f %s, %3.1f %s %3.1f%% %s\n\n",_("Summary"), total_wakeups(), _("wakeups/second"), total_gpu_ops(), _("GPU ops/seconds"), total_disk_hits(), _("VFS ops/sec and"), total_cpu_time()*100, _("CPU use"));


	if (show_power)
		wprintw(win, "%s              %s       %s    %s       %s\n", _("Power est."), _("Usage"), _("Events/s"), _("Category"), _("Description"));
	else
		wprintw(win, "                %s       %s    %s       %s\n", _("Usage"), _("Events/s"), _("Category"), _("Description"));

	for (i = 0; i < all_power.size(); i++) {
		char power[16];
		char name[20];
		char usage[20];
		char events[20];
		char descr[128];
		format_watts(all_power[i]->Witts(), power, 10);

		if (!show_power)
			strcpy(power, "          ");
		sprintf(name, "%s", all_power[i]->type());
		while (mbstowcs(NULL,name,0) < 14) strcat(name, " ");


		if (all_power[i]->events() == 0 && all_power[i]->usage() == 0 && all_power[i]->Witts() == 0)
			break;

		usage[0] = 0;
		if (all_power[i]->usage_units()) {
			if (all_power[i]->usage() < 1000)
				sprintf(usage, "%5.1f%s", all_power[i]->usage(), all_power[i]->usage_units());
			else
				sprintf(usage, "%5i%s", (int)all_power[i]->usage(), all_power[i]->usage_units());
		}
		while (mbstowcs(NULL,usage,0) < 14) strcat(usage, " ");
		sprintf(events, "%5.1f", all_power[i]->events());
		if (!all_power[i]->show_events())
			events[0] = 0;
		else if (all_power[i]->events() <= 0.3)
			sprintf(events, "%5.2f", all_power[i]->events());

		while (strlen(events) < 12) strcat(events, " ");
		wprintw(win, "%s  %s %s %s %s\n", power, usage, events, name, pretty_print(all_power[i]->description(), descr, 128));
	}
#endif // DISABLE_NCURSES
}
std::ostream & hyperbola_function::print( std::ostream & os ) const {
	return os << "f(x) = " << get_parameter_value( 0 ) << " / (x + " << get_parameter_value( 1 ) << ") + " << get_parameter_value( 2 );
}