void KMod::setupCounter(Counter &counter) {
	char base[128];
	char text[128];
	snprintf(base, sizeof(base), "/dev/gator/events/%s", counter.getType());

	snprintf(text, sizeof(text), "%s/enabled", base);
	int enabled = true;
	if (Collector::writeReadDriver(text, &enabled) || !enabled) {
		counter.setEnabled(false);
		return;
	}

	snprintf(text, sizeof(text), "%s/key", base);
	int key = 0;
	Collector::readIntDriver(text, &key);
	counter.setKey(key);

	snprintf(text, sizeof(text), "%s/event", base);
	Collector::writeDriver(text, counter.getEvent());
	snprintf(text, sizeof(text), "%s/count", base);
	if (access(text, F_OK) == 0) {
		int count = counter.getCount();
		if (Collector::writeReadDriver(text, &count) && counter.getCount() > 0) {
			logg->logError(__FILE__, __LINE__, "Cannot enable EBS for %s:%i with a count of %d\n", counter.getType(), counter.getEvent(), counter.getCount());
			handleException();
		}
		counter.setCount(count);
	} else if (counter.getCount() > 0) {
		logg->logError(__FILE__, __LINE__, "Event Based Sampling is only supported with kernel versions 3.0.0 and higher with CONFIG_PERF_EVENTS=y, and CONFIG_HW_PERF_EVENTS=y\n");
		handleException();
	}
}
Exemple #2
0
TEST(StatsTest, CounterSimpleTest) {
  Counter c;
  c.record(-7);
  EXPECT_EQ(1, c.getCount());
  EXPECT_EQ(-7, c.getMin());
  EXPECT_EQ(-7, c.getMax());
  EXPECT_EQ(-7.0, c.getAverage());
  c.record(-9);
  EXPECT_EQ(2, c.getCount());
  EXPECT_EQ(-9, c.getMin());
  EXPECT_EQ(-7, c.getMax());
  EXPECT_EQ(-8.0, c.getAverage());
  ostringstream oss;
  c.print(oss);
  EXPECT_EQ(oss.str(), "2,-8,-9,-7,1");
}
Exemple #3
0
TEST(StatsTest, CounterNoData) {
  Counter c;
  EXPECT_EQ(0, c.getCount());
  EXPECT_TRUE(std::isnan(c.getAverage()));
  ostringstream oss;
  c.print(oss);
  std::string res = oss.str();
  EXPECT_EQ(res, "0,nan,0,0,0");
}
Exemple #4
0
	void force_unique() { 
		if (counter->getCount() > 1) { 
			counter->decrement();  
			counter = new Counter();
			counter->increment(); 
			Core *new_core = new Core(*(this->core)); 
			this->core = new_core;
		}
	}
Exemple #5
0
	void force_unique() { 
		if (counter->getCount() > 1) {
			char * temp = data; 
			data = new char[len + 1];
			strcpy(data, temp);
			counter->decrement(); 
			counter = new Counter(); 
			counter->increment();
		}
	}
Exemple #6
0
int main()
{
	Counter counter;
	for(int i=0; i<10; i++)
		counter.hit();
	sleep(2);
	for(int i=0; i<5; i++)
		counter.hit();
	sleep(3);
	cout<<counter.getCount()<<endl;
	for(int i=0; i<10; i++)
		counter.hit();
	sleep(6);
	cout<<counter.getCount()<<endl;
	sleep(3);
	cout<<counter.getCount()<<endl;
	
	return 0;
}
Exemple #7
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MSG oMsg;

	float timeNow, timeLast;

	Counter	 *frameCounter = new Counter();
	Graphics *engine = new Graphics();

	engine->init(hInstance, nCmdShow, 1024, 768);
	frameCounter->start();

	timeNow = frameCounter->getCount();
	timeLast = timeNow;

	PeekMessage( &oMsg, NULL, 0, 0, PM_NOREMOVE );
	while ( oMsg.message != WM_QUIT )
	{
		if (PeekMessage( &oMsg, NULL, 0, 0, PM_REMOVE )) 
		{
			TranslateMessage( &oMsg );
			DispatchMessage( &oMsg );
		}
		else
		{
			timeNow = frameCounter->getCount();
			float timeElapsed = (timeNow - timeLast);
			if (frameCounter->isValidFPS(30.0))
			{
				timeLast = timeNow;
				engine->run(timeElapsed);
			}
		}
	}

    delete engine;
	delete frameCounter;
	//Release D3D objects
	return (int) oMsg.wParam;
}
Exemple #8
0
void KMod::setupCounter(Counter &counter) {
	char base[128];
	char text[128];
	snprintf(base, sizeof(base), "/dev/gator/events/%s", counter.getType());

	snprintf(text, sizeof(text), "%s/enabled", base);
	int enabled = true;
	if (DriverSource::writeReadDriver(text, &enabled) || !enabled) {
		counter.setEnabled(false);
		return;
	}

	int value = 0;
	snprintf(text, sizeof(text), "%s/key", base);
	DriverSource::readIntDriver(text, &value);
	counter.setKey(value);

	snprintf(text, sizeof(text), "%s/cores", base);
	if (DriverSource::readIntDriver(text, &value) == 0) {
		counter.setCores(value);
	}

	snprintf(text, sizeof(text), "%s/event", base);
	DriverSource::writeDriver(text, counter.getEvent());
	snprintf(text, sizeof(text), "%s/count", base);
	if (access(text, F_OK) == 0) {
		int count = counter.getCount();
		if (DriverSource::writeReadDriver(text, &count) && counter.getCount() > 0) {
			logg->logError(__FILE__, __LINE__, "Cannot enable EBS for %s:%i with a count of %d\n", counter.getType(), counter.getEvent(), counter.getCount());
			handleException();
		}
		counter.setCount(count);
	} else if (counter.getCount() > 0) {
		ConfigurationXML::remove();
		logg->logError(__FILE__, __LINE__, "Event Based Sampling is only supported with kernel versions 3.0.0 and higher with CONFIG_PERF_EVENTS=y, and CONFIG_HW_PERF_EVENTS=y. The invalid configuration.xml has been removed.\n");
		handleException();
	}
}
Exemple #9
0
void PerfDriver::setupCounter(Counter &counter) {
	PerfCounter *const perfCounter = findCounter(counter);
	if (perfCounter == NULL) {
		counter.setEnabled(false);
		return;
	}

	// Don't use the config from counters XML if it's not set, ex: software counters
	if (counter.getEvent() != -1) {
		perfCounter->setConfig(counter.getEvent());
	}
	perfCounter->setCount(counter.getCount());
	perfCounter->setEnabled(true);
	counter.setKey(perfCounter->getKey());
}
int main(int argc, char const *argv[]) {
  Counter count1(10);
  Counter count2(12);
  Counter megaCount = count1 + count2;
  cout << "count1: " << count1.getCount() <<\
   "\ncount2: " << count2.getCount() <<\
   "\nmegaCount: " << megaCount.getCount() << endl;
  if ((++count1).getCount() > 10) {
    cout << "count1 is greater than 10!" << endl;
  }

  if ((count2++).getCount() == 12) {
    cout << "Check out what count2 is: " << count2.getCount() << endl;
  }
  return 0;
}
Exemple #11
0
void task1(void *pvParameters)
{
    Counter local_counter = Counter(12);
    Counter *new_counter = new Counter(24);
    while(1) {
        Counter *counter = NULL;
        switch(rand() % 3) {
        case 0:
            counter = &local_counter;
            break;
        case 1:
            counter = &static_counter;
            break;
        default:
            counter = new_counter;
            break;
        }
        counter->Increment();
        printf("local counter %d static counter %d newly allocated counter %d\r\n", local_counter.getCount(),
               static_counter.getCount(), new_counter->getCount());
        vTaskDelay(100);
    }
}
Counter Counter::operator+(Counter rhs) {
  Counter newCount(this -> getCount() + rhs.getCount());
  return newCount;
}
 int getCount() {return counter.getCount();}