~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cost_vect.h

  • Committer: Stewart Smith
  • Date: 2010-02-05 01:20:18 UTC
  • mto: (1286.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1287.
  • Revision ID: stewart@flamingspork.com-20100205012018-blvmeky20wze8eyg
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :(

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_COST_VECT_H
 
21
#define DRIZZLED_COST_VECT_H
 
22
 
 
23
#include <stdint.h>
 
24
 
 
25
class COST_VECT
 
26
{
 
27
public:
 
28
  double io_count;     /* number of I/O                 */
 
29
  double avg_io_cost;  /* cost of an average I/O oper.  */
 
30
  double cpu_cost;     /* cost of operations in CPU     */
 
31
  double mem_cost;     /* cost of used memory           */
 
32
  double import_cost;  /* cost of remote operations     */
 
33
 
 
34
  static const uint32_t IO_COEFF=1;
 
35
  static const uint32_t CPU_COEFF=1;
 
36
  static const uint32_t MEM_COEFF=1;
 
37
  static const uint32_t IMPORT_COEFF=1;
 
38
 
 
39
  COST_VECT() :
 
40
    io_count(0.0),
 
41
    avg_io_cost(1.0),
 
42
    cpu_cost(0.0),
 
43
    mem_cost(0.0),
 
44
    import_cost(0.0)
 
45
  {}
 
46
 
 
47
  double total_cost()
 
48
  {
 
49
    return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
 
50
      MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
 
51
  }
 
52
 
 
53
  void zero()
 
54
  {
 
55
    avg_io_cost= 1.0;
 
56
    io_count= cpu_cost= mem_cost= import_cost= 0.0;
 
57
  }
 
58
 
 
59
  void multiply(double m)
 
60
  {
 
61
    io_count *= m;
 
62
    cpu_cost *= m;
 
63
    import_cost *= m;
 
64
    /* Don't multiply mem_cost */
 
65
  }
 
66
 
 
67
  void add(const COST_VECT* cost)
 
68
  {
 
69
    double io_count_sum= io_count + cost->io_count;
 
70
    add_io(cost->io_count, cost->avg_io_cost);
 
71
    io_count= io_count_sum;
 
72
    cpu_cost += cost->cpu_cost;
 
73
  }
 
74
  void add_io(double add_io_cnt, double add_avg_cost)
 
75
  {
 
76
    double io_count_sum= io_count + add_io_cnt;
 
77
    avg_io_cost= (io_count * avg_io_cost +
 
78
                  add_io_cnt * add_avg_cost) / io_count_sum;
 
79
    io_count= io_count_sum;
 
80
  }
 
81
};
 
82
 
 
83
#endif /* DRIZZLED_COST_VECT_H */