コード例 #1
0
ファイル: collision.c プロジェクト: metredigm/hunter
int get_axis_seperating(collision_vec2* axis, collision_box first, collision_box second) {
	float first_interval_min = -1.0f, first_interval_max = -1.0f;
	float second_interval_min = -1.0f, second_interval_max = -1.0f;
	float axis_length = sqrt(pow(axis->x, 2) + pow(axis->y, 2));

	if (!axis_length) {
		return 0;
	}

	axis->x /= axis_length;
	axis->y /= axis_length;

	if (get_interval(*axis, first, &first_interval_min, &first_interval_max) < 0.0f) {
		printf("[collision_rect_overlap] ALGORITHM FAILURE\n");
	}

	if (get_interval(*axis, second, &second_interval_min, &second_interval_max) < 0.0f) {
		printf("[collision_rect_overlap] ALGORITHM FAILURE\n");
	}

	//printf("[get_axis_seperating] first interval : %f->%f, second interval : %f->%f\n", first_interval_min, first_interval_max, second_interval_min, second_interval_max);

	if (first_interval_min > second_interval_max || second_interval_min > first_interval_max) {
		return 1;
	}

	float overlap_depth = fmin(first_interval_max - second_interval_min, second_interval_max - first_interval_min);

	axis->x *= overlap_depth;// / axis_length;
	axis->y *= overlap_depth;// / axis_length;

	return 0;
}
コード例 #2
0
ファイル: collector.cpp プロジェクト: brennane/gridpot
TIMESTAMP collector::commit(TIMESTAMP t0, TIMESTAMP t1)
{
	TIMESTAMP dt = (TIMESTAMP)get_interval();
	if ( dt==0 || ( t1==next_t && next_t!=TS_NEVER ) )
	{
		char buffer[4096];
		size_t eos = sprintf(buffer,"INSERT INTO `%s` (t", get_table());
		int n;
		for ( n=0 ; n<n_aggregates ; n++ )
			eos += sprintf(buffer+eos,",`%s`",names[n]);
		eos += sprintf(buffer+eos,") VALUES (from_unixtime(%lli)",gl_globalclock);
		for ( n=0 ; n<n_aggregates ; n++ )
			eos += sprintf(buffer+eos,",%g",list[n].get_value());
		sprintf(buffer+eos,"%s",")");

		if ( !db->query(buffer) )
			exception("unable to add data to '%s' - %s", get_table(), mysql_error(mysql));
		else
			gl_verbose("%s: sample added to '%s' ok", get_name(), get_table());

		// check limit
		if ( get_limit()>0 && db->get_last_index()>=get_limit() )
		{
			gl_verbose("%s: limit of %d records reached", get_name(), get_limit());
			next_t = TS_NEVER;
		}
		else
		{
			next_t = (dt==0 ? TS_NEVER : (TIMESTAMP)(t1/dt+1)*dt);
		}
		set_clock(t1);
	}
	return TS_NEVER;
}
コード例 #3
0
void Simulator::run_simulation(int time)
{
	srand(time);
	int interval = get_interval(time);

	for (int i = 0; i < time; i++)
	{
        elevator_system_ptr->tick(i);
		if (i%interval ==0)
		{
			int from = rand() % 12;
			int to = rand() % 12;

			while (from == to)
			{
				from = rand() % 12 + 1;
				to = rand() % 12 + 1;
			}
            cout << "Making new passenger, floor: " << from << " to " << to << endl;
			Passenger * temp_passenger = new Passenger(from, to);
				//randomly generate floor from, floor to 
			temp_passenger->set_call_time(i);
            elevator_system_ptr->call_elevator(temp_passenger);

		}
	}
}
コード例 #4
0
ファイル: sar.c プロジェクト: Embedded-linux/sysstat
/*
 ***************************************************************************
 * Print statistics average.
 *
 * IN:
 * @curr		Index in array for current sample statistics.
 * @read_from_file	Set to TRUE if stats are read from a system activity
 * 			data file.
 * @act_id		Activity that can be displayed, or ~0 for all.
 *			Remember that when reading stats from a file, only
 *			one activity can be displayed at a time.
 ***************************************************************************
 */
void write_stats_avg(int curr, int read_from_file, unsigned int act_id)
{
	int i;
	unsigned long long itv, g_itv;
	static __nr_t cpu_nr = -1;

	if (cpu_nr < 0)
		cpu_nr = act[get_activity_position(act, A_CPU)]->nr;

	/* Interval value in jiffies */
	g_itv = get_interval(record_hdr[2].uptime, record_hdr[curr].uptime);

	if (cpu_nr > 1)
		itv = get_interval(record_hdr[2].uptime0, record_hdr[curr].uptime0);
	else
		itv = g_itv;

	strncpy(timestamp[curr], _("Average:"), TIMESTAMP_LEN);
	timestamp[curr][TIMESTAMP_LEN - 1] = '\0';
	strcpy(timestamp[!curr], timestamp[curr]);

	/* Test stdout */
	TEST_STDOUT(STDOUT_FILENO);

	for (i = 0; i < NR_ACT; i++) {

		if ((act_id != ALL_ACTIVITIES) && (act[i]->id != act_id))
			continue;

		if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
			/* Display current average activity statistics */
			(*act[i]->f_print_avg)(act[i], 2, curr,
					       NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv);
		}
	}

	if (read_from_file) {
		/*
		 * Reset number of lines printed only if we read stats
		 * from a system activity file.
		 */
		avg_count = 0;
	}
}
コード例 #5
0
/*
 ***************************************************************************
 * Print statistics average
 *
 * IN:
 * @curr		Index in array for current sample statistics.
 * @read_from_file	Set to TRUE if stats are read from a system activity
 * 			data file.
 * @act_id		Activity that can be displayed, or ~0 for all.
 *			Remember that when reading stats from a file, only
 *			one activity can be displayed at a time.
 ***************************************************************************
 */
void write_stats_avg(int curr, int read_from_file, unsigned int act_id)
{
	int i;
	unsigned long long itv, g_itv;
	static __nr_t cpu_nr = -1;
	
	if (cpu_nr < 0)
		cpu_nr = act[get_activity_position(act, A_CPU)]->nr;

	/* Interval value in jiffies */
	g_itv = get_interval(record_hdr[2].uptime, record_hdr[curr].uptime);

	if (cpu_nr > 1)
		itv = get_interval(record_hdr[2].uptime0, record_hdr[curr].uptime0);
	else
		itv = g_itv;

	strcpy(timestamp[curr], _("Average:"));
	strcpy(timestamp[!curr], timestamp[curr]);
	
	/* Test stdout */
	TEST_STDOUT(STDOUT_FILENO);
	
	for (i = 0; i < NR_ACT; i++) {
		
		if ((act_id != ALL_ACTIVITIES) && (act[i]->id != act_id))
			continue;
		
		if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
			/* Display current average activity statistics */
			if (NEEDS_GLOBAL_ITV(act[i]->options))
				(*act[i]->f_print_avg)(act[i], 2, curr, g_itv);
			else
				(*act[i]->f_print_avg)(act[i], 2, curr, itv);
		}
	}

	if (read_from_file) {
		/* Reset counters only if we read stats from a system activity file */
		memset(&asum, 0, STATS_SUM_SIZE);
	}
}
コード例 #6
0
ファイル: ace_search.c プロジェクト: idx0/ace
static void print_uci_info(app_t *app, int depth, int score)
{
	ms_time_t tm;
	u64 i, s;

	get_current_tick(&tm);
	i = get_interval(&app->search.start, &tm);
	s = i / 1000;

	printf("info depth %d score cp %d time %lld nodes %lld nps %lld pv ",
		depth, score,
		i, app->search.nodes,
		/* we are calculating average nps here - to calculate true nps we should
		   only consider the nodes searched and time interval for this depth */
		(s != 0 ? app->search.nodes / s : app->search.nodes));
	print_pv(app, depth);
	printf("\n");
}
コード例 #7
0
void GeneralTab::updateFrameInterval()
{
	v4l2_frmivalenum frmival;
	v4l2_fract curr;
	bool curr_ok, ok;

	m_frameInterval->clear();

	ok = enum_frameintervals(frmival, m_pixelformat, m_width, m_height);
	curr_ok = get_interval(curr);
	if (ok && frmival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
		do {
			m_frameInterval->addItem(QString("%1 fps")
				.arg((double)frmival.discrete.denominator / frmival.discrete.numerator));
			if (curr_ok &&
			    frmival.discrete.numerator == curr.numerator &&
			    frmival.discrete.denominator == curr.denominator)
				m_frameInterval->setCurrentIndex(frmival.index);
		} while (enum_frameintervals(frmival));
	}
}
コード例 #8
0
ファイル: sysmon.c プロジェクト: RPI-WCL/sysmon
/* "pkill --signal 2 sysmon" will be captured here. */
void signal_callback_handler(int signum)
{
    struct stats st;
    struct ext_stats ext_st;
    unsigned long long interval;

    printf("\nCaught signal %d\n", signum);

    /* Overall stats calculation */
    read_stats(&st);
    interval = get_interval(base_stats.uptime, st.uptime);

    /* Overall stats output */
    fprintf(fp, "Mean:\n");
    #if 1
    subst_stats(&st, &base_stats);      /* st -= base_stats */
    fprint_stats(fp, print_flag | MEM_USED_DBL, &st, &mean);
    #else
    compute_ext_stats(interval, &st, &base_stats, &ext_st);
    ext_st.mem = mean.mem;
    subst_stats(&st, &base_stats);      /* st -= base_stats */
    fprint_stats(fp, print_flag | MEM_USED_DBL, &st, &ext_st);
    #endif

    #if 0
    fprintf(fp, "Minimum:\n");
    fprint_stats(fp, print_flag, &st, &min);
    fprintf(fp, "Maximum:\n");
    fprint_stats(fp, print_flag, &st, &max);
    fprintf(fp, "Variance:\n");
    fprint_stats(fp, print_flag | MEM_USED_DBL, &st, &var);
    #endif

    /* All done! */
    #ifndef DEBUG
    fclose(fp);
    #endif
    exit(signum);
}
コード例 #9
0
ファイル: announce.c プロジェクト: robertseaton/slug
void 
http_announce(struct Torrent *t, int8_t event, CURL *connection, struct event_base *base)
{
     int32_t length = strlen(t->name) + strlen("/tmp/slug/-announce") + 1;
     char *filepath = malloc(length);
     char *url = construct_url(t, event);
     snprintf(filepath, length, "/tmp/slug/%s-announce", t->name);
     FILE *announce_data = fopen(filepath, "w");

     curl_easy_setopt(connection, CURLOPT_URL, url);
     curl_easy_setopt(connection, CURLOPT_WRITEDATA, announce_data);
     curl_easy_perform(connection);

     fclose(announce_data);
     announce_data = fopen(filepath, "r");

     /* read announce response into array */
     fseek(announce_data, 0, SEEK_END);
     int32_t pos = ftell(announce_data);
     fseek(announce_data, 0, SEEK_SET);
     char *data = malloc(pos);
     fread(data, pos, 1, announce_data);
     
     int64_t x = 0;
     struct BEncode *announceBEncode = parseBEncode(data, &x);

     assert(announceBEncode->type == BDict);
     if (failed(announceBEncode->cargo.bDict))
          pfailure_reason(announceBEncode->cargo.bDict);
     else {
          get_peers(t, data);
          t->announce_interval = get_interval(announceBEncode->cargo.bDict);
     }

     free(data);
     free(filepath);
     freeBEncode(announceBEncode);
}
コード例 #10
0
ファイル: iostat.c プロジェクト: jimis/sysstat
/*
 ***************************************************************************
 * Print everything now (stats and uptime).
 *
 * IN:
 * @curr	Index in array for current sample statistics.
 * @rectime	Current date and time.
 ***************************************************************************
 */
void write_stats(int curr, struct tm *rectime)
{
	int dev, i, fctr = 1;
	unsigned long long itv;
	struct io_hdr_stats *shi;
	struct io_dlist *st_dev_list_i;

	/* Test stdout */
	TEST_STDOUT(STDOUT_FILENO);

	/* Print time stamp */
	if (DISPLAY_TIMESTAMP(flags)) {
		if (DISPLAY_ISO(flags)) {
			strftime(timestamp, sizeof(timestamp), "%FT%T%z", rectime);
		}
		else {
			strftime(timestamp, sizeof(timestamp), "%x %X", rectime);
		}
		printf("%s\n", timestamp);
#ifdef DEBUG
		if (DISPLAY_DEBUG(flags)) {
			fprintf(stderr, "%s\n", timestamp);
		}
#endif
	}

	/* Interval is multiplied by the number of processors */
	itv = get_interval(uptime[!curr], uptime[curr]);

	if (DISPLAY_CPU(flags)) {
#ifdef DEBUG
		if (DISPLAY_DEBUG(flags)) {
			/* Debug output */
			fprintf(stderr, "itv=%llu st_cpu[curr]{ cpu_user=%llu cpu_nice=%llu "
					"cpu_sys=%llu cpu_idle=%llu cpu_iowait=%llu cpu_steal=%llu "
					"cpu_hardirq=%llu cpu_softirq=%llu cpu_guest=%llu "
					"cpu_guest_nice=%llu }\n",
				itv,
				st_cpu[curr]->cpu_user,
				st_cpu[curr]->cpu_nice,
				st_cpu[curr]->cpu_sys,
				st_cpu[curr]->cpu_idle,
				st_cpu[curr]->cpu_iowait,
				st_cpu[curr]->cpu_steal,
				st_cpu[curr]->cpu_hardirq,
				st_cpu[curr]->cpu_softirq,
				st_cpu[curr]->cpu_guest,
				st_cpu[curr]->cpu_guest_nice);
		}
#endif

		/* Display CPU utilization */
		write_cpu_stat(curr, itv);
	}

	if (cpu_nr > 1) {
		/* On SMP machines, reduce itv to one processor (see note above) */
		itv = get_interval(uptime0[!curr], uptime0[curr]);
	}

	if (DISPLAY_DISK(flags)) {
		struct io_stats *ioi, *ioj;

		shi = st_hdr_iodev;

		/* Display disk stats header */
		write_disk_stat_header(&fctr);

		for (i = 0; i < iodev_nr; i++, shi++) {
			if (shi->used) {

				if (dlist_idx && !HAS_SYSFS(flags)) {
					/*
					 * With /proc/diskstats, stats for every device
					 * are read even if we have entered a list on devices
					 * on the command line. Thus we need to check
					 * if stats for current device are to be displayed.
					 */
					for (dev = 0; dev < dlist_idx; dev++) {
						st_dev_list_i = st_dev_list + dev;
						if (!strcmp(shi->name, st_dev_list_i->dev_name))
							break;
					}
					if (dev == dlist_idx)
						/* Device not found in list: Don't display it */
						continue;
				}

				ioi = st_iodev[curr] + i;
				ioj = st_iodev[!curr] + i;

				if (!DISPLAY_UNFILTERED(flags)) {
					if (!ioi->rd_ios && !ioi->wr_ios)
						continue;
				}

				if (DISPLAY_ZERO_OMIT(flags)) {
					if ((ioi->rd_ios == ioj->rd_ios) &&
						(ioi->wr_ios == ioj->wr_ios))
						/* No activity: Ignore it */
						continue;
				}

				if (DISPLAY_GROUP_TOTAL_ONLY(flags)) {
					if (shi->status != DISK_GROUP)
						continue;
				}
#ifdef DEBUG
				if (DISPLAY_DEBUG(flags)) {
					/* Debug output */
					fprintf(stderr, "name=%s itv=%llu fctr=%d ioi{ rd_sectors=%lu "
							"wr_sectors=%lu rd_ios=%lu rd_merges=%lu rd_ticks=%u "
							"wr_ios=%lu wr_merges=%lu wr_ticks=%u ios_pgr=%u tot_ticks=%u "
							"rq_ticks=%u }\n",
						shi->name,
						itv,
						fctr,
						ioi->rd_sectors,
						ioi->wr_sectors,
						ioi->rd_ios,
						ioi->rd_merges,
						ioi->rd_ticks,
						ioi->wr_ios,
						ioi->wr_merges,
						ioi->wr_ticks,
						ioi->ios_pgr,
						ioi->tot_ticks,
						ioi->rq_ticks
						);
				}
#endif

				if (DISPLAY_EXTENDED(flags)) {
					write_ext_stat(curr, itv, fctr, shi, ioi, ioj);
				}
				else {
					write_basic_stat(curr, itv, fctr, shi, ioi, ioj);
				}
			}
		}
		printf("\n");
	}
}
コード例 #11
0
ファイル: collector.cpp プロジェクト: brennane/gridpot
int collector::init(OBJECT *parent)
{
	// check the connection
	if ( get_connection()!=NULL )
		db = (database*)(get_connection()+1);
	if ( db==NULL )
		exception("no database connection available or specified");
	if ( !db->isa("database") )
		exception("connection is not a mysql database");
	gl_verbose("connection to mysql server '%s', schema '%s' ok", db->get_hostname(), db->get_schema());

	// check mode
	if ( strlen(mode)>0 )
	{
		options = 0xffffffff;
		struct {
			char *str;
			set bits;
		} modes[] = {
			{"r",	0xffff},
			{"r+",	0xffff},
			{"w",	MO_DROPTABLES},
			{"w+",	MO_DROPTABLES},
			{"a",	0x0000},
			{"a+",	0x0000},
		};
		int n;
		for ( n=0 ; n<sizeof(modes)/sizeof(modes[0]) ; n++ )
		{
			if ( strcmp(mode,modes[n].str)==0 )
			{
				options = modes[n].bits;
				break;
			}
		}
		if ( options==0xffffffff )
			exception("mode '%s' is not recognized",(const char*)mode);
		else if ( options==0xffff )
			exception("mode '%s' is not valid for a recorder", (const char*)mode);
	}

	// verify group is defined
	if ( strcmp(get_group(),"")==0 )
		exception("group must be specified");

	// verify property is defined
	if ( strcmp(get_property(),"")==0 )
		exception("at least one property aggregation must be specified");

	// copy property spec into working buffer
	char1024 propspecs;
	strcpy(propspecs,get_property());

	// count properties in specs
	char *p = propspecs;
	n_aggregates = 0;
	do {
		n_aggregates++;
		p = strchr(p,',');
	} while (p++!=NULL);
	list = new gld_aggregate[n_aggregates];
	names = new char*[n_aggregates];

	// load property structs
	int n;
	for ( p=propspecs,n=0 ; n<n_aggregates ; n++ )
	{
		char *np = strchr(p,',');
		if ( np!=NULL ) *np='\0';
		while ( *p!='\0' && isspace(*p) ) p++; // left trim
		int len = strlen(p);
		while ( len>0 && isspace(p[len-1]) ) p[--len]='\0'; // right trim
		if ( !list[n].set_aggregate(p,get_group()) )
			exception("unable to aggregate '%s' over group '%s'", p, get_group());
		gl_debug("%s: group '%s' aggregate '%s' initial value is '%lf'", get_name(), get_group(), p, list[n].get_value());
		names[n] = new char[strlen(p)+1];
		strcpy(names[n],p);
		p = np+1;
	}
	gl_debug("%s: %d aggregates ok", get_name(), n_aggregates);

	// drop table if exists and drop specified
	if ( db->table_exists(get_table()) )
	{
		if ( get_options()&MO_DROPTABLES && !db->query("DROP TABLE IF EXISTS `%s`", get_table()) )
			exception("unable to drop table '%s'", get_table());
	}
	
	// create table if not exists
	if ( !db->table_exists(get_table()) )
	{
		if ( !(options&MO_NOCREATE) )
		{
			char buffer[4096];
			size_t eos = sprintf(buffer,"CREATE TABLE IF NOT EXISTS `%s` ("
				"id INT AUTO_INCREMENT PRIMARY KEY, "
				"t TIMESTAMP, ", get_table());
			int n;
			for ( n=0 ; n<n_aggregates ; n++ )
				eos += sprintf(buffer+eos,"`%s` double, ",names[n]);
			eos += sprintf(buffer+eos,"%s","INDEX i_t (t))");

			if ( !db->query(buffer) )
				exception("unable to create table '%s' in schema '%s'", get_table(), db->get_schema());
			else
				gl_verbose("table %s created ok", get_table());
		}
		else
			exception("NOCREATE option prevents creation of table '%s'", get_table());
	}

	// check row count
	else 
	{
		if ( db->select("SELECT count(*) FROM `%s`", get_table())==NULL )
			exception("unable to get row count of table '%s'", get_table());

		gl_verbose("table '%s' ok", get_table());
	}
	
	// first event time
	TIMESTAMP dt = (TIMESTAMP)get_interval();
	if ( dt>0 )
		next_t = (TIMESTAMP)(gl_globalclock/dt+1)*dt;
	else if ( dt==0 )
		next_t = TS_NEVER;
	else
		exception("%s: interval must be zero or positive");
		
	// @todo use prepared statement instead of insert

	// set heartbeat
	if ( interval>0 )
		set_heartbeat((TIMESTAMP)interval);

	return 1;
}
コード例 #12
0
ファイル: cifsiostat.c プロジェクト: gavinlin/sysstat-android
/*
 ***************************************************************************
 * Print everything now (stats and uptime).
 *
 * IN:
 * @curr	Index in array for current sample statistics.
 * @rectime	Current date and time.
 ***************************************************************************
 */
void write_stats(int curr, struct tm *rectime)
{
	int i, fctr = 1;
	unsigned long long itv;
	struct io_hdr_stats *shi;
	struct cifs_stats *ioni, *ionj;

	/* Test stdout */
	TEST_STDOUT(STDOUT_FILENO);

	/* Print time stamp */
	if (DISPLAY_TIMESTAMP(flags)) {
		if (DISPLAY_ISO(flags)) {
			strftime(timestamp, sizeof(timestamp), "%FT%T%z", rectime);
		}
		else {
			strftime(timestamp, sizeof(timestamp), "%x %X", rectime);
		}
		printf("%s\n", timestamp);
#ifdef DEBUG
		if (DISPLAY_DEBUG(flags)) {
			fprintf(stderr, "%s\n", timestamp);
		}
#endif
	}

	/* Interval is multiplied by the number of processors */
	itv = get_interval(uptime[!curr], uptime[curr]);

	if (cpu_nr > 1) {
		/* On SMP machines, reduce itv to one processor (see note above) */
		itv = get_interval(uptime0[!curr], uptime0[curr]);
	}

	shi = st_hdr_cifs;

	/* Display CIFS stats header */
	write_cifs_stat_header(&fctr);

	for (i = 0; i < cifs_nr; i++, shi++) {
		if (shi->used) {
			ioni = st_cifs[curr]  + i;
			ionj = st_cifs[!curr] + i;
#ifdef DEBUG
			if (DISPLAY_DEBUG(flags)) {
				/* Debug output */
				fprintf(stderr, "name=%s itv=%llu fctr=%d ioni{ rd_bytes=%llu "
						"wr_bytes=%llu rd_ops=%llu wr_ops=%llu fopens=%llu "
						"fcloses=%llu fdeletes=%llu}\n",
					shi->name, itv, fctr,
					ioni->rd_bytes, ioni->wr_bytes,
					ioni->rd_ops,   ioni->wr_ops,
					ioni->fopens,   ioni->fcloses,
					ioni->fdeletes);
			}
#endif
			write_cifs_stat(curr, itv, fctr, shi, ioni, ionj);
		}
	}
	printf("\n");
}
コード例 #13
0
ファイル: opt_confirms.c プロジェクト: qznc/libfirm
/**
 * Return the value of a Cmp if one or both predecessors
 * are Confirm nodes.
 *
 * @param cmp      the Cmp node
 * @param left     the left operand of the Cmp
 * @param right    the right operand of the Cmp
 * @param relation the compare relation
 */
ir_tarval *computed_value_Cmp_Confirm(const ir_node *cmp, ir_node *left, ir_node *right, ir_relation relation)
{
	ir_node    *l_bound;
	ir_relation l_relation, res_relation, neg_relation;
	interval_t  l_iv, r_iv;
	ir_tarval  *tv;

	if (is_Confirm(right)) {
		/* we want the Confirm on the left side */
		ir_node *t = right;
		right = left;
		left  = t;

		relation = get_inversed_relation(relation);
	} else if (! is_Confirm(left)) {
		/* nothing more found */
		tv = tarval_bad;
		goto check_null_case;
	}

	/* ok, here at least left is a Confirm, right might be */
	l_bound    = get_Confirm_bound(left);
	l_relation = get_Confirm_relation(left);

	if (is_Confirm(right)) {
		/*
		 * both sides are Confirm's. Check some rare cases first.
		 */
		ir_node    *r_bound    = get_Confirm_bound(right);
		ir_relation r_relation = get_Confirm_relation(right);

		/*
		 * some check can be made WITHOUT constant bounds
		 */
		if (r_bound == l_bound) {
			if (is_transitive(l_relation)) {
				ir_relation r_inc_relation = get_inversed_relation(r_relation);

				/*
				 * triangle inequality:
				 *
				 * a CMP B && B CMP b => a CMP b, !(a ~CMP b)
				 *
				 * We handle correctly cases with some <=/>= here
				 */
				if ((l_relation & ~ir_relation_equal) == (r_inc_relation & ~ir_relation_equal)) {
					res_relation = (l_relation & ~ir_relation_equal) | (l_relation & r_inc_relation & ir_relation_equal);

					if ((relation == res_relation) || ((relation & ~ir_relation_equal) == res_relation)) {
						DBG_OUT_TR(l_relation, l_bound, r_relation, r_bound, relation, "true");
						DBG_EVAL_CONFIRM(cmp);
						return tarval_b_true;
					} else {
						ir_relation neg_relation = get_negated_relation(relation);

						if ((neg_relation == res_relation) || ((neg_relation & ~ir_relation_equal) == res_relation)) {
							DBG_OUT_TR(l_relation, l_bound, r_relation, r_bound, relation, "false");
							DBG_EVAL_CONFIRM(cmp);
							return tarval_b_false;
						}
					}
				}
			}
		}

		/*
		 * Here, we check only the right Confirm, as the left Confirms are
		 * checked later anyway.
		 */
		if (left == r_bound) {
			/*
			 * l == bound(r) AND relation(r) == relation:
			 *
			 * We know that a CMP b and check for that
			 */
			if ((r_relation == relation) || (r_relation == (relation & ~ir_relation_equal))) {
				DBG_OUT_R(r_relation, r_bound, left, relation, right, "true");
				DBG_EVAL_CONFIRM(cmp);
				return tarval_b_true;
			}
			/*
			 * l == bound(r) AND relation(r) != relation:
			 *
			 * We know that a CMP b and check for a ~CMP b
			 */
			else {
				neg_relation = get_negated_relation(relation);

				if ((r_relation == neg_relation) || (r_relation == (neg_relation & ~ir_relation_equal))) {
					DBG_OUT_R(r_relation, r_bound, left, relation, right, "false");
					DBG_EVAL_CONFIRM(cmp);
					return tarval_b_false;
				}
			}
		}

		/* now, try interval magic */
		tv = compare_iv(
			get_interval(&l_iv, l_bound, l_relation),
			get_interval(&r_iv, r_bound, r_relation),
			relation);

		if (tv != tarval_bad) {
			DBG_EVAL_CONFIRM(cmp);
			return tv;
		}
	}

	/* from Here, check only left Confirm */

	/*
	 * some checks can be made WITHOUT constant bounds
	 */
	if (right == l_bound) {
		/*
		 * r == bound(l) AND relation(l) == relation:
		 *
		 * We know that a CMP b and check for that
		 */
		if ((l_relation == relation) || (l_relation == (relation & ~ir_relation_equal))) {
			DBG_OUT_L(l_relation, l_bound, left, relation, right, "true");
			DBG_EVAL_CONFIRM(cmp);
			return tarval_b_true;
		}
		/*
		 * r == bound(l) AND relation(l) is Not(relation):
		 *
		 * We know that a CMP b and check for a ~CMP b
		 */
		else {
			neg_relation = get_negated_relation(relation);

			if ((l_relation == neg_relation) || (l_relation == (neg_relation & ~ir_relation_equal))) {
				DBG_OUT_L(l_relation, l_bound, left, relation, right, "false");
				DBG_EVAL_CONFIRM(cmp);
				return tarval_b_false;
			}
		}
	}

	/* now, only right == Const can help */
	tv = value_of(right);

	if (tv != tarval_bad) {
		tv = compare_iv(
			get_interval(&l_iv, l_bound, l_relation),
			get_interval_from_tv(&r_iv, tv),
			relation);
	} else {
check_null_case:
		/* check some other cases */
		if ((relation == ir_relation_equal || relation == ir_relation_less_greater) &&
			is_Const(right) && is_Const_null(right)) {
			/* for == 0 or != 0 we have some special tools */
			ir_mode       *mode = get_irn_mode(left);
			const ir_node *dummy;
			if (mode_is_reference(mode)) {
				if (value_not_null(left, &dummy)) {
					tv = relation == ir_relation_equal ? tarval_b_false : tarval_b_true;
				}
			} else {
				if (value_not_zero(left, &dummy)) {
					tv = relation == ir_relation_equal ? tarval_b_false : tarval_b_true;
				}
			}
		}
	}

	if (tv != tarval_bad)
		DBG_EVAL_CONFIRM(cmp);

	return tv;
}
コード例 #14
0
ファイル: sysmon.c プロジェクト: RPI-WCL/sysmon
int main(int argc, char* argv[])
{
    struct stats st, st_prev;
    struct ext_stats ext_st;
    unsigned long long interval;
    char *logfile = LOG_FILE;
    int speed = -1, duplex = -1;
    

    /* Usage: ./sysmon [real-time logging switch] [log filename] [print flag] (netif speed) (netif duplex)
       netif duplex takes C_DUPLEX_HALF=1 or C_DUPLEX_FULL=2 */
    
    if (2 <= argc)      realtime_logging = (strcmp("1", argv[1]) == 0);
    if (3 <= argc)      logfile = argv[2];
    if (4 <= argc && (strncmp("0x", argv[3], 2) == 0))
        print_flag = (int)strtol(argv[3], NULL, 0); /* Expecting 0x... */
    if (5 <= argc)      speed = atoi(argv[4]);
    if (6 <= argc)      duplex = atoi(argv[5]);

    printf ("realtime logging : %s\n", realtime_logging ? "enabled" : "disabled");
    printf ("log file         : %s\n", logfile);
    printf ("print flag       : 0x%08x\n", print_flag);
    printf ("speed            : %d\n", speed);
    printf ("duplex           : %d\n", duplex);

    #ifndef DEBUG
    if ((fp = fopen(logfile, "w+")) == NULL) {
        fprintf(stderr, "opening logfile failed\n");
        exit(EXIT_FAILURE);
    }
    #else
    fp = stdout;
    #endif


    /* Initialization */
    signal(SIGINT, signal_callback_handler); /* Set up a signal handler */
    read_stats(&base_stats);
    clock_gettime(CLOCK_MONOTONIC, &base_time);
    /* Obtain speed/duplex info for eth0 */
    read_net_dev(&st.net, 1);
    read_if_info(&st.net, 1); 
    /* VMs on Google Clouds do not let you read files under /sys/class/net/eth0/
       See also: http://unix.stackexchange.com/questions/77750/checking-the-speed-of-active-network-connections */
    base_stats.net.speed = (0 < speed) ? speed : st.net.speed;
    base_stats.net.duplex = (0 < duplex) ? duplex : st.net.duplex;
    st = st_prev = base_stats;
    /* Initialize variables for min/max/mean/var computation */
    num_samples = 1;
    set_max_ext_stats(&min);
    memset((void *)&max, 0x00, sizeof(struct ext_stats));
    memset((void *)&mean, 0x00, sizeof(struct ext_stats));
    memset((void *)&var, 0x00, sizeof(struct ext_stats));
    /* For real-time logging */
    if (realtime_logging) fprint_header(fp, print_flag);
    /* Get HZ */
    get_HZ();

    while (1) { /* Anyways, we record stats for average computation */
        usleep(INTERVAL_SEC * SEC_TO_MSEC);
        read_stats(&st);
        interval = get_interval(st_prev.uptime, st.uptime);

        /* Compute extended stats from raw stats */
        compute_ext_stats(interval, &st, &st_prev, &ext_st);
        update_ext_stats(num_samples, &ext_st, &min, &max, &mean, &var);
        if (realtime_logging) fprint_stats(fp, print_flag, &st, &ext_st);
        
        /* Update stats (min/max/mean/var) for ext_stats */
        st_prev = st;
        num_samples++;
    }

    /* Program never gets here */
    printf("Waiting for the SIGINT signal\n");
    pause();

    return EXIT_SUCCESS;
}
コード例 #15
0
ファイル: stub.c プロジェクト: kathydxue/AlgorithmCollection
/*
 * master_thread
 */
static void master_thread(void)
{
    unsigned int i;

    /* wait for all threads end */
    pthread_mutex_lock(&end_mtx);
    while (system_variables.thread_num != end_thread_num)
	pthread_cond_wait(&end_cond, &end_mtx);
    pthread_mutex_unlock(&end_mtx);

    //    show_list(list);
    free_list(list);

    /* display result */
    double tmp_itvl;
    double min_itvl = 0x7fffffff;
    double ave_itvl = 0.0;
    double max_itvl = 0.0;
    long double itvl = 0.0;

    unsigned long long int total = 0;
    long long int count1, count2;

    gettimeofday(&stat_data_end, NULL);

    total = 0;
    for (i = 0; i < system_variables.thread_num; i++) {
      total += sum[i];

      tmp_itvl = get_interval(stat_data[i].begin, stat_data[i].end);
      
      itvl += tmp_itvl;
      if (max_itvl < tmp_itvl)
	max_itvl = tmp_itvl;
      if (tmp_itvl < min_itvl)
	min_itvl = tmp_itvl;
      if (0 < system_variables.verbose)
	fprintf(stderr, "thread(%d) end %f[sec]\n", i, tmp_itvl);
    }
    /*
    if (total != (((system_variables.item_num * system_variables.thread_num) *
		 ((system_variables.item_num * system_variables.thread_num) + 1)) / 2))
    */
    if (((system_variables.item_num * system_variables.thread_num) % 2) == 0) {
      count1 = (system_variables.item_num * system_variables.thread_num) / 2;
      count2 = (system_variables.item_num * system_variables.thread_num + 1);
    }
    else {
      count1 = (system_variables.item_num * system_variables.thread_num + 1) / 2;
      count2 = (system_variables.item_num * system_variables.thread_num);
    }
    if (total != (count1 * count2))
      fprintf (stderr, "RESULT: test FAILED!\n");
    else
      fprintf (stderr, "RESULT: test OK\n");

    fprintf (stderr, "condition =>\n");
    printf ("\t%d threads run\n", system_variables.thread_num);
    printf ("\t%d items inserted and deleted / thread, total %d items\n",
	    system_variables.item_num,
	    system_variables.item_num * system_variables.thread_num);

    assert(0 < system_variables.thread_num);
    ave_itvl = (double) (itvl / system_variables.thread_num);

    tmp_itvl = get_interval(stat_data_begin, stat_data_end);

    fprintf(stderr, "performance =>\n\tinterval =  %f [sec]\n", tmp_itvl);

    fprintf
      (stderr, "\tthread info:\n\t  ave. = %f[sec], min = %f[sec], max = %f[sec]\n",
       ave_itvl, min_itvl, max_itvl);
}