aboutsummaryrefslogtreecommitdiff
path: root/process/powerconsumer.cpp
blob: 53b8b847e1018c0922cb89dfc28bc58e36e70c9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright 2010, Intel Corporation
 *
 * This file is part of PowerTOP
 *
 * This program file is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program in a file named COPYING; if not, write to the
 * Free Software Foundation, Inc,
 * 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 * or just google for it.
 *
 * Authors:
 *	Arjan van de Ven <arjan@linux.intel.com>
 */

#include "powerconsumer.h"
#include "process.h"
#include "../parameters/parameters.h"

double power_consumer::Witts(void)
{
	double cost;
	double timecost;
	double wakeupcost;
	double gpucost;
	double disk_cost;
	double hard_disk_cost;

	if (child_runtime > accumulated_runtime)
		child_runtime = 0;

	timecost = get_parameter_value("cpu-consumption");
	wakeupcost = get_parameter_value("cpu-wakeups");
	gpucost = get_parameter_value("gpu-operations");
	disk_cost = get_parameter_value("disk-operations");
	hard_disk_cost = get_parameter_value("disk-operations-hard");

	cost = 0;

	cost += wakeupcost * wake_ups / 10000.0;
	cost += ( (accumulated_runtime - child_runtime) / 1000000000.0) * timecost;
	cost += gpucost * gpu_ops / 100.0;
	cost += hard_disk_cost * hard_disk_hits / 100.0;
	cost += disk_cost * disk_hits / 100.0;

	cost = cost / measurement_time;

	return cost;
}

power_consumer::power_consumer(void)
{
	accumulated_runtime = 0;
	child_runtime = 0;
	disk_hits = 0;
	wake_ups = 0;
	gpu_ops = 0;
	hard_disk_hits = 0;
	waker = NULL;
}

double power_consumer::usage(void) 
{ 
	double t;
	t = (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time;
	if (t < 0.7)
		t = t * 1000;
	return t; 
}

const char * power_consumer::usage_units(void)
{
	double t;
	t = (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time;
	if (t < 0.7)
		return " us/s";
//		return " µs";
	return " ms/s";
}