コード例 #1
0
ファイル: ReapThread.cpp プロジェクト: daliniu/mobile
void PropertyDimenReapThread::getData(const string &sCloneFile, vector<map<PropDimenHead,PropBody> > &mAllStatMsg)
{
    try
    {
        PropertyHashMap tHashmap;
        tHashmap.initStore(sCloneFile.c_str(), g_hashmap.getMapHead()._iMemSize);
        LOG->debug() << "PropertyDimenReapThread::getData tHashmap Chunk:"<<tHashmap.allBlockChunkCount() <<"|"<<tHashmap.getMapHead()._iUsedChunk<<endl;
		int dbNumber = PropertyDimenDbManager::getInstance()->getDbNumber();
		int iCount = 0, dbSeq = 0;

		PropertyHashMap::lock_iterator it = tHashmap.beginSetTime();
        while ( it != tHashmap.end() )
        {
            PropDimenHead head;
            PropBody body;
            int ret = it->get( head, body );
            if ( ret < 0 )
            {
                continue;
            }

			PropertyDimenDbManager::getInstance()->filter(head, body);

			if (dbNumber > 0 && body.vInfo.size() > 0)
			{
				dbSeq = iCount%dbNumber;
				mAllStatMsg[dbSeq][head] = body;
			}
			iCount++;
            ++it;
        }
        LOG->debug() << "get total iCount:" << iCount << endl;
    }
    catch (exception& ex)
    {
        LOG->debug() << "PropertyDimenReapThread::getData exception:"<< ex.what() << endl;
		TAF_NOTIFY_ERROR("PropertyDimenReapThread::getData exception:"+string(ex.what()));
    }
}
コード例 #2
0
ファイル: PropertyImp.cpp プロジェクト: Blucezhang/Tars
int PropertyImp::handlePropMsg(const map<StatPropMsgHead, StatPropMsgBody> &propMsg, tars::TarsCurrentPtr current)
{
    for ( map<StatPropMsgHead,StatPropMsgBody>::const_iterator it = propMsg.begin(); it != propMsg.end(); it++ )
    {

        const StatPropMsgHead &head = it->first;
        const StatPropMsgBody &body = it->second;

        PropHead tHead;
        tHead.moduleName    = head.moduleName;
        tHead.propertyName  = head.propertyName;
        tHead.setName       = head.setName;
        tHead.setArea       = head.setArea;
        tHead.setID         = head.setID;
        tHead.ip            = current->getIp();

        size_t iIndex = 0;
        PropertyImpThreadData * td = PropertyImpThreadData::getData();

        if(td)
        {
            iIndex = td->_threadIndex;
        }

        dump2file();

        int iBufferIndex = g_app.getSelectBufferIndex();

        if(_lastBufferIndex != iBufferIndex)
        {
            if(_lastBufferIndex != -1)
            {
                TLOGDEBUG("PropertyImp::handlePropMsg iIndex:" << iIndex << "|iBufferIndex:" << iBufferIndex << "|_lastBufferIndex:" << _lastBufferIndex << endl);

                map<int,vector<pair<int64_t, int> > >& mBuffer = g_app.getBuffer();
                map<int,vector<pair<int64_t, int> > >::iterator iter = mBuffer.find(_lastBufferIndex);
                iter->second[iIndex].first  = TNOWMS;
                iter->second[iIndex].second = 1;
            }

            _lastBufferIndex = iBufferIndex;
        }

        string sKey = tHead.moduleName;
        sKey += tHead.ip;

        int iHashKey = _hashf(sKey) % g_app.getBuffNum();

        PropertyHashMap *pHashMap = g_app.getHashMapBuff(iBufferIndex, iHashKey);
        
        //////////////////////////////////////////////////////////////////////////////////////

        float rate =  (pHashMap->getMapHead()._iUsedChunk) * 1.0/pHashMap->allBlockChunkCount();

        if(rate >0.9)
        {
            pHashMap->expand(pHashMap->getMapHead()._iMemSize * 2);
            TLOGERROR("PropertyImp::handlePropMsg hashmap expand to " << pHashMap->getMapHead()._iMemSize << endl);
        }

        int iRet = pHashMap->add(tHead, body);
        if(iRet != TC_HashMap::RT_OK )
        {
            TLOGERROR("PropertyImp::handlePropMsg add hashmap recourd iRet:" << iRet << endl);
        }

        if(LOG->IsNeedLog(TarsRollLogger::INFO_LOG))
        {
            ostringstream os;
            os.str("");
            head.displaySimple(os);
            body.displaySimple(os);
            TLOGINFO("ret|"<<iRet<<"|"<<os.str()<< endl);
        }

    }

    return 0;
}