[1194] | 1 | /*
|
---|
| 2 | root -l examples/MemoryUsage.C\(\"ps_output.txt\"\)
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | #include "Riostream.h"
|
---|
| 6 |
|
---|
| 7 | static const Font_t kExRootFont = 42;
|
---|
| 8 | static const Float_t kExRootFontSize = 0.04;
|
---|
| 9 | static const Color_t kExRootBackgroundColor = 10;
|
---|
| 10 |
|
---|
| 11 | //------------------------------------------------------------------------------
|
---|
| 12 |
|
---|
| 13 | TGraph grvsz, grrss;
|
---|
[1205] | 14 | TLegend legend(0.41, 0.59, 0.77, 0.68);
|
---|
[1194] | 15 |
|
---|
[1197] | 16 | TCanvas *canvas;
|
---|
| 17 |
|
---|
[1194] | 18 | //------------------------------------------------------------------------------
|
---|
| 19 |
|
---|
| 20 | void MemoryUsage(const char *inputFile)
|
---|
| 21 | {
|
---|
| 22 | Int_t i, vsz, rss;
|
---|
| 23 | ifstream in;
|
---|
| 24 |
|
---|
| 25 | TDirectory *currentDirectory = gDirectory;
|
---|
| 26 |
|
---|
| 27 | // Graphics style parameters to avoid grey background on figures
|
---|
| 28 | gStyle->SetCanvasColor(kExRootBackgroundColor);
|
---|
| 29 | gStyle->SetStatColor(kExRootBackgroundColor);
|
---|
| 30 | // gStyle->SetTitleColor(kExRootBackgroundColor);
|
---|
| 31 | gStyle->SetPadColor(kExRootBackgroundColor);
|
---|
| 32 |
|
---|
| 33 | gStyle->SetPadTopMargin(0.10);
|
---|
| 34 | gStyle->SetPadRightMargin(0.10);
|
---|
| 35 | gStyle->SetPadBottomMargin(0.15);
|
---|
| 36 | gStyle->SetPadLeftMargin(0.15);
|
---|
| 37 |
|
---|
| 38 | gStyle->SetStatFont(kExRootFont);
|
---|
| 39 | gStyle->SetStatFontSize(kExRootFontSize);
|
---|
| 40 |
|
---|
| 41 | gStyle->SetTitleFont(kExRootFont, "");
|
---|
| 42 | gStyle->SetTitleFont(kExRootFont, "X");
|
---|
| 43 | gStyle->SetTitleFont(kExRootFont, "Y");
|
---|
| 44 | gStyle->SetTitleFont(kExRootFont, "Z");
|
---|
| 45 | gStyle->SetTitleSize(kExRootFontSize, "");
|
---|
| 46 | gStyle->SetTitleSize(kExRootFontSize, "X");
|
---|
| 47 | gStyle->SetTitleSize(kExRootFontSize, "Y");
|
---|
| 48 | gStyle->SetTitleSize(kExRootFontSize, "Z");
|
---|
| 49 |
|
---|
| 50 | gStyle->SetLabelFont(kExRootFont, "X");
|
---|
| 51 | gStyle->SetLabelFont(kExRootFont, "Y");
|
---|
| 52 | gStyle->SetLabelFont(kExRootFont, "Z");
|
---|
| 53 | gStyle->SetLabelSize(kExRootFontSize, "X");
|
---|
| 54 | gStyle->SetLabelSize(kExRootFontSize, "Y");
|
---|
| 55 | gStyle->SetLabelSize(kExRootFontSize, "Z");
|
---|
| 56 |
|
---|
| 57 | gStyle->SetPadTickX(1);
|
---|
| 58 | gStyle->SetPadTickY(1);
|
---|
| 59 |
|
---|
| 60 | gStyle->SetTextFont(kExRootFont);
|
---|
| 61 | gStyle->SetTextSize(kExRootFontSize);
|
---|
| 62 |
|
---|
| 63 | gStyle->SetOptStat(111110);
|
---|
| 64 | // gStyle->SetOptFit(101);
|
---|
| 65 |
|
---|
| 66 | canvas = static_cast<TCanvas*>(gROOT->FindObject("c1"));
|
---|
| 67 | if(canvas)
|
---|
| 68 | {
|
---|
| 69 | canvas->Clear();
|
---|
| 70 | canvas->UseCurrentStyle();
|
---|
| 71 | canvas->SetWindowSize(800, 650);
|
---|
| 72 | }
|
---|
| 73 | else
|
---|
| 74 | {
|
---|
| 75 | canvas = new TCanvas("c1", "c1", 800, 650);
|
---|
| 76 | }
|
---|
[1197] | 77 | canvas->SetGrid();
|
---|
[1194] | 78 | canvas->SetHighLightColor(kExRootBackgroundColor);
|
---|
| 79 |
|
---|
| 80 | currentDirectory->cd();
|
---|
| 81 |
|
---|
| 82 | grvsz.SetPoint(1, 0.0, 0.0);
|
---|
| 83 | grrss.SetPoint(1, 0.0, 0.0);
|
---|
| 84 |
|
---|
| 85 | in.open(inputFile);
|
---|
| 86 | i = 2;
|
---|
| 87 | while(1)
|
---|
| 88 | {
|
---|
| 89 | in >> vsz >> rss;
|
---|
| 90 | if(!in.good()) break;
|
---|
[1205] | 91 | grvsz.SetPoint(i, (i-1)*0.1, vsz/1024.0);
|
---|
| 92 | grrss.SetPoint(i, (i-1)*0.1, rss/1024.0);
|
---|
[1194] | 93 | ++i;
|
---|
| 94 | }
|
---|
[1205] | 95 | grvsz.SetPoint(i, (i-1)*0.1, 0.0);
|
---|
| 96 | grrss.SetPoint(i, (i-1)*0.1, 0.0);
|
---|
[1194] | 97 |
|
---|
| 98 | grvsz.GetXaxis()->SetLimits(0, 30);
|
---|
| 99 | grvsz.GetXaxis()->SetTitleOffset(1.5);
|
---|
| 100 | grvsz.GetYaxis()->SetTitleOffset(1.75);
|
---|
| 101 | grvsz.GetXaxis()->SetTitle("time, s");
|
---|
[1205] | 102 | grvsz.GetYaxis()->SetTitle("memory usage, MB");
|
---|
| 103 | grvsz.SetLineColor(16);
|
---|
[1202] | 104 | grrss.SetLineColor(kBlack);
|
---|
[1205] | 105 | grvsz.SetLineStyle(kSolid);
|
---|
[1202] | 106 | grrss.SetLineStyle(kSolid);
|
---|
| 107 | grvsz.SetLineWidth(3);
|
---|
| 108 | grrss.SetLineWidth(3);
|
---|
[1194] | 109 | grvsz.Draw("AL");
|
---|
| 110 | grrss.Draw("L");
|
---|
[1197] | 111 |
|
---|
| 112 | legend.SetTextSize(kExRootFontSize);
|
---|
| 113 | legend.SetTextFont(kExRootFont);
|
---|
| 114 | legend.SetFillColor(kExRootBackgroundColor);
|
---|
| 115 | legend.SetBorderSize(0);
|
---|
[1202] | 116 | legend.AddEntry(&grvsz, "virtual memory", "l");
|
---|
| 117 | legend.AddEntry(&grrss, "physical memory", "l");
|
---|
[1197] | 118 | legend.Draw();
|
---|
[1194] | 119 | }
|
---|
| 120 |
|
---|