示例#1
0
Statistics::Statistics() : counters(), eventsEnabled(false) {
	frameNumberCounter = addCounter("frame number", "1");
	frameDurationCounter = addCounter("frame duration", "ms");
	vboCounter = addCounter("VBOs rendered", "1");
	trianglesCounter = addCounter("triangles rendered", "1");
	linesCounter = addCounter("lines rendered", "1");
	pointsCounter = addCounter("points rendered", "1");
	nodeCounter = addCounter("geometry nodes rendered", "1");

	ioRateReadCounter = addCounter("I/O rate read", "MiB/s");
	ioRateWriteCounter = addCounter("I/O rate write", "MiB/s");
}
示例#2
0
/**
 * add one IB port to the list of available ports and add the
 * counters related to this port to the global counter list
 */
static void
addIBPort( const char *ca_name, umad_port_t * port )
{
	ib_port *nwif, *last;
	char counter_name[512];

	nwif = ( ib_port * ) malloc( sizeof ( ib_port ) );

	if ( nwif == NULL ) {
		fprintf( stderr, "can not allocate memory for IB port description\n" );
		exit( 1 );
	}

	sprintf( counter_name, "%s_%d", ca_name, port->portnum );
	nwif->name = strdup( counter_name );

	sprintf( counter_name, "%s_%d_recv", ca_name, port->portnum );
	nwif->recv_cntr =
		addCounter( counter_name, "bytes received on this IB port", "bytes" );

	sprintf( counter_name, "%s_%d_send", ca_name, port->portnum );
	nwif->send_cntr =
		addCounter( counter_name, "bytes written to this IB port", "bytes" );

	nwif->port_rate = port->rate;
	nwif->is_initialized = 0;
	nwif->port_number = port->portnum;
	nwif->next = NULL;

	num_counters += 2;

	if ( root_ib_port == NULL ) {
		root_ib_port = nwif;
	} else {
		last = root_ib_port;
		while ( last->next != NULL )
			last = last->next;
		last->next = nwif;
	}
}
示例#3
0
StatusWith<std::vector<PerfCounterCollector::CounterInfo>> PerfCounterCollector::addCounters(
    StringData path) {
    std::wstring pathWide = toNativeString(path.toString().c_str());
    DWORD pathListLength = 0;
    PDH_STATUS status = PdhExpandCounterPathW(pathWide.c_str(), nullptr, &pathListLength);

    if (status != PDH_MORE_DATA) {
        return {ErrorCodes::WindowsPdhError,
                str::stream() << formatFunctionCallError("PdhExpandCounterPathW", status)
                              << " for counter '"
                              << path
                              << "'"};
    }

    auto buf = stdx::make_unique<wchar_t[]>(pathListLength);

    status = PdhExpandCounterPathW(pathWide.c_str(), buf.get(), &pathListLength);

    if (status != ERROR_SUCCESS) {
        return {ErrorCodes::WindowsPdhError,
                formatFunctionCallError("PdhExpandCounterPathW", status)};
    }

    std::vector<CounterInfo> counters;

    // Windows' PdhExpandWildCardPathW returns a nullptr terminated array of nullptr separated
    // strings.
    std::vector<std::string> counterNames;

    const wchar_t* ptr = buf.get();
    while (ptr && *ptr) {
        counterNames.emplace_back(toUtf8String(ptr));
        ptr += wcslen(ptr) + 1;
    }

    // Sort to ensure we have a predictable ordering in the final BSON
    std::sort(counterNames.begin(), counterNames.end());

    for (const auto& name : counterNames) {

        auto swCounterInfo = addCounter(name);
        if (!swCounterInfo.isOK()) {
            return swCounterInfo.getStatus();
        }

        counters.emplace_back(std::move(swCounterInfo.getValue()));
    }

    return {std::move(counters)};
}
示例#4
0
/**
 * If we are going to collect counters every second while we work out whether
 * we've got 64bit or not, lets just make the counter query once and reuse it.
 */
static PDH_STATUS createCounterQuery()
{
	PDH_STATUS status= PdhOpenQuery(NULL, 0, &query);
	if (status == ERROR_SUCCESS) {
		addCounter(NIO_COUNTER_BYTES_IN, &bytesIn);
		addCounter(NIO_COUNTER_PACKETS_IN, &pktsIn);
		addCounter(NIO_COUNTER_ERRORS_IN, &errorsIn);
		addCounter(NIO_COUNTER_DISCARDS_IN, &discardsIn);
		addCounter(NIO_COUNTER_BYTES_OUT, &bytesOut);
		addCounter(NIO_COUNTER_PACKETS_OUT, &pktsOut);
		addCounter(NIO_COUNTER_ERRORS_OUT, &errorsOut);
		addCounter(NIO_COUNTER_DISCARDS_OUT, &discardsOut);
		return ERROR_SUCCESS;
	} else {
		return status;
	}
}
示例#5
0
文件: Counters.cpp 项目: Esplin/wagic
int Counters::addCounter(int _power, int _toughness)
{
    return addCounter("", _power, _toughness);
}
示例#6
0
void Server_Player::setupZones()
{
	// This may need to be customized according to the game rules.
	// ------------------------------------------------------------------

	// Create zones
	Server_CardZone *deckZone = new Server_CardZone(this, "deck", false, HiddenZone);
	addZone(deckZone);
	Server_CardZone *sbZone = new Server_CardZone(this, "sb", false, HiddenZone);
	addZone(sbZone);
	addZone(new Server_CardZone(this, "table", true, PublicZone));
	addZone(new Server_CardZone(this, "hand", false, PrivateZone));
	addZone(new Server_CardZone(this, "stack", false, PublicZone));
	addZone(new Server_CardZone(this, "grave", false, PublicZone));
	addZone(new Server_CardZone(this, "rfg", false, PublicZone));

	addCounter(new Server_Counter(0, "life", Color(255, 255, 255), 25, 20));
	addCounter(new Server_Counter(1, "w", Color(255, 255, 150), 20, 0));
	addCounter(new Server_Counter(2, "u", Color(150, 150, 255), 20, 0));
	addCounter(new Server_Counter(3, "b", Color(150, 150, 150), 20, 0));
	addCounter(new Server_Counter(4, "r", Color(250, 150, 150), 20, 0));
	addCounter(new Server_Counter(5, "g", Color(150, 255, 150), 20, 0));
	addCounter(new Server_Counter(6, "x", Color(255, 255, 255), 20, 0));
	addCounter(new Server_Counter(7, "storm", Color(255, 255, 255), 20, 0));

	initialCards = 7;

	// ------------------------------------------------------------------

	// Assign card ids and create deck from decklist
	InnerDecklistNode *listRoot = deck->getRoot();
	nextCardId = 0;
	for (int i = 0; i < listRoot->size(); ++i) {
		InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
		Server_CardZone *z;
		if (currentZone->getName() == "main")
			z = deckZone;
		else if (currentZone->getName() == "side")
			z = sbZone;
		else
			continue;
		
		for (int j = 0; j < currentZone->size(); ++j) {
			DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
			if (!currentCard)
				continue;
			for (int k = 0; k < currentCard->getNumber(); ++k)
				z->cards.append(new Server_Card(currentCard->getName(), nextCardId++, 0, 0));
		}
	}
	
	const QList<MoveCardToZone *> &sideboardPlan = deck->getCurrentSideboardPlan();
	for (int i = 0; i < sideboardPlan.size(); ++i) {
		MoveCardToZone *m = sideboardPlan[i];
		
		Server_CardZone *start, *target;
		if (m->getStartZone() == "main")
			start = deckZone;
		else if (m->getStartZone() == "side")
			start = sbZone;
		else
			continue;
		if (m->getTargetZone() == "main")
			target = deckZone;
		else if (m->getTargetZone() == "side")
			target = sbZone;
		else
			continue;
		
		for (int j = 0; j < start->cards.size(); ++j)
			if (start->cards[j]->getName() == m->getCardName()) {
				Server_Card *card = start->cards[j];
				start->cards.removeAt(j);
				target->cards.append(card);
				break;
			}
	}
	
	deckZone->shuffle();
}
示例#7
0
/**
 * adds a Lustre fs to the fs list and creates the counters for it
 * @param name fs name
 * @param procpath_general path to the 'stats' file in /proc/fs/lustre/... for this fs
 * @param procpath_readahead path to the 'readahead' file in /proc/fs/lustre/... for this fs
 */
static int
addLustreFS( const char *name,
	     const char *procpath_general, 
	     const char *procpath_readahead )
{
	lustre_fs *fs, *last;
	char counter_name[512];
	FILE *fff;

	SUBDBG("Adding lustre fs\n");

	fs = malloc( sizeof ( lustre_fs ) );
	if ( fs == NULL ) {
	   SUBDBG("can not allocate memory for new Lustre FS description\n" );
	   return PAPI_ENOMEM;
	}

	fs->proc_file=strdup(procpath_general);
	fff = fopen( procpath_general, "r" );
	if ( fff == NULL ) {
	  SUBDBG("can not open '%s'\n", procpath_general );
	  free(fs);
	  return PAPI_ESYS;
	}
	fclose(fff);

	fs->proc_file_readahead = strdup(procpath_readahead);
	fff = fopen( procpath_readahead, "r" );
	if ( fff == NULL ) {
	  SUBDBG("can not open '%s'\n", procpath_readahead );
	  free(fs);
	  return PAPI_ESYS;
	}
	fclose(fff);

	sprintf( counter_name, "%s_llread", name );
	if (NULL == (fs->read_cntr = addCounter( counter_name, 
				    "bytes read on this lustre client", 
				    "bytes" ))) {
			free(fs);
			return PAPI_ENOMEM;
	}

	sprintf( counter_name, "%s_llwrite", name );
	if ( NULL == (fs->write_cntr = addCounter( counter_name, 
				     "bytes written on this lustre client",
				     "bytes" ))) {
			free(fs->read_cntr);
			free(fs);
			return PAPI_ENOMEM;
	}

	sprintf( counter_name, "%s_wrong_readahead", name );
	if ( NULL == (fs->readahead_cntr = addCounter( counter_name, 
					 "bytes read but discarded due to readahead",
					 "bytes" ))) {
			free(fs->read_cntr);
			free(fs->write_cntr);
			free(fs);
			return PAPI_ENOMEM;
	}

	fs->next = NULL;

	/* Insert into the linked list */
	/* Does this need locking? */
	if ( root_lustre_fs == NULL ) {
		root_lustre_fs = fs;
	} else {
		last = root_lustre_fs;

		while ( last->next != NULL )
			last = last->next;

		last->next = fs;
	}
	return PAPI_OK;
}
示例#8
0
int Counters::addCounter(int _power, int _toughness, bool _noevent)
{
    return addCounter("", _power, _toughness, _noevent);
}
示例#9
0
/**
 * Call back function called when it is time to sample the Hyper-V switch interface counters.
 * Uses the poller->userData to find the device name (ie switch port guid) which identifies
 * the counter instance for the switch port.
 */
void getCounters_interface(void *magic, SFLPoller *poller, SFL_COUNTERS_SAMPLE_TYPE *cs)
 {
	 HSP *sp = (HSP *)poller->magic;
    
    // device name was copied as userData
    char *deviceName = (char *)poller->userData;
	myLog(LOG_INFO, "getCounters_interface: dsClass=%u, dsIndex=%u, deviceName=%s", 
		  poller->dsi.ds_class, poller->dsi.ds_index, deviceName);

	if (deviceName) {
		//find the vadaptor for the deviceName
		SFLAdaptor *vAdaptor = adaptorListGet(sp->vAdaptorList, deviceName);
		if (vAdaptor != NULL) {
			myLog(LOG_INFO, "getCounters_interface: found adaptor index=%u", vAdaptor->ifIndex);
			wchar_t *instance = ((HVSVPortInfo *)vAdaptor->userData)->portCountersInstance;
			if (!instance) {
				myLog(LOG_INFO, "getCounters_interface: counters instance name not set for %s", deviceName);
				return;
			}
			//Get the counter data
			SFLCounters_sample_element elem = { 0 };
			elem.tag = SFLCOUNTERS_GENERIC;
			elem.counterBlock.generic.ifIndex = poller->dsi.ds_index;
			elem.counterBlock.generic.ifType = 6; // assume ethernet
			elem.counterBlock.generic.ifSpeed = vAdaptor->ifSpeed;
			elem.counterBlock.generic.ifDirection = vAdaptor->ifDirection;
			elem.counterBlock.generic.ifStatus = 3; // ifAdminStatus==up, ifOperstatus==up
			elem.counterBlock.generic.ifPromiscuousMode = vAdaptor->promiscuous;
			PDH_HQUERY query;
			if (PdhOpenQuery(NULL, 0, &query) == ERROR_SUCCESS) {
				PDH_HCOUNTER bytesIn, pktsIn, mcastsIn, bcastsIn, discardsIn;
				PDH_HCOUNTER bytesOut, pktsOut, mcastsOut, bcastsOut, discardsOut;
				if (addCounter(instance, IF_COUNTER_BYTES_IN, &query, &bytesIn) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_PACKETS_IN, &query, &pktsIn) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_MULTICASTS_IN, &query, &mcastsIn) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_BROADCASTS_IN, &query, &bcastsIn) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_DISCARDS_IN, &query, &discardsIn) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_BYTES_OUT, &query, &bytesOut) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_PACKETS_OUT, &query, &pktsOut) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_MULTICASTS_OUT, &query, &mcastsOut) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_BROADCASTS_OUT, &query, &bcastsOut) == ERROR_SUCCESS &&
					addCounter(instance, IF_COUNTER_DISCARDS_OUT, &query, &discardsOut) == ERROR_SUCCESS &&
					PdhCollectQueryData(query) == ERROR_SUCCESS) {
					elem.counterBlock.generic.ifInOctets = getRawCounterValue(&bytesIn);
					elem.counterBlock.generic.ifInUcastPkts = (uint32_t)getRawCounterValue(&pktsIn);
					elem.counterBlock.generic.ifInMulticastPkts = (uint32_t)getRawCounterValue(&mcastsIn);
					elem.counterBlock.generic.ifInBroadcastPkts = (uint32_t)getRawCounterValue(&bcastsIn);
					elem.counterBlock.generic.ifInDiscards = (uint32_t)getRawCounterValue(&discardsIn);
					elem.counterBlock.generic.ifOutOctets = getRawCounterValue(&bytesOut);
					elem.counterBlock.generic.ifOutUcastPkts = (uint32_t)getRawCounterValue(&pktsOut);
					elem.counterBlock.generic.ifOutMulticastPkts = (uint32_t)getRawCounterValue(&mcastsOut);
					elem.counterBlock.generic.ifOutBroadcastPkts = (uint32_t)getRawCounterValue(&bcastsOut);
					elem.counterBlock.generic.ifOutDiscards = (uint32_t) getRawCounterValue(&discardsOut);
				}
				PdhCloseQuery(query);
			}
			elem.counterBlock.generic.ifInErrors = UNKNOWN_COUNTER;
			elem.counterBlock.generic.ifOutErrors = UNKNOWN_COUNTER;
			elem.counterBlock.generic.ifInUnknownProtos = UNKNOWN_COUNTER;
			SFLADD_ELEMENT(cs, &elem);
			myLog(LOG_INFO, "getCounters_interface:\n\tifIndex:\t%u\n\tifType:\t%u\n\tifSpeed:\t%I64u\n"
				"\tifDirection:\t%u\n\tifStatus:\t%u\n\tpromiscuous:\t%u\n\tinOctets:\t%I64u\n\tinUcast:\t%u\n"
				"\tinMulticast:\t%u\n\tinBroadcast:\t%u\n\tinDiscards:\t%u\n\tinErrors:\t%u\n\toutOctets:\t%I64u\n"
				"\toutUcast:\t%u\n\toutMulticast:\t%u\n\toutBroadcast:\t%u\n\toutDiscards:\t%u\n\toutErrors:\t%u",
				elem.counterBlock.generic.ifIndex, elem.counterBlock.generic.ifType, elem.counterBlock.generic.ifSpeed, 
				elem.counterBlock.generic.ifDirection, elem.counterBlock.generic.ifStatus, 
				elem.counterBlock.generic.ifPromiscuousMode, elem.counterBlock.generic.ifInOctets, 
				elem.counterBlock.generic.ifInUcastPkts, elem.counterBlock.generic.ifInMulticastPkts, 
				elem.counterBlock.generic.ifInBroadcastPkts, elem.counterBlock.generic.ifInDiscards, 
				elem.counterBlock.generic.ifInErrors, elem.counterBlock.generic.ifOutOctets, 
				elem.counterBlock.generic.ifOutUcastPkts, elem.counterBlock.generic.ifOutMulticastPkts, 
				elem.counterBlock.generic.ifOutBroadcastPkts, elem.counterBlock.generic.ifOutDiscards, 
				elem.counterBlock.generic.ifOutErrors);
			sfl_poller_writeCountersSample(poller, cs);
		}
	}
}