MCPcopy Create free account
hub / github.com/chenshuo/muduo / plotCpu

Method plotCpu

examples/procmon/plot.cc:35–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35muduo::string Plot::plotCpu(const std::vector<double>& data)
36{
37 gdImageFilledRectangle(image_, 0, 0, width_, height_, background_);
38 if (data.size() > 1)
39 {
40 gdImageSetThickness(image_, 2);
41 double max = *std::max_element(data.begin(), data.end());
42 if (max >= 10.0)
43 {
44 max = ceil(max);
45 }
46 else
47 {
48 max = std::max(0.1, ceil(max*10.0) / 10.0);
49 }
50 label(max);
51
52 for (size_t i = 0; i < data.size()-1; ++i)
53 {
54 gdImageLine(image_,
55 getX(i, data.size()),
56 getY(data[i] / max),
57 getX(i+1, data.size()),
58 getY(data[i+1]/max),
59 black_);
60 }
61 }
62
63 int total = totalSeconds_/samplingPeriod_;
64 gdImageSetThickness(image_, 1);
65 gdImageLine(image_, getX(0, total), getY(0)+2, getX(total, total), getY(0)+2, gray_);
66 gdImageLine(image_, getX(total, total), getY(0)+2, getX(total, total), getY(1)+2, gray_);
67 return toPng();
68}
69
70void Plot::label(double maxValue)
71{

Callers 2

onRequestMethod · 0.80
mainFunction · 0.80

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

mainFunction · 0.64