Esempio n. 1
0
	/*
	 * Prints the probe with the specified name. There
	 * are certain conditions that this method wont print
	 * anything:
	 *
	 * 1) No such probe exists.
	 * 2) The probe has not been closed.
	 */
	void printProbe(string s)
	{
		TimeProbe* tp;

		if (probes[s] == 0)
			return;
		tp = probes[s];

		if (tp->getStatus() != TimeProbe::CLOSED)
			return;

		timeval* t1 = tp->getStart();
		timeval* t2 = tp->getEnd();

		if (t1->tv_usec > t2->tv_usec)
		{
			t2->tv_usec += 1000000;
			t2->tv_sec--;
		}

		timeval lapsed;
		lapsed.tv_usec = t2->tv_usec - t1->tv_usec;
		lapsed.tv_sec = (int) (t2->tv_sec - t1->tv_sec);
		cout << s << ": ";
		printf("Time elapsed: %d.%06dsec\n", (int) lapsed.tv_sec,(int) lapsed.tv_usec);

	}
Esempio n. 2
0
	/**
	 * Open the probe with the specified name and measures
	 * the time value at that point in the program's path
	 * of execution.
	 *
	 * If a probe for that name already exists, this method
	 * does nothing.
	 */
	void openProbe(string s)
	{
		TimeProbe* tp;

		if (probes[s] == 0)
		{
			tp = new TimeProbe();
			probes[s] = tp;
		}
		else
		{
			tp = probes[s];
		}
		if (tp->getStatus() != TimeProbe::INACTIVE)
			return;

		tp->setStatus(TimeProbe::OPEN);

		timeval* tv = new timeval();
		struct timezone tz;

		gettimeofday(tv, &tz);
		tp->setStart(tv);

	}
Esempio n. 3
0
	/**
	 * Closes the probe for the given name. If the probe
	 * is not open or if the probe is already closed this
	 * method does nothing.
	 */
	void closeProbe(string s)
	{

		TimeProbe* tp;
		if (probes[s] == 0)
			return;

		tp = probes[s];

		if (tp->getStatus() != TimeProbe::OPEN)
			return;

		timeval* tv = new timeval();
		struct timezone tz;
		gettimeofday(tv, NULL);
		tp->setEnd(tv);

		tp->setStatus(TimeProbe::CLOSED);

	}