chromium之histogram.h
histogram不知道是干啥的
// Histogram is an object that aggregates statistics, and can summarize them in
// various forms, including ASCII graphical, HTML, and numerically (as a
// vector of numbers corresponding to each of the aggregating buckets).
google翻译
//直方图是汇总统计信息的对象,可以将它们汇总
//各种形式,包括ASCII图形,HTML和数字(如
//每个聚合桶对应的数字向量)。
直方图——不就是统计用的,PPT还有饼图什么的
不管了,看看怎么实现的,就知道是干嘛用的了。
瞄一下,有没有引用不认识的头文件
histogram.cc
#include "base/histogram.h" #include <math.h>
#include <string> #include "base/logging.h"
#include "base/pickle.h"
#include "base/string_util.h"
有一个!
#include "base/pickle.h"
参见分析chromium之pickle,我们知道该类提供基本的二进制打包、解包的功能。这样代码就能继续看下去了
这个pickle在头文件里有用到
bool Serialize(Pickle* pickle) const;
bool Deserialize(void** iter, const Pickle& pickle);
序列化一般是进程间通讯传递数据用的
序列化在什么时候用:
当你想把的内存中的对象状态保存到一个文件中或者数据库中时候;
当你想用套接字在网络上传送对象的时候;
当你想通过RMI传输对象的时候;
一个类,有没有掌握——给你头文件,你会不会使用里面的函数——会了,这个类你就懂了。
class Pickle;
class Histogram {
public:
//----------------------------------------------------------------------------
// Statistic values, developed over the life of the histogram.
class SampleSet {
public:
explicit SampleSet();
// Adjust size of counts_ for use with given histogram.
void Resize(const Histogram& histogram);
void CheckSize(const Histogram& histogram) const;
// Accessor for histogram to make routine additions.
void Accumulate(Sample value, Count count, size_t index);
// Accessor methods.
Count counts(size_t i) const { return counts_[i]; }
Count TotalCount() const;
int64 sum() const { return sum_; }
int64 square_sum() const { return square_sum_; }
// Arithmetic manipulation of corresponding elements of the set.
void Add(const SampleSet& other);
void Subtract(const SampleSet& other);
bool Serialize(Pickle* pickle) const;
bool Deserialize(void** iter, const Pickle& pickle);
protected:
// Actual histogram data is stored in buckets, showing the count of values
// that fit into each bucket.
Counts counts_;
// Save simple stats locally. Note that this MIGHT get done in base class
// without shared memory at some point.
int64 sum_; // sum of samples.
int64 square_sum_; // sum of squares of samples.
};
//----------------------------------------------------------------------------
Histogram(const char* name, Sample minimum,
Sample maximum, size_t bucket_count);
Histogram(const char* name, base::TimeDelta minimum,
base::TimeDelta maximum, size_t bucket_count);
virtual ~Histogram();
void Add(int value);
// Accept a TimeDelta to increment.
void AddTime(base::TimeDelta time) {
Add(static_cast<int>(time.InMilliseconds()));
}
void AddSampleSet(const SampleSet& sample);
// The following methods provide graphical histogram displays.
void WriteHTMLGraph(std::string* output) const;
void WriteAscii(bool graph_it, const std::string& newline,
std::string* output) const;
// Support generic flagging of Histograms.
// 0x1 Currently used to mark this histogram to be recorded by UMA..
// 0x8000 means print ranges in hex.
void SetFlags(int flags) { flags_ |= flags; }
void ClearFlags(int flags) { flags_ &= ~flags; }
int flags() const { return flags_; }
virtual BucketLayout histogram_type() const { return EXPONENTIAL; }
// Convenience methods for serializing/deserializing the histograms.
// Histograms from Renderer process are serialized and sent to the browser.
// Browser process reconstructs the histogram from the pickled version
// accumulates the browser-side shadow copy of histograms (that mirror
// histograms created in the renderer).
// Serialize the given snapshot of a Histogram into a String. Uses
// Pickle class to flatten the object.
static std::string SerializeHistogramInfo(const Histogram& histogram,
const SampleSet& snapshot);
// The following method accepts a list of pickled histograms and
// builds a histogram and updates shadow copy of histogram data in the
// browser process.
static bool DeserializeHistogramInfo(const std::string& histogram_info);
//----------------------------------------------------------------------------
// Accessors for serialization and testing.
//----------------------------------------------------------------------------
const std::string histogram_name() const { return histogram_name_; }
Sample declared_min() const { return declared_min_; }
Sample declared_max() const { return declared_max_; }
virtual Sample ranges(size_t i) const { return ranges_[i];}
virtual size_t bucket_count() const { return bucket_count_; }
// Snapshot the current complete set of sample data.
// Override with atomic/locked snapshot if needed.
virtual void SnapshotSample(SampleSet* sample) const;
// ...
}
看一下测试用例
// Check for basic syntax and use.
TEST(HistogramTest, StartupShutdownTest) {
// Try basic construction
Histogram histogram("TestHistogram", , , );
Histogram histogram1("Test1Histogram", , , ); LinearHistogram linear_histogram("TestLinearHistogram", , , );
LinearHistogram linear_histogram1("Test1LinearHistogram", , , ); // Use standard macros (but with fixed samples)
HISTOGRAM_TIMES("Test2Histogram", TimeDelta::FromDays());
HISTOGRAM_COUNTS("Test3Histogram", ); DHISTOGRAM_TIMES("Test4Histogram", TimeDelta::FromDays());
DHISTOGRAM_COUNTS("Test5Histogram", ); ASSET_HISTOGRAM_COUNTS("Test6Histogram", ); // Try to construct samples.
Histogram::SampleSet sample1;
Histogram::SampleSet sample2; // Use copy constructor of SampleSet
sample1 = sample2;
Histogram::SampleSet sample3(sample1); // Finally test a statistics recorder, without really using it.
StatisticsRecorder recorder;
}
看一下效果,浏览器地址栏输入:chrome://histograms/

chromium之histogram.h的更多相关文章
- chromium之MessagePump.h
上代码,注释已经写得很详细了. 粗看一下,这是个纯虚类,用于跨平台的通用接口. MessagePump,Pump的意思是泵,,MessagePump也就是消息泵,输送消息 namespace base ...
- chromium之MessageLoop浅析
对chromium的MessageLoop非常感兴趣,接下来会详细分析Windows平台的具体实现. 代码版本:chromium-4.0.210.0_p26329 先看一下依赖的文件 message_ ...
- 【Chromium中文文档】Chromium多进程架构
多进程架构 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//Start_Here_Background_Readin ...
- Chromium
Chromium多进程架构 多进程架构 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//Start_Here_Bac ...
- Histogram
folly/Histogram.h Classes Histogram Histogram.h defines a simple histogram class, templated on the t ...
- Word histogram
Here is a program that reads a file and builds a histogram of the words in the file: process_file lo ...
- 直方图均衡算法(Histogram Equalized)
Lab1: Histogram Equalization 1. 实验环境(C++) 操作系统版本 MacOS Catalina 10.15 OpenCV4.0 (imgcodecs | core | ...
- 根据直方图 histogram 进行简单的图像检索
https://github.com/TouwaErioH/Machine-Learning/tree/master/image%20identification/Histogram%20retrie ...
- Android编译环境折腾记
题记:感觉是时候写点什么了=_=! 第一次安装了ubuntu14.04.5,官网下载的iso,官网下的jar,编译android4.x需要安装jdk6,更高的版本会有问题,baidu到很多搭建环境的步 ...
随机推荐
- Linux基础之-Bash命令优先级
一. Bash简介 命令解释器,也就是 Bourne Again Shell,起源于shell.shell俗称壳,它是指UNIX系统下的一个命令解析器:主要用于用户和系统的交互.UNIX系统上有很多种 ...
- 05_zookeeper的ACL
[ACL概述] ACL:access control Lists,权限控制. * 针对节点可以设置相关的读写等权限,目的是为了保障数据安全性. * 权限permissions可以指定不同的权限范围以及 ...
- recommendation baselines
整理recommendation baseline 的实现代码和方法归类: bpr: https://github.com/gamboviol/bpr fpmc: https://github.c ...
- BEM,SASS,LESS,bootstrap:如何有效地将这些方法,工具和框架聪明地整合?
https://medium.com/@andersonorui_/bem-sass-and-bootstrap-9f89dc07d20f Bootstrap是一个“HTML,CSS和Javascri ...
- 【NLP汉语自然语言处理与实践】分词_笔记
一.两种分词标准: 1. 粗粒度. 将词作为最小基本单位.比如:浙江大学. 主要用于自然语言处理的各种应用. 2. 细粒度. 不仅对词汇继续切分,也对词汇内部的语素进行切分.比如:浙江/大学. 主要用 ...
- 页面引入(include)方式的研究及性能比较
1. 应用Html中的框架(iframe) 目前大多数门户网站都应用iframe来进行页面上广告的投放,就是将不同的广告分别应用iframe投放到主页面上,优点是效率高,互不影响,缺点是不符合网页标准 ...
- selenium+python 数据驱动-csv篇,可封装
#循环读取csv文件中的数据,可以作为用户名,密码等使用from selenium import webdriverimport csv#获取csv文件中password列with open(r'C: ...
- IntelliJ IDEA 2017.3-2018.1 全系列汉化包
JetBrains 系列软件汉化包 关键字: Android Studio 3.0-3.1 汉化包 GoLand 2017.3.2-2018.1 汉化包 IntelliJ IDEA 2017.3-20 ...
- SOJ 1002/1003/1004 大整数相加/相乘/相除
三个题目分别考察大整数相加相乘相除运算.如果按照传统算法是取一个长数组,之后进行模拟或者FFT来进行运算.但是相对繁琐. 后来昨天的青岛区域赛网赛1001,用到了JAVA的BigDecimal,于是反 ...
- Linux修改权限命令chmod用法详解
Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方式对文件和目录进行访问和操作. 文件或目录的访问权限分为只读,只写和可执行三种.以文件为例,只读权限表示只允许读其内容,而禁 ...