Drizzled Public API Documentation

cost_vector.h

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 namespace drizzled
00023 {
00024 namespace optimizer
00025 {
00026 class CostVector
00027 {
00028 
00029 public:
00030   CostVector() :
00031     io_count(0.0),
00032     avg_io_cost(1.0),
00033     cpu_cost(0.0),
00034     mem_cost(0.0),
00035     import_cost(0.0)
00036   {}
00037 
00038   double total_cost()
00039   {
00040     return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
00041       MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
00042   }
00043 
00044   void zero()
00045   {
00046     avg_io_cost= 1.0;
00047     io_count= cpu_cost= mem_cost= import_cost= 0.0;
00048   }
00049 
00050   void multiply(double m)
00051   {
00052     io_count *= m;
00053     cpu_cost *= m;
00054     import_cost *= m;
00055     /* Don't multiply mem_cost */
00056   }
00057 
00058   void add(const CostVector* cost)
00059   {
00060     double io_count_sum= io_count + cost->io_count;
00061     add_io(cost->io_count, cost->avg_io_cost);
00062     io_count= io_count_sum;
00063     cpu_cost += cost->cpu_cost;
00064   }
00065   void add_io(double add_io_cnt, double add_avg_cost)
00066   {
00067     double io_count_sum= io_count + add_io_cnt;
00068     avg_io_cost= (io_count * avg_io_cost +
00069                   add_io_cnt * add_avg_cost) / io_count_sum;
00070     io_count= io_count_sum;
00071   }
00072 
00073   /* accessor methods*/
00074   void setIOCount(double m)
00075   {
00076      io_count= m;
00077   }
00078   double getIOCount() const 
00079   {
00080      return io_count;
00081   }
00082   void setAvgIOCost(double m)
00083   {
00084      avg_io_cost= m;
00085   }
00086   double getAvgIOCost() const 
00087   {
00088      return avg_io_cost;
00089   }
00090   void setCpuCost(double m)
00091   { 
00092      cpu_cost= m;
00093   }
00094   double getCpuCost() const
00095   {
00096      return cpu_cost;
00097   }
00098   void setMemCost(double m)
00099   { 
00100      mem_cost= m;
00101   }
00102   double getMemCost() const
00103   {
00104      return mem_cost;
00105   }
00106   void setImportCost(double m)
00107   {
00108      import_cost= m;
00109   }
00110   double getImportCost() const
00111   {
00112      return import_cost;
00113   }
00114 
00115 private:
00116 
00117   double io_count;     /* number of I/O                 */
00118   double avg_io_cost;  /* cost of an average I/O oper.  */
00119   double cpu_cost;     /* cost of operations in CPU     */
00120   double mem_cost;     /* cost of used memory           */
00121   double import_cost;  /* cost of remote operations     */
00122 
00123   static const uint32_t IO_COEFF=1;
00124   static const uint32_t CPU_COEFF=1;
00125   static const uint32_t MEM_COEFF=1;
00126   static const uint32_t IMPORT_COEFF=1;
00127 
00128 };
00129 } /* namespace optimizer */
00130 } /* namespace drizzled */
00131