]> granicus.if.org Git - pdns/commitdiff
fix up 4.4 billion query statistics wraparound. And congratulations to the people...
authorBert Hubert <bert.hubert@netherlabs.nl>
Mon, 14 Feb 2011 15:34:32 +0000 (15:34 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Mon, 14 Feb 2011 15:34:32 +0000 (15:34 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2019 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/statbag.cc
pdns/statbag.hh
pdns/ws.cc

index 39e6303630d71a18cfcd787d984fa071ba3c70b6..fbda4291a03d58e1ce2a907795a839aa032ffb0b 100644 (file)
@@ -96,7 +96,7 @@ void StatBag::declare(const string &key, const string &descrip)
 
 
           
-void StatBag::set(const string &key, int value)
+void StatBag::set(const string &key, unsigned int value)
 {
   lock();
   exists(key);
@@ -105,7 +105,7 @@ void StatBag::set(const string &key, int value)
   unlock();
 }
 
-int StatBag::read(const string &key)
+unsigned int StatBag::read(const string &key)
 {
   lock();
 
@@ -115,14 +115,13 @@ int StatBag::read(const string &key)
       return 0;
     }
 
-  int tmp=*d_stats[key];
+  unsigned int tmp=*d_stats[key];
 
   unlock();
   return tmp;
-
 }
 
-int StatBag::readZero(const string &key)
+unsigned int StatBag::readZero(const string &key)
 {
   lock();
 
@@ -134,7 +133,7 @@ int StatBag::readZero(const string &key)
     }
 
   
-  int tmp=*d_stats[key];
+  unsigned int tmp=*d_stats[key];
   d_stats[key]=0;
 
   unlock();
@@ -174,7 +173,7 @@ StatBag::~StatBag()
   
 }
 
-StatRing::StatRing(int size)
+StatRing::StatRing(unsigned int size)
 {
   d_size=size;
   d_items.resize(d_size);
@@ -184,7 +183,7 @@ StatRing::StatRing(int size)
   pthread_mutex_init(d_lock, 0);
 }
 
-void StatRing::resize(int newsize)
+void StatRing::resize(unsigned int newsize)
 {
   if(d_size==newsize)
     return;
@@ -200,7 +199,7 @@ void StatRing::resize(int newsize)
   int startpos=d_pos-newsize;
   int rpos;
   vector<string>newring;
-  for(int i=startpos;i<d_pos;++i) {
+  for(unsigned int i=startpos;i<d_pos;++i) {
     rpos=i>=0 ? i : i+d_size;
 
     newring.push_back(d_items[rpos%d_size]);
@@ -230,17 +229,17 @@ static bool popisort(const pair<string,int> &a, const pair<string,int> &b)
   return (a.second > b.second);
 }
 
-vector<pair<string,int> >StatRing::get() const
+vector<pair<string,unsigned int> >StatRing::get() const
 {
   Lock l(d_lock);
-  map<string,int> res;
+  map<string,unsigned int> res;
   for(vector<string>::const_iterator i=d_items.begin();i!=d_items.end();++i) {
     if(!i->empty())
       res[*i]++;
   }
   
-  vector<pair<string,int> > tmp;
-  for(map<string,int>::const_iterator i=res.begin();i!=res.end();++i) 
+  vector<pair<string,unsigned int> > tmp;
+  for(map<string,unsigned int>::const_iterator i=res.begin();i!=res.end();++i) 
     tmp.push_back(*i);
 
   sort(tmp.begin(),tmp.end(),popisort);
@@ -254,7 +253,7 @@ void StatBag::declareRing(const string &name, const string &help, unsigned int s
   d_rings[name].setHelp(help);
 }
 
-vector<pair<string,int> > StatBag::getRing(const string &name)
+vector<pair<string, unsigned int> > StatBag::getRing(const string &name)
 {
   return d_rings[name].get();
 }
@@ -273,13 +272,13 @@ void StatBag::resetRing(const string &name)
   d_rings[name].reset();
 }
 
-void StatBag::resizeRing(const string &name, int newsize)
+void StatBag::resizeRing(const string &name, unsigned int newsize)
 {
   d_rings[name].resize(newsize);
 }
 
 
-int StatBag::getRingSize(const string &name)
+unsigned int StatBag::getRingSize(const string &name)
 {
   return d_rings[name].getSize();
 }
index 37d8bfe1734fdcfc5ce77bc5bb0e842a6f848cd5..2e9194378b7e3c03060a19c01c4a628611cc52aa 100644 (file)
@@ -28,7 +28,7 @@
 class StatRing
 {
 public:
-  StatRing(int size=10000);
+  StatRing(unsigned int size=10000);
   ~StatRing();
   void account(const string &item)
   {
@@ -37,19 +37,19 @@ public:
   }
 
 
-  int getSize()
+  unsigned int getSize()
   {
     return d_size;
   }
-  void resize(int newsize);  
+  void resize(unsigned int newsize);  
   void reset();
   void setHelp(const string &str);
   string getHelp();
-  vector<pair<string,int> >get() const;
+  vector<pair<string,unsigned int> >get() const;
 private:
-  int d_size;
-  int d_pos;
-  vector<string>d_items;
+  unsigned int d_size;
+  unsigned int d_pos;
+  vector<string> d_items;
   pthread_mutex_t *d_lock;
   string d_help;
 };
@@ -70,7 +70,7 @@ public:
   void declare(const string &key, const string &descrip=""); //!< Before you can store or access a key, you need to declare it
 
   void declareRing(const string &name, const string &title, unsigned int size=10000);
-  vector<pair<string,int> >getRing(const string &name);
+  vector<pair<string, unsigned int> >getRing(const string &name);
   string getRingTitle(const string &name);
   void ringAccount(const string &name, const string &item)
   {
@@ -84,8 +84,8 @@ public:
 
   vector<string>listRings();
   void resetRing(const string &name);
-  void resizeRing(const string &name, int newsize);
-  int getRingSize(const string &name);
+  void resizeRing(const string &name, unsigned int newsize);
+  unsigned int getRingSize(const string &name);
 
   string directory(); //!< Returns a list of all data stored
   vector<string> getEntries(); //!< returns a vector with datums (items)
@@ -93,9 +93,9 @@ public:
   void exists(const string &key); //!< call this function to throw an exception in case a key does not exist
   inline void deposit(const string &key, int value); //!< increment the statistics behind this key by value amount
   inline void inc(const string &key); //!< increase this key's value by one
-  void set(const string &key, int value); //!< set this key's value
-  int read(const string &key); //!< read the value behind this key
-  int readZero(const string &key); //!< read the value behind this key, and zero it afterwards
+  void set(const string &key, unsigned int value); //!< set this key's value
+  unsigned int read(const string &key); //!< read the value behind this key
+  unsigned int readZero(const string &key); //!< read the value behind this key, and zero it afterwards
   unsigned int *getPointer(const string &key); //!< get a direct pointer to the value behind a key. Use this for high performance increments
   string getValueStr(const string &key); //!< read a value behind a key, and return it as a string
   string getValueStrZero(const string &key); //!< read a value behind a key, and return it as a string, and zero afterwards
index b88f532bef94c34bc459c9a7f6a01838d62eeb46..f52047e994790fd9f69ea975f69b605b27ea6ace 100644 (file)
@@ -77,9 +77,9 @@ void printtable(ostringstream &ret, const string &ringname, const string &title,
 {
   int tot=0;
   int entries=0;
-  vector<pair <string,int> >ring=S.getRing(ringname);
+  vector<pair <string,unsigned int> >ring=S.getRing(ringname);
 
-  for(vector<pair<string,int> >::const_iterator i=ring.begin(); i!=ring.end();++i) {  
+  for(vector<pair<string, unsigned int> >::const_iterator i=ring.begin(); i!=ring.end();++i) {  
     tot+=i->second;
     entries++;
   }
@@ -93,7 +93,7 @@ void printtable(ostringstream &ret, const string &ringname, const string &title,
     "<a href=?resetring="<<ringname<<"><font color=#ffffff>Reset</a></td>";
   ret<<"<td align=right>Resize: ";
   
-  int sizes[]={10,100,500,1000,10000,500000,0};
+  unsigned int sizes[]={10,100,500,1000,10000,500000,0};
   for(int i=0;sizes[i];++i) {
     if(S.getRingSize(ringname)!=sizes[i])
       ret<<"<a href=?resizering="<<ringname<<"&size="<<sizes[i]<<">"<<sizes[i]<<"</a> ";
@@ -104,7 +104,7 @@ void printtable(ostringstream &ret, const string &ringname, const string &title,
 
 
   int printed=0;
-  for(vector<pair<string,int> >::const_iterator i=ring.begin();limit && i!=ring.end();++i,--limit) {
+  for(vector<pair<string,unsigned int> >::const_iterator i=ring.begin();limit && i!=ring.end();++i,--limit) {
     ret<<"<tr><td>"<<i->first<<"</td><td>"<<i->second<<"</td><td align=right>"<< StatWebServer::makePercentage(i->second*100.0/tot)<<"</td>"<<endl;
     printed+=i->second;
   }