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翻譯
//直方圖是匯總統(tǒng)計(jì)信息的對(duì)象,可以將它們匯總 //各種形式,包括ASCII圖形,HTML和數(shù)字(如 //每個(gè)聚合桶對(duì)應(yīng)的數(shù)字向量)。?直方圖——不就是統(tǒng)計(jì)用的,PPT還有餅圖什么的
?
不管了,看看怎么實(shí)現(xiàn)的,就知道是干嘛用的了。
瞄一下,有沒有引用不認(rèn)識(shí)的頭文件
histogram.cc
#include "base/histogram.h"#include <math.h> #include <string>#include "base/logging.h" #include "base/pickle.h" #include "base/string_util.h"有一個(gè)!
#include "base/pickle.h"參見分析chromium之pickle,我們知道該類提供基本的二進(jìn)制打包、解包的功能。這樣代碼就能繼續(xù)看下去了
這個(gè)pickle在頭文件里有用到
bool Serialize(Pickle* pickle) const;bool Deserialize(void** iter, const Pickle& pickle);序列化一般是進(jìn)程間通訊傳遞數(shù)據(jù)用的
序列化在什么時(shí)候用:
當(dāng)你想把的內(nèi)存中的對(duì)象狀態(tài)保存到一個(gè)文件中或者數(shù)據(jù)庫中時(shí)候;
當(dāng)你想用套接字在網(wǎng)絡(luò)上傳送對(duì)象的時(shí)候;
當(dāng)你想通過RMI傳輸對(duì)象的時(shí)候;
?
一個(gè)類,有沒有掌握——給你頭文件,你會(huì)不會(huì)使用里面的函數(shù)——會(huì)了,這個(gè)類你就懂了。
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 constructionHistogram histogram("TestHistogram", 1, 1000, 10);Histogram histogram1("Test1Histogram", 1, 1000, 10);LinearHistogram linear_histogram("TestLinearHistogram", 1, 1000, 10);LinearHistogram linear_histogram1("Test1LinearHistogram", 1, 1000, 10);// Use standard macros (but with fixed samples)HISTOGRAM_TIMES("Test2Histogram", TimeDelta::FromDays(1));HISTOGRAM_COUNTS("Test3Histogram", 30);DHISTOGRAM_TIMES("Test4Histogram", TimeDelta::FromDays(1));DHISTOGRAM_COUNTS("Test5Histogram", 30);ASSET_HISTOGRAM_COUNTS("Test6Histogram", 129);// Try to construct samples. Histogram::SampleSet sample1;Histogram::SampleSet sample2;// Use copy constructor of SampleSetsample1 = sample2;Histogram::SampleSet sample3(sample1);// Finally test a statistics recorder, without really using it. StatisticsRecorder recorder; }?
看一下效果,瀏覽器地址欄輸入:chrome://histograms/
?
轉(zhuǎn)載于:https://www.cnblogs.com/ckelsel/p/9032599.html
總結(jié)
以上是生活随笔為你收集整理的chromium之histogram.h的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 不动产登记中心备案购房合同吗?
- 下一篇: 安卓手机录音格式怎么设置方法?