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/

最新文章

  1. xcode6 beta 中智能提示(自动完成)功能有时不显示的问题
  2. String Mybatis 多数据源配置
  3. 【Oracle】Oracle时间日期格式
  4. jQuery form插件的使用--用 formData 参数校验表单,验证后提交(简单验证).
  5. &lt;实训|第四天&gt;Linux下的vim你真的掌握了吗?附上ftp远程命令上传。
  6. c++继承中的内存布局
  7. JSON-JObject
  8. 使用hibernate tools插件生成POJO
  9. centos 安装php ide (eclipse + php 插件)
  10. PHP开发利器zend studio常见问题解答
  11. 使用gitbook
  12. Halcon一日一练:创建三通道图像
  13. C#的扩展方法简介
  14. 学习React系列(四)——受控组件与非受控组件
  15. Android Studio 更新同步Gradle错误解决方法
  16. [Asp.net core]bootstrap分页
  17. 页面弹出全屏浮层或遮罩时,禁止底层body滚动
  18. 9-sort使用时的错误
  19. BNU 26480 Horror List【最短路】
  20. [算法][LeetCode]Single Number——异或运算的巧妙运用

热门文章

  1. 006服务监控看板Hystrix Dashboard
  2. How to solve problems
  3. ubuntu下root不能复制 abc用户下的软连接文件
  4. Ubuntu14.04下如何安装Python爬虫框架Scrapy
  5. Linux 虚拟机的计划维护
  6. 微软Azure虚拟机备份服务在中国发布
  7. mongodb数据库备份恢复-windows系统
  8. java操作svn【svnkit】实操
  9. window搭建svn服务器,本地提交至服务器后,直接同步
  10. Lovable eccentric