chromium之tracked_objects
// 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的更多相关文章
- chromium之tracked
//------------------------------------------------------------------------------ // Tracked is the b ...
- 【Chromium中文文档】线程
线程 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Threading. ...
- chromium之task
// A task is a generic runnable thingy, usually used for running code on a // different thread or fo ...
- chromium源码阅读
linux下chromium的入口函数在文件:src/chrome/app/chrome_exe_main_aura.cc 中 int main(int argc, const char** argv ...
- Chromium多线程模型设计和实现分析
Chromium除了远近闻名的多进程架构之外,它的多线程模型也相当引人注目的.Chromium的多进程架构是为了解决网页的稳定性问题,而多线程模型则是为了解决网页的卡顿问题.为了达到这个目的,Chro ...
- QT5利用chromium内核与HTML页面交互
在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...
- Google之Chromium浏览器源码学习——base公共通用库(一)
Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...
- 如何在windows上编译Chromium (CEF3) 并加入MP3支持(二)
时隔一年,再次编译cef3,独一无二的目的仍为加入mp3支持.新版本的编译环境和注意事项都已经发生了变化,于是再记录一下. 一.编译版本 cef版本号格式为X.YYYY.A.gHHHHHHH X为主版 ...
- 如何在Windows上从源码编译Chromium (CEF3) 加入mp3支持
一.什么是CEF CEF即Chromium Embeded Framework,由谷歌的开源浏览器项目Chromium扩展而来,可方便地嵌入其它程序中以得到浏览器功能. CEF包括CEF1和CEF3两 ...
随机推荐
- XHR的应用场景
一.简史 IE5.5最早实现XHR,需要通过ActiveXObject创建xhr实例,直到IE7才定义了XMLHttpRequest对象.IE5.5实现XHR之后,其他浏览器紧随其后实现了XHR,直接 ...
- github使用手册
1.git init 2.git add README.md (增加文件夹/文件:git add dir/files) 3.git commit -m "注释内容” 4.git push - ...
- JSP数据库综合练习
一.问题概述 实现了数据库的增删改查和分页显示. 分页显示:mysql String cmd = "select * from t_user limit &q ...
- Android Activity中状态保存机制
在Activity中保存用户的当前操作状态,如输入框中的文本,一般情况下载按了home键后,重新进入文本框中的东西会丢下,所以我们要保存当前页面信息,如在写短信的时候接到一个电话,那么当你接电话的时候 ...
- spring----spring中的注解@service等的作用
service 是有用的相当于 xml配置中得bean id = service 也可以不指定 不指定相当于 bean id = com. service.service 就是这个类的全限定名 ...
- C#程序集
我的理解: 程序集是一个物理上的概念,一个项目生成的exe或者dll都可以叫做一个程序集,internal修饰的内容可以在程序集内可见.
- 新发布 | Azure镜像市场正式上线
由世纪互联运营的 Azure 镜像市场于2016年9月21日正式落地中国市场,在客户和软件开发商间搭建起了一站式门户.来自全球和本地领先软件开发商并基于 Azure 的云应用.云服务和解决方案在门户中 ...
- bootstrap时时提醒填入数据是否与数据库数据重复
standardcode: { group: '.col-sm-4',//对应前台input的class占用宽度 validators: { notEmpty: { message: '请输入标准代号 ...
- asp.net超过字数限制用省略号...表示
显示8个字,多于8个字, 用...表示 <asp:Repeater runat="server" ID="MsgLists"> ...
- May 30th 2017 Week 22nd Tuesday
Knowledge will give you power, but character respect. 知识给你力量,品格给你别人的尊敬. Good characters can help us ...