zoukankan      html  css  js  c++  java
  • 如何找到bug(7): 检查事例完整性的逻辑

    在 SequentialInputHandler.cpp里,areFragmentsThere()函数用来检查L1id事例的数据片段有没有到齐。

    305 /***************************************************************/
    306 bool SequentialInputHandler::areFragmentsThere(unsigned int l1id)
    307 /***************************************************************/
    308 {
    309 
    310   std::map <unsigned int, int>::iterator it;
    311 
    312   DEBUG_TEXT(DFDB_ROSFM, 10, "SequentialInputHandler::areFragmentsThere. On entry:  l1id =  "
    313                             << l1id << " Size of outstanding map = " << m_outStandingEvents.size());
    314   //If there is a single data channel, every new incoming fragment shall generate a trigger
    315   if (m_numberOfDataChannels==1)
    316     return true;
    317 
    318   //IF in singleFragment mode every new incoming fragment shall generate a trigger
    319   if (m_singleFragmentMode)
    320     return true;
    321 
    322   // update map size histogram
    323   int mapsize = m_outStandingEvents.size();
    324   if (mapsize < (c_mapSizeBins - 1)) {
    325     m_mapSizeHist[mapsize]++;
    326   }
    327   else {                            // overflow
    328     DEBUG_TEXT(DFDB_ROSFM, 8, "mapsize:" << mapsize << std::endl);
    329     m_mapSizeHist[c_mapSizeBins - 1]++;
    330   }
    331 
    332   it = m_outStandingEvents.find(l1id);
    333   if (it == m_outStandingEvents.end()) {  // add l1id to map, suggest at the end
    334     m_outStandingEvents.insert(m_outStandingEvents.end(), std::pair<unsigned int, int>(l1id, 1));
    335     return false;
    336   }
    337   else {  // l1id found
    338     if (it->second == (m_numberOfDataChannels-1)) { // complete 
    339 
    340       for(std::map <u_int, int>::iterator iter = m_outStandingEvents.begin(); iter != m_outStandingEvents.end(); iter++)
    341       {
    342         DEBUG_TEXT(DFDB_ROSFM,8, "iter->first:" << iter->first << ", iter->second:" << iter->second <<  std::endl);
    343       } //打印出来m_outStandingEvents的所有元素
    344       m_outStandingEvents.erase(it);
    345       DEBUG_TEXT(DFDB_ROSFM, 8, "areFragmentsThere: l1id complete " << l1id << " l1id erased and map size = " << m_outStandingEvent    s.size());
    346       return true;
    347     }
    348     else {  // incomplete
    349       (it->second)++;
    350       return false;
    351     }
    352   }
    353 }

    查看头文件:

     72     std::map <u_int, int> m_outStandingEvents;              //u_int = L1ID, int = Number of fragments received for this L1ID
     73                                                        //Once each channel has sent a fragment for a given L1ID the event can be processed

    81 static const int c_mapSizeBins = 100; //Histogram (see below)  常量静态数据成员
    82 std::vector<int> m_mapSizeHist; //The histogram tells you how many events (in terms of L1IDs) the system was working on in parallel                       //at any moment in time

     

    第331~347行是检查事例片段是否到齐的逻辑,m_outStandingEvents是一个map, map元素的key为已经接收的L1id, value为已经接收的L1id Fragment的个数。

    每个dataChannel接收一个Fragment后,都会调用一次areFragmentsThere()来检查该L1id 的Fragment是否到齐。

    检查逻辑是: 例如检查L1id=m的数据片段是否到齐: areFragmentsThere(m)

    如果没有在m_outStandingEvents里找到m, 说明之前还没接收过L1id=m的数据片段,于是在m_outStandingEvents的最后插入<m, 1>,表示现在收到L1id=m的第一个数据片段;

    如果在m_outStandingEvents里找到了key=m的元素,value < m_numberOfDataChannels-1, 说明之前就收到过L1id=m的数据片段,但是还没收齐,将value值加1, 表示又收到了一个;如果value =m_numberOfDataChannels-1,说明现在刚好收齐了所有L1id=m的数据片段。

    log文件:

       3687 Debug(1,139760517510912): iter->first:0, iter->second:63
       3688 
       3689 Debug(1,139760517510912): iter->first:1, iter->second:22
       3690 
       3691 Debug(1,139760517510912): iter->first:2, iter->second:9
       3692 
       3693 Debug(1,139760517510912): iter->first:3, iter->second:8
       3694 
       3695 Debug(1,139760517510912): iter->first:4, iter->second:1
       3696 
       3697 Debug(1,139760517510912): iter->first:5, iter->second:1
       3698 
       3699 Debug(1,139760517510912): areFragmentsThere: l1id complete 0 l1id erased and map size = 5
       3700 InputHandler got first ROD: 0
       3701 now we are going to recv data!
       3702 Debug(1,139760517510912): iter->first:1, iter->second:42
       3703 
       3704 Debug(1,139760517510912): iter->first:2, iter->second:55
       3705 
       3706 Debug(1,139760517510912): iter->first:3, iter->second:56
       3707 
       3708 Debug(1,139760517510912): iter->first:4, iter->second:63
       3709 
       3710 Debug(1,139760517510912): iter->first:5, iter->second:63
       3711 
       3712 Debug(1,139760517510912): iter->first:6, iter->second:63
       3713 
       3714 Debug(1,139760517510912): iter->first:7, iter->second:22
       3715 
       3716 Debug(1,139760517510912): iter->first:8, iter->second:9
       3717 
       3718 Debug(1,139760517510912): iter->first:9, iter->second:8
       3719 
       3720 Debug(1,139760517510912): iter->first:10, iter->second:1
       3721 
       3722 Debug(1,139760517510912): iter->first:11, iter->second:1
       3723 
       3724 Debug(1,139760517510912): areFragmentsThere: l1id complete 6 l1id erased and map size = 10

    为什么log文件里面L1id值大的Fragment收到的个数比L1id值小的Fragment收到的个数还多呢?按照这个检查逻辑,好像有哪里不对啊?

  • 相关阅读:
    Python数据分析的几种绘图方式——数据可视化(附源码)
    Python GUI项目实战:主窗体的界面设计与实现
    Python Scrapy框架:数据爬取全流程
    python来爬取煎蛋网随手拍小姐姐图片
    有意思的逻辑小练习:函数做参数进行传递
    python值*args和**kwargs的总结思考
    数据类型的基础知识补充,字典的并交集、空集合、可作为字典元组的元素、删除字典中的元素
    python里面为什么shell和保存文件运行结果不一样的相关思考(内存相关)
    代码:购物车(待修改)
    python里面为什么shell和保存文件运行结果不一样?
  • 原文地址:https://www.cnblogs.com/zengtx/p/6421225.html
Copyright © 2011-2022 走看看