1. // For each thread, we have a ThreadData that stores all tracking info generated
  2. // on this thread. This prevents the need for locking as data accumulates.

该文件用到了chromium之ThreadLocalStorage

看看头文件

  1. class ThreadData {
  2. public:
  3. typedef std::map<Location, Births*> BirthMap;
  4. typedef std::map<const Births*, DeathData> DeathMap;
  5.  
  6. ThreadData();
  7.  
  8. // Using Thread Local Store, find the current instance for collecting data.
  9. // If an instance does not exist, construct one (and remember it for use on
  10. // this thread.
  11. // If shutdown has already started, and we don't yet have an instance, then
  12. // return null.
  13. static ThreadData* current();
  14.  
  15. // For a given about:objects URL, develop resulting HTML, and append to
  16. // output.
  17. static void WriteHTML(const std::string& query, std::string* output);
  18.  
  19. // For a given accumulated array of results, use the comparator to sort and
  20. // subtotal, writing the results to the output.
  21. static void WriteHTMLTotalAndSubtotals(
  22. const DataCollector::Collection& match_array,
  23. const Comparator& comparator, std::string* output);
  24.  
  25. // In this thread's data, find a place to record a new birth.
  26. Births* FindLifetime(const Location& location);
  27.  
  28. // Find a place to record a death on this thread.
  29. void TallyADeath(const Births& lifetimes, const base::TimeDelta& duration);
  30.  
  31. // (Thread safe) Get start of list of instances.
  32. static ThreadData* first();
  33. // Iterate through the null terminated list of instances.
  34. ThreadData* next() const { return next_; }
  35.  
  36. MessageLoop* message_loop() const { return message_loop_; }
  37. const std::string ThreadName() const;
  38.  
  39. // Using our lock, make a copy of the specified maps. These calls may arrive
  40. // from non-local threads.
  41. void SnapshotBirthMap(BirthMap *output) const;
  42. void SnapshotDeathMap(DeathMap *output) const;
  43.  
  44. static void RunOnAllThreads(void (*Func)());
  45.  
  46. // Set internal status_ to either become ACTIVE, or later, to be SHUTDOWN,
  47. // based on argument being true or false respectively.
  48. // IF tracking is not compiled in, this function will return false.
  49. static bool StartTracking(bool status);
  50. static bool IsActive();
  51.  
  52. #ifdef OS_WIN
  53. // WARNING: ONLY call this function when all MessageLoops are still intact for
  54. // all registered threads. IF you call it later, you will crash.
  55. // Note: You don't need to call it at all, and you can wait till you are
  56. // single threaded (again) to do the cleanup via
  57. // ShutdownSingleThreadedCleanup().
  58. // Start the teardown (shutdown) process in a multi-thread mode by disabling
  59. // further additions to thread database on all threads. First it makes a
  60. // local (locked) change to prevent any more threads from registering. Then
  61. // it Posts a Task to all registered threads to be sure they are aware that no
  62. // more accumulation can take place.
  63. static void ShutdownMultiThreadTracking();
  64. #endif
  65.  
  66. // WARNING: ONLY call this function when you are running single threaded
  67. // (again) and all message loops and threads have terminated. Until that
  68. // point some threads may still attempt to write into our data structures.
  69. // Delete recursively all data structures, starting with the list of
  70. // ThreadData instances.
  71. static void ShutdownSingleThreadedCleanup();

大致想想怎么用

1. 开始

开始运行,

  1. StartTracking(true)

2. 结束,并输出

  1. StartTracking(false)
  1. WriteHTML(...)
  2.  
  3. 有个测试用例,可以看看
  1. TEST_F(TrackedObjectsTest, MinimalStartupShutdown) {
  2. // Minimal test doesn't even create any tasks.
  3. if (!ThreadData::StartTracking(true))
  4. return;
  5.  
  6. EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
  7. ThreadData* data = ThreadData::current();
  8. EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
  9. EXPECT_TRUE(data);
  10. EXPECT_TRUE(!data->next());
  11. EXPECT_EQ(data, ThreadData::current());
  12. ThreadData::BirthMap birth_map;
  13. data->SnapshotBirthMap(&birth_map); // Get all birth data
  14. EXPECT_EQ(0u, birth_map.size());
  15. ThreadData::DeathMap death_map;
  16. data->SnapshotDeathMap(&death_map);
  17. EXPECT_EQ(0u, death_map.size());
  18. ThreadData::ShutdownSingleThreadedCleanup();
  19.  
  20. // Do it again, just to be sure we reset state completely.
  21. ThreadData::StartTracking(true);
  22. EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
  23. data = ThreadData::current();
  24. EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
  25. EXPECT_TRUE(data);
  26. EXPECT_TRUE(!data->next());
  27. EXPECT_EQ(data, ThreadData::current());
  28. birth_map.clear();
  29. data->SnapshotBirthMap(&birth_map);
  30. EXPECT_EQ(0u, birth_map.size());
  31. death_map.clear();
  32. data->SnapshotDeathMap(&death_map);
  33. EXPECT_EQ(0u, death_map.size());
  34. ThreadData::ShutdownSingleThreadedCleanup();
  35. }

chromium之tracked_objects的更多相关文章

  1. chromium之tracked

    //------------------------------------------------------------------------------ // Tracked is the b ...

  2. 【Chromium中文文档】线程

    线程 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Threading. ...

  3. chromium之task

    // A task is a generic runnable thingy, usually used for running code on a // different thread or fo ...

  4. chromium源码阅读

    linux下chromium的入口函数在文件:src/chrome/app/chrome_exe_main_aura.cc 中 int main(int argc, const char** argv ...

  5. Chromium多线程模型设计和实现分析

    Chromium除了远近闻名的多进程架构之外,它的多线程模型也相当引人注目的.Chromium的多进程架构是为了解决网页的稳定性问题,而多线程模型则是为了解决网页的卡顿问题.为了达到这个目的,Chro ...

  6. QT5利用chromium内核与HTML页面交互

    在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...

  7. Google之Chromium浏览器源码学习——base公共通用库(一)

    Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...

  8. 如何在windows上编译Chromium (CEF3) 并加入MP3支持(二)

    时隔一年,再次编译cef3,独一无二的目的仍为加入mp3支持.新版本的编译环境和注意事项都已经发生了变化,于是再记录一下. 一.编译版本 cef版本号格式为X.YYYY.A.gHHHHHHH X为主版 ...

  9. 如何在Windows上从源码编译Chromium (CEF3) 加入mp3支持

    一.什么是CEF CEF即Chromium Embeded Framework,由谷歌的开源浏览器项目Chromium扩展而来,可方便地嵌入其它程序中以得到浏览器功能. CEF包括CEF1和CEF3两 ...

随机推荐

  1. 当Activity出现Exception时是如何处理的?

    1.ActivityThread 2.PerformStop 在这里会调用mWindow.closeAllPanels(),从而关闭OptionMenu, ContextMenu.如果自己通过Wind ...

  2. rest-framework框架——解析器、ur控制、分页、响应器、渲染器、版本

    一.解析器(parser) 解析器在reqest.data取值的时候才执行. 对请求的数据进行解析:是针对请求体进行解析的.表示服务器可以解析的数据格式的种类. from rest_framework ...

  3. 【数据库】1.0 MySQL入门学习(一)——常识性知识

    1.0 什么是MySQL(官方发音 My Ess Que Ell)? 是一个快速.多线程.多用户和强壮的SQL数据库服务器,SQL是世界上最流行的标准化数据库语言. 名字来源:共同创办人Monty W ...

  4. 转载《学习HTML5 canvas遇到的问题》

    学习HTML5 canvas遇到的问题 1. 非零环绕原则(nonzZero rule) 非零环绕原则是canvas在进行填充的时候是否要进行填充的判断依据. 在判断填充的区域拉一条线出来,拉到图形的 ...

  5. r.js压缩打包

    AMD模块化开发中的代码压缩打包工具——r.js 环境搭建基于nodejs:用于AMD模块化开发中的项目文件压缩打包,不是AMD模式也是可以的 javascript部分 压缩javascript项目开 ...

  6. 企业Web应用创新实验

    我现在设计一个小而美的管理工具,为此费劲心思搞“创新”.“创新”一词已经被滥用,但我...真的想弄出一点创新. 基于Web的企业应用,如CRM.项目管理.OA等软件,尽管经历十几年发展,所谓的理论有所 ...

  7. arcgis版接合图表5.2 免费软件,支持国家2000坐标系,ArcGIS10.0,ArcGIS10.1,ArcGIS10.2都可以使用

    下载地址:http://files.cnblogs.com/gisoracle/jionmap52.rar 1.      国家2000,西安80,北京54.坐标系的接合图表生成.根据经纬度范围,坐标 ...

  8. mybooklist.cn 书单de故事六月十六日

    1.我的30年30本书 刘苏里书单北京万圣书园总经理,以经营人文社科类图书著称.生于1960年,1983年毕业于北京大学国际政治系,1986年毕业于中国政法大学研究生院.

  9. May 26th 2017 Week 21st Friday

    One thorn of experience is worth a whole wilderness of warning. 一次痛彻心扉的经历,抵得上千百次的告诫. Several days ag ...

  10. Django运行SQL语句

    1.Manager.raw(raw_query, params=None, translations=None) >>> for p in Person.objects.raw('S ...