当前位置: 首页>>代码示例>>C++>>正文


C++ Timeval::getTimeAsMilliSecondsDouble方法代码示例

本文整理汇总了C++中Timeval::getTimeAsMilliSecondsDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ Timeval::getTimeAsMilliSecondsDouble方法的具体用法?C++ Timeval::getTimeAsMilliSecondsDouble怎么用?C++ Timeval::getTimeAsMilliSecondsDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Timeval的用法示例。


在下文中一共展示了Timeval::getTimeAsMilliSecondsDouble方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getKey

void
ReplicationOptimizer::notifySendFailure(DataObjectRef dObj, NodeRef node)
{
    if (utilFunction) {
        utilFunction->notifySendFailure(dObj, node);
    }

    string dobj_id = DataObject::idString(dObj);
    string node_id = Node::idString(node);
    string key = getKey(dobj_id, node_id);

    meta_map_t::iterator it = meta.find(key);
    if (it == meta.end()) {
        errorCount++;
        HAGGLE_ERR("Missing entry.\n");
        return;
    }

    ReplicationDataObjectUtilityMetadataRef do_info = (*it).second;
    if (!do_info) {
        errorCount++;
        HAGGLE_ERR("Missing metadata.\n");
        return;
    }

    Timeval now = Timeval::now();
    double delta = now.getTimeAsMilliSecondsDouble() - do_info->getComputedTime().getTimeAsMilliSecondsDouble();

    if (delta > computePeriodMs && utilFunction) {
        double new_utility = utilFunction->compute(do_info->getId(), do_info->getNodeId());
        do_info->setUtility(new_utility, now);
    }
}
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:33,代码来源:ReplicationOptimizer.cpp

示例2: updateInfoDataObject

void EvictStrategyLRFU::updateInfoDataObject(DataObjectRef &dObj, unsigned int count, Timeval time) 
{

    ScratchpadManager *pad = getKernel()->getDataStore()->getScratchpadManager();
    //create scratchpad keys
    string paramNameF0=name;
    paramNameF0.append("_LRU_F0");
    double c_now = 0.0;
    double c_old = 0.0;
    double lastTime = 0.0;
    double paramValueF0 = 0.0;
    double paramValueLastk = 0.0;
    string paramName_c_now=name;
    paramName_c_now.append("_c_now");
    string paramNameLastk=name;
    paramNameLastk.append("_LRU_last_k");
    
    if (countType == EVICT_STRAT_LRFU_COUNT_TYPE_TIME) {
	paramValueLastk = time.getTimeAsMilliSecondsDouble();
    } else {  //otherwise count
	paramValueLastk = (double) count; 
    }

    bool has_attr = pad->hasScratchpadAttributeDouble(dObj, paramNameF0);
    if (has_attr) {
        paramValueF0 = pad->getScratchpadAttributeDouble(dObj, paramNameF0);
	c_now = pad->getScratchpadAttributeDouble(dObj, paramName_c_now);
	c_old = c_now;
       	lastTime = pad->getScratchpadAttributeDouble(dObj, paramNameLastk);
        c_now *= fx_calc(paramValueLastk-lastTime);
        c_now += paramValueF0; 
       	HAGGLE_DBG("%s f(x) = %f + G(%f - %f)*%f = %f\n", dObj->getIdStr() ,paramValueF0 , (float) count, lastTime, c_old,  c_now);

    } else {
	c_now = 1.0; //fx_calc(paramValueLastk);
       	pad->setScratchpadAttributeDouble(dObj, paramNameF0, c_now);
       	HAGGLE_DBG("%s f(0) = g(%f) = %f\n", dObj->getIdStr(), paramValueLastk, c_now);
    }

   //set current values
   pad->setScratchpadAttributeDouble(dObj, paramName_c_now, c_now);
   pad->setScratchpadAttributeDouble(dObj, paramNameLastk, paramValueLastk);
   

}
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:45,代码来源:EvictStrategyLRFU.cpp

示例3:

void
ReplicationOptimizer::computeUtilities()
{
    for (meta_map_t::iterator it = meta.begin(); it != meta.end(); it++) {
        ReplicationDataObjectUtilityMetadataRef do_info = (*it).second;
        if (!do_info) {
            errorCount++;
            HAGGLE_ERR("NULL DO in cache\n");
            continue;
        }
        Timeval now = Timeval::now();
        // was the utility recently computed?
        double delta = now.getTimeAsMilliSecondsDouble() - do_info->getComputedTime().getTimeAsMilliSecondsDouble();
        if (delta > computePeriodMs && utilFunction) {
            double new_utility = utilFunction->compute(do_info->getId(), do_info->getNodeId());
HAGGLE_DBG("do:node %s:%s has a utility value of %f\n", do_info->getId().c_str(), do_info->getNodeId().c_str());
            do_info->setUtility(new_utility, now);
        }
    }
}
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:20,代码来源:ReplicationOptimizer.cpp

示例4: getCost

/**
 * Find the next best data object to replicate towards neighbor with id
 * `node_id`, given that we have an estimated `bytes_left` bytes left to
 *  send. If `bytes_left == 0` then we assume the bag size is infinite
 * and therefore send data objects with highest utility first.
 * If the computed bytes_left < 0 then the bag is full and no data objects
 * will be replicated.
 */
bool
ReplicationOptimizer::getNextDataObject(string node_id, List<string> &dobj_blacklist, int bytes_left, DataObjectRef& o_dobj, NodeRef& o_node)
{
    neighbor_node_id_map_t::iterator it = utils.find(node_id);
    if (it == utils.end()) {
        // no data objects for node
        if (dobjs.size() != 0) {
            errorCount++;
            HAGGLE_ERR("Neighbors map missing data objects.\n");
        }
        return false;
    }

    {
        node_map_t::iterator it = node_map.find(node_id);
        if (it == node_map.end()) {
            HAGGLE_ERR("Node missing from data structure.\n");
            return false;
        }
        o_node = (*it).second;
        if (!o_node) {
            HAGGLE_ERR("NULL node.\n");
            return false;
        }
    }
    // remove in-flight data objects from the bag size
    for (List<string>::iterator itt = dobj_blacklist.begin(); itt != dobj_blacklist.end(); itt++) {
        string dobj_id = (*itt);
        if (bytes_left != 0) {   //0 means unilmited
        	bytes_left = bytes_left - getCost(dobj_id, node_id);
		if (bytes_left == 0) { bytes_left = -1; }
 	}
    }

    if (bytes_left < 0) {
        // buffer already full
        return false;
    }

    // used when bytes_left == 0
    double best_utility = 0;
    int best_cost = 0;
    string best_dobj_id = "";

    List<ReplicationDataObjectUtilityMetadataRef> process_dos;
    List<ReplicationDataObjectUtilityMetadataRef> include_dos;
    List<ReplicationDataObjectUtilityMetadataRef> exclude_dos;

    for (;it != utils.end() && (*it).first == node_id; it++) {
        ReplicationDataObjectUtilityMetadataRef do_info = (*it).second;
        Timeval now = Timeval::now();
        if (!do_info) {
            errorCount++;
            HAGGLE_ERR("NULL DO in cache\n");
            continue;
        }
        string do_id = do_info->getId();
        DataObjectId_t id;
        DataObject::idStrToId(do_id, id);

        bool inBloomfilter = o_node->getBloomfilter()->has(id);
        if (inBloomfilter) {
            HAGGLE_DBG("Skipping, %s already in bloomfilter.\n", Node::nameString(o_node).c_str());
            continue;
        }

        // skip over data objects in the black list
        bool inBlacklist = false;
        for (List<string>::iterator itt = dobj_blacklist.begin(); itt != dobj_blacklist.end(); itt++) {
            if ((*itt) == do_id) {
                inBlacklist = true;
                break;
            }
        }
        if (inBlacklist) {
            continue;
        }
        // recompute the utility if need be
        double delta = now.getTimeAsMilliSecondsDouble() - do_info->getComputedTime().getTimeAsMilliSecondsDouble();
        if (delta > computePeriodMs && utilFunction) {
            double new_utility = utilFunction->compute(do_info->getId(), do_info->getNodeId());
            do_info->setUtility(new_utility, now);

        }
        // skip utilites beneeath threshold
        int cost = do_info->getCost();
        double util = do_info->getUtility();
        if (util >= globalOptimizer->getMinimumThreshold()) {
            process_dos.push_front(do_info);
            if (util > best_utility || (util == best_utility && cost < best_cost)) {
                best_utility = util;
                best_cost = cost;
//.........这里部分代码省略.........
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:101,代码来源:ReplicationOptimizer.cpp

示例5: getUtilityFunction

/**
 * The main function to purge the cache and recompute utilities. 
 * If HAGGLE_DEBUG2 is set, this will add a new debug printout per utility computation,
 * which wills how the results of each individual utility value per data object.
 * Useful for verifying new utilities are acting correctly, not recommended for production
 * run.   To use this feature, pass any non empty string to getUtilityFunction()->compute(id, string).
 * The compute() routines will append current values and status for the data object identified by 'id'
 * only if the string being passed is non empty.   If the string is empty, the routines ignore it.
 *
 */
void
CacheStrategyUtility::_purgeCache(string doid, bool *o_was_deleted)
{
    List<DataObjectUtilityMetadata *> process_dos;
    List<DataObjectUtilityMetadata *> delete_dos;
    long long total_size = 0;
    // iterate across data objects and compute utilities for
    // DOS that have not been computed recently
    for (do_util_metadata_t::iterator it = utilMetadata.begin(); it != utilMetadata.end(); it++) {
        DataObjectUtilityMetadata *do_info = (*it).second;
        Timeval now = Timeval::now();
        if (!do_info) {
            HAGGLE_ERR("NULL DO in cache\n");
            continue;
        }
        total_size += do_info->getCost();
        // was the utility recently computed?
        double delta = now.getTimeAsMilliSecondsDouble() - do_info->getComputedTime().getTimeAsMilliSecondsDouble();
        if (delta > computePeriodMs) {
            string strResults="";
            if (Trace::trace.getTraceType() == TRACE_TYPE_DEBUG2) {
              strResults.append(do_info->getId());
              strResults.append("[T]=");
            }
            double new_utility = getUtilityFunction()->compute(do_info->getId(), strResults);
            do_info->setUtility(new_utility, now);
            HAGGLE_DBG2("%s --> %f\n", strResults.c_str(), new_utility);
        }

        // does the utility meet the threshold?
        if (do_info->getUtility() < getGlobalOptimizer()->getMinimumThreshold()) {
            delete_dos.push_front(do_info);
        }
        else {
            process_dos.push_front(do_info);
        }
    }

    if (total_size != current_size) {
        HAGGLE_ERR("Fatal error: count mismatch of cache sizes! (%lld != %lld)\n", total_size, current_size);
        return;
    }

    if (total_size > (watermark_capacity_kb*1024)) {
        CacheKnapsackOptimizerResults results = getKnapsackOptimizer()->solve(&process_dos, &delete_dos, watermark_capacity_kb*1024 );
        if (results.getHadError()) {
            HAGGLE_ERR("Knapsack optimizer failed\n");
        }
    }
    else {
        //HAGGLE_DBG("High water mark short-circuit, bypassing knapsack...\n");
    }


    int num_deleted = 0;
    long long bytes_freed = 0;

    while (!delete_dos.empty()) {
        DataObjectUtilityMetadata *to_delete = delete_dos.front();
        delete_dos.pop_front();
        if (!to_delete) {
            HAGGLE_ERR("NULL utility\n");
            continue;
        }
        DataObjectId_t id;
        DataObject::idStrToId(to_delete->getId(), id);
		bool deletionEnabled = to_delete->getEnableDeletion();

        if (to_delete->getId() == doid && o_was_deleted) {
            *o_was_deleted = true;
        }

        bytes_freed += to_delete->getCost();

        num_deleted++;

        // some DOs should not be deleted immedaitely 
        // (they may not even be inserted yet)
        if (deletionEnabled) {
            getManager()->getKernel()->getDataStore()->deleteDataObject(id, true);
        }

        DataObjectRef stale_dobj = to_delete->getDataObject();
        // SW: this will delete "to_delete"
        _handleDeletedDataObject(stale_dobj);
    }

    // sanity check
    if (current_size > (watermark_capacity_kb*1024)) {
        HAGGLE_ERR("Optimizer failed (did not remove enough bytes)\n");
//.........这里部分代码省略.........
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:101,代码来源:CacheStrategyUtility.cpp


注:本文中的Timeval::getTimeAsMilliSecondsDouble方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。