~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/cost_vector.h

  • Committer: Brian Aker
  • Date: 2010-02-14 01:56:51 UTC
  • mto: (1273.16.5 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: brian@gaz-20100214015651-ror9j0xu7dccz0ct
Two fixes for "make dist"

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#ifndef DRIZZLED_OPTIMIZER_COST_VECTOR_H
21
 
#define DRIZZLED_OPTIMIZER_COST_VECTOR_H
22
 
 
23
 
namespace drizzled
24
 
{
25
 
namespace optimizer
26
 
{
27
 
class CostVector
28
 
{
29
 
 
30
 
public:
31
 
  CostVector() :
32
 
    io_count(0.0),
33
 
    avg_io_cost(1.0),
34
 
    cpu_cost(0.0),
35
 
    mem_cost(0.0),
36
 
    import_cost(0.0)
37
 
  {}
38
 
 
39
 
  double total_cost()
40
 
  {
41
 
    return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
42
 
      MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
43
 
  }
44
 
 
45
 
  void zero()
46
 
  {
47
 
    avg_io_cost= 1.0;
48
 
    io_count= cpu_cost= mem_cost= import_cost= 0.0;
49
 
  }
50
 
 
51
 
  void multiply(double m)
52
 
  {
53
 
    io_count *= m;
54
 
    cpu_cost *= m;
55
 
    import_cost *= m;
56
 
    /* Don't multiply mem_cost */
57
 
  }
58
 
 
59
 
  void add(const CostVector* cost)
60
 
  {
61
 
    double io_count_sum= io_count + cost->io_count;
62
 
    add_io(cost->io_count, cost->avg_io_cost);
63
 
    io_count= io_count_sum;
64
 
    cpu_cost += cost->cpu_cost;
65
 
  }
66
 
  void add_io(double add_io_cnt, double add_avg_cost)
67
 
  {
68
 
    double io_count_sum= io_count + add_io_cnt;
69
 
    avg_io_cost= (io_count * avg_io_cost +
70
 
                  add_io_cnt * add_avg_cost) / io_count_sum;
71
 
    io_count= io_count_sum;
72
 
  }
73
 
 
74
 
  /* accessor methods*/
75
 
  void setIOCount(double m)
76
 
  {
77
 
     io_count= m;
78
 
  }
79
 
  double getIOCount() const 
80
 
  {
81
 
     return io_count;
82
 
  }
83
 
  void setAvgIOCost(double m)
84
 
  {
85
 
     avg_io_cost= m;
86
 
  }
87
 
  double getAvgIOCost() const 
88
 
  {
89
 
     return avg_io_cost;
90
 
  }
91
 
  void setCpuCost(double m)
92
 
  { 
93
 
     cpu_cost= m;
94
 
  }
95
 
  double getCpuCost() const
96
 
  {
97
 
     return cpu_cost;
98
 
  }
99
 
  void setMemCost(double m)
100
 
  { 
101
 
     mem_cost= m;
102
 
  }
103
 
  double getMemCost() const
104
 
  {
105
 
     return mem_cost;
106
 
  }
107
 
  void setImportCost(double m)
108
 
  {
109
 
     import_cost= m;
110
 
  }
111
 
  double getImportCost() const
112
 
  {
113
 
     return import_cost;
114
 
  }
115
 
 
116
 
private:
117
 
 
118
 
  double io_count;     /* number of I/O                 */
119
 
  double avg_io_cost;  /* cost of an average I/O oper.  */
120
 
  double cpu_cost;     /* cost of operations in CPU     */
121
 
  double mem_cost;     /* cost of used memory           */
122
 
  double import_cost;  /* cost of remote operations     */
123
 
 
124
 
  static const uint32_t IO_COEFF=1;
125
 
  static const uint32_t CPU_COEFF=1;
126
 
  static const uint32_t MEM_COEFF=1;
127
 
  static const uint32_t IMPORT_COEFF=1;
128
 
 
129
 
};
130
 
} /* namespace optimizer */
131
 
} /* namespace drizzled */
132
 
 
133
 
#endif /* DRIZZLED_OPTIMIZER_COST_VECTOR_H */