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

该文件用到了chromium之ThreadLocalStorage

看看头文件

class ThreadData {
public:
typedef std::map<Location, Births*> BirthMap;
typedef std::map<const Births*, DeathData> DeathMap; ThreadData(); // Using Thread Local Store, find the current instance for collecting data.
// If an instance does not exist, construct one (and remember it for use on
// this thread.
// If shutdown has already started, and we don't yet have an instance, then
// return null.
static ThreadData* current(); // For a given about:objects URL, develop resulting HTML, and append to
// output.
static void WriteHTML(const std::string& query, std::string* output); // For a given accumulated array of results, use the comparator to sort and
// subtotal, writing the results to the output.
static void WriteHTMLTotalAndSubtotals(
const DataCollector::Collection& match_array,
const Comparator& comparator, std::string* output); // In this thread's data, find a place to record a new birth.
Births* FindLifetime(const Location& location); // Find a place to record a death on this thread.
void TallyADeath(const Births& lifetimes, const base::TimeDelta& duration); // (Thread safe) Get start of list of instances.
static ThreadData* first();
// Iterate through the null terminated list of instances.
ThreadData* next() const { return next_; } MessageLoop* message_loop() const { return message_loop_; }
const std::string ThreadName() const; // Using our lock, make a copy of the specified maps. These calls may arrive
// from non-local threads.
void SnapshotBirthMap(BirthMap *output) const;
void SnapshotDeathMap(DeathMap *output) const; static void RunOnAllThreads(void (*Func)()); // Set internal status_ to either become ACTIVE, or later, to be SHUTDOWN,
// based on argument being true or false respectively.
// IF tracking is not compiled in, this function will return false.
static bool StartTracking(bool status);
static bool IsActive(); #ifdef OS_WIN
// WARNING: ONLY call this function when all MessageLoops are still intact for
// all registered threads. IF you call it later, you will crash.
// Note: You don't need to call it at all, and you can wait till you are
// single threaded (again) to do the cleanup via
// ShutdownSingleThreadedCleanup().
// Start the teardown (shutdown) process in a multi-thread mode by disabling
// further additions to thread database on all threads. First it makes a
// local (locked) change to prevent any more threads from registering. Then
// it Posts a Task to all registered threads to be sure they are aware that no
// more accumulation can take place.
static void ShutdownMultiThreadTracking();
#endif // WARNING: ONLY call this function when you are running single threaded
// (again) and all message loops and threads have terminated. Until that
// point some threads may still attempt to write into our data structures.
// Delete recursively all data structures, starting with the list of
// ThreadData instances.
static void ShutdownSingleThreadedCleanup();

大致想想怎么用

1. 开始

开始运行,

StartTracking(true)

2. 结束,并输出

StartTracking(false)
WriteHTML(...)

有个测试用例,可以看看
TEST_F(TrackedObjectsTest, MinimalStartupShutdown) {
// Minimal test doesn't even create any tasks.
if (!ThreadData::StartTracking(true))
return; EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
ThreadData* data = ThreadData::current();
EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
EXPECT_TRUE(data);
EXPECT_TRUE(!data->next());
EXPECT_EQ(data, ThreadData::current());
ThreadData::BirthMap birth_map;
data->SnapshotBirthMap(&birth_map); // Get all birth data
EXPECT_EQ(0u, birth_map.size());
ThreadData::DeathMap death_map;
data->SnapshotDeathMap(&death_map);
EXPECT_EQ(0u, death_map.size());
ThreadData::ShutdownSingleThreadedCleanup(); // Do it again, just to be sure we reset state completely.
ThreadData::StartTracking(true);
EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
data = ThreadData::current();
EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
EXPECT_TRUE(data);
EXPECT_TRUE(!data->next());
EXPECT_EQ(data, ThreadData::current());
birth_map.clear();
data->SnapshotBirthMap(&birth_map);
EXPECT_EQ(0u, birth_map.size());
death_map.clear();
data->SnapshotDeathMap(&death_map);
EXPECT_EQ(0u, death_map.size());
ThreadData::ShutdownSingleThreadedCleanup();
}

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. struts2的基本配置

    1.package标签下主要的点在namespace和name,extend上 extend 一般继承自struts-default.xml下,继承其拦截器及一些功能,这个已在本人的拦截器一文中有讲到 ...

  2. WinSock WSAEventSelect 模型

    在前面我们说了WSAAsyncSelect 模型,它相比于select模型来说提供了这样一种机制:当发生对应的IO通知时会立即通知操作系统,并调用对应的处理函数,它解决了调用send和 recv的时机 ...

  3. springmvc 全局的异常拦截处理 @ControllerAdvice注解 @ExceptionHandler

    第一步: Dispatcher前端控制器的源码中 默认的 private boolean throwExceptionIfNoHandlerFound = false;说明如果没有找到匹配的执行器,不 ...

  4. iOS开发之Objective-c的AES128加密和解密算法的实现

    #import <Foundation/Foundation.h> #import <CommonCrypto/CommonDigest.h> #import <Comm ...

  5. 五款app原型设计工具对比

    五款app原型设计工具对比 Proto.io, Pixate, Origami, Framer & Form 本文由Panblack 翻译,原文作者 Tes Mat 我用五款“高保真”原型设计 ...

  6. 3D开源推荐:3DWebExplorer

    开源网址:https://github.com/irconde/3DWebExplorer 介绍:演示如何内嵌Google Earth 插件,开发面向公众的3D旅游展示平台

  7. matlab练习程序(结构张量structure tensor)

    根据结构张量能区分图像的平坦区域.边缘区域与角点区域. 此算法也算是计算机科学最重要的32个算法之一了.链接的文章中此算法名称为Strukturtensor算法,不过我搜索了一下,Strukturte ...

  8. 在crontab中执行脚本重要事项

    crontab不能成功执行shell脚本的可能原因 crond进程不存在,该进程是crontab的守护进程,它必须存在才能让crontab正常使用: 系统时间不对: 环境变量的问题:crontab执行 ...

  9. MySQL的基础(优化)3

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  10. 建立自己的git账户并保存资料的重要性

    Github是一个代码托管平台和开发者社区,开发者可以在Github上创建自己的开源项目并与其他开发者协作编码.创业公司可以用它来托管软件项目,开源项目可以免费托管,私有项目需付费.[2] GitHu ...