Add Disk IO gauge.
[ardour.git] / gtk2_ardour / disk_io_indicator.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #include "ardour_ui.h"
20 #include "disk_io_indicator.h"
21
22 #include "ardour/audioengine.h"
23
24 #include "pbd/i18n.h"
25
26 #define PADDING 3
27
28 DiskIoIndicator::DiskIoIndicator ()
29         : ArdourGauge ("00.0%")
30         , _disk_io (0)
31 {
32 }
33
34 void
35 DiskIoIndicator::set_disk_io (const double load)
36 {
37         if (load == _disk_io) {
38                 return;
39         }
40         _disk_io = load;
41
42         char buf[64];
43         snprintf (buf, sizeof (buf), "Dsk: %.1f%%", _disk_io);
44         update (std::string (buf));
45 }
46
47 float
48 DiskIoIndicator::level () const {
49         return (_disk_io / 100.f);
50 }
51
52 bool
53 DiskIoIndicator::alert () const
54 {
55         return false;
56 }
57
58 ArdourGauge::Status
59 DiskIoIndicator::indicator () const
60 {
61         if (_disk_io < 50) {
62                 return ArdourGauge::Level_CRIT;
63         } else if (_disk_io < 75) {
64                 return ArdourGauge::Level_WARN;
65         } else {
66                 return ArdourGauge::Level_OK;
67         }
68 }
69
70 std::string
71 DiskIoIndicator::tooltip_text ()
72 {
73         char buf[64];
74
75         snprintf (buf, sizeof (buf), _("Disk I/O cache: %.1f"), _disk_io);
76
77         return buf;
78 }