1# -- perl -- 2 3# RRD::Format: constants useful when digging around in an RRD file 4# from Perl 5# 6# Copyright (C) 1998 Jeff R. Allen and WebTV Networks, Inc. 7# 8# This program is free software; you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation; either version 2 of the License, or 11# (at your option) any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program; if not, write to the Free Software 20# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 22# PORTING: 23# 24# Because RRD datafiles are defined in terms of C structures, 25# different C compilers will pad them differently. Thus, this 26# file needs to be updated to understand the various file 27# layouts. To add support for an unsupported architecture, 28# add a section to setArch that matches your architecture. 29 30# The simple C program getFormat.c (which is in the util directory) 31# can probably be trusted to find the correct format strings 32# for your architecture. Instructions on how to use it are in 33# the comments at the beginning of the program. 34# Please send patches in, as you find 35# formats for your specific architecture. 36 37package RRD::Format; 38require Exporter; 39 40@ISA = qw(Exporter); 41@EXPORT = qw(sizeof); 42 43sub new { 44 my($class) = @_; 45 my($self) = {}; 46 bless($self, $class); 47 return $self; 48} 49 50sub format { 51 my($self, $fmt) = @_; 52 return $self->{$fmt}; 53} 54 55sub isOld { 56 my($str) = @_; 57 return ($str eq "mrtg"); 58} 59 60sub setArch { 61 my($self, $archname) = @_; 62 63 $self->{'cookie'} = "RRD"; 64 $self->{'float_cookie'} = 8.642135e130; 65 66 $self->{'DST_COUNTER'} = 0; 67 $self->{'DST_ABSOLUTE'} = 1; 68 $self->{'DST_GAUGE'} = 2; 69 $self->{'DST_DERIVE'} = 3; 70 71 $self->{'CF_AVERAGE'} = 0; 72 $self->{'CF_MINIMUM'} = 1; 73 $self->{'CF_MAXIMUM'} = 2; 74 # new cf functions 75 $self->{'CF_LAST'} = 3; 76 $self->{'CF_HWPREDICT'} = 4; 77 $self->{'CF_SEASONAL'} = 5; 78 $self->{'CF_DEVPREDICT'} = 6; 79 $self->{'CF_DEVSEASONAL'} = 7; 80 $self->{'CF_FAILURES'} = 8; 81 82 $self->{'LAST_DS_LEN'} = 30; # Tobias says, "DO NOT CHANGE THIS" :) 83 84 $archname =~ s/-multi-thread//g; 85 $archname =~ s/-thread-multi//g; 86 $archname =~ s/-thread//g; 87 88 if ($archname eq "sun4-solaris" || 89 $archname eq "MSWin32-x86" || $archname eq "MSWin32-x86-object" || 90 $archname eq "irix-o32" || $archname eq "sparc-linux") { 91 92 $self->{'newOld'} = "A4"; 93 $self->{'statHead'} = "a4 a5 x7 d L L L x4 x80"; 94 $self->{'dsDef'} = "a20 a20 L x4 d d x56"; 95 $self->{'rraDef'} = "a20 L L x4 d x72"; 96 $self->{'pdpDef'} = "a30 x2 L x4 d x64"; 97 $self->{'cdpDef'} = "d L x4 x64"; 98 99 $self->{'liveHead'} = "L"; 100 $self->{'liveHead3'} = "L L"; 101 $self->{'rraPtr'} = "L"; 102 $self->{'element'} = "d"; 103 104 return 1; 105 106 } elsif ($archname =~ /^aix|i.?86/i) { 107 # Matija.Grabnar@arnes.si says that these formats 108 # work for Solaris x86 too. And Patrick Myers <pjm@mcc.ac.uk> 109 # says it works for i386-freebsd. Cool. And John Banner 110 # <jbanner@UVic.Ca> says it works on AIX. And Dave Mangot 111 # <dave@epylon.com> says it works on i386-openbsd. Peter Evans 112 # <peter@gol.com> found a bug with Solaris 8/x86 which has been 113 # fixed. 114 115 # So, let's simplify and just say, 'if it has i.86 in the name, 116 # use this format. 117 118 $self->{'newOld'} = "A4"; 119 $self->{'statHead'} = "a4 a5 x3 d L L L x80"; 120 $self->{'dsDef'} = "a20 a20 L x4 d d x56"; 121 $self->{'rraDef'} = "a20 L L d x72"; 122 $self->{'pdpDef'} = "a30 x2 L x4 d x64"; 123 $self->{"liveHead3"} = "L L"; 124 $self->{'cdpDef'} = "d L x4 x64"; 125 126 $self->{'liveHead'} = "L"; 127 $self->{'rraPtr'} = "L"; 128 $self->{'element'} = "d"; 129 130 return 1; 131 } elsif ($archname eq 'amd64-freebsd') { 132 133 $self->{'statHead'} = "a4 a5 x7 d Q Q Q x80"; 134 $self->{'dsDef'} = "a20 a20 Q d d x56"; 135 $self->{'rraDef'} = "a20 x4 Q Q d x72"; 136 $self->{'pdpDef'} = "a30 x2 Q d x64"; 137 $self->{'cdpDef'} = "d Q x64"; 138 $self->{'liveHead'} = "Q"; 139 $self->{'rraPtr'} = "Q"; 140 $self->{'element'} = "d"; 141 $self->{'liveHead3'} = "Q Q"; 142 143 return 1; 144 } elsif ( $archname eq 'alpha-dec_osf') { 145 # Thanks to Melissa D. Binde <binde@amazon.com> for 146 # finding this (and a major foobar in getFormat.c) 147 148 $self->{'statHead'} = "a4 a5 x7 d L L L x80"; 149 $self->{'dsDef'} = "a20 a20 L d d x56"; 150 $self->{'rraDef'} = "a20 L L d x72"; 151 $self->{'pdpDef'} = "a30 x2 L d x64"; 152 $self->{'cdpDef'} = "d L x64"; 153 154 $self->{'liveHead'} = "L"; 155 $self->{'rraPtr'} = "L"; 156 $self->{'element'} = "d"; 157 158 } elsif ( $archname =~ 'PA-RISC' or $archname eq 'powerpc-linux') { 159 $self->{'statHead'} = "a4 a5 x7 d L L L x4 x80"; 160 $self->{'dsDef'} = "a20 a20 L x4 d d x56"; 161 $self->{'rraDef'} = "a20 L L x4 d x72"; 162 $self->{'pdpDef'} = "a30 x2 L x4 d x64"; 163 $self->{'cdpDef'} = "d L x4 x64"; 164 $self->{'liveHead'} = "L"; 165 $self->{'rraPtr'} = "L"; 166 $self->{'element'} = "d"; 167 } elsif ( $archname eq 'alpha-linux' ) { 168 $self->{'statHead'} = "a4 a5 x7 d Q Q Q x80"; 169 $self->{'dsDef'} = "a20 a20 Q d d x56"; 170 $self->{'rraDef'} = "a20 x4 Q Q d x72"; 171 $self->{'pdpDef'} = "a30 x2 Q d x64"; 172 $self->{'cdpDef'} = "d Q x64"; 173 $self->{'liveHead'} = "Q"; 174 $self->{'rraPtr'} = "Q"; 175 $self->{'element'} = "d"; 176 } elsif ( $archname eq 'sparc64-netbsd' ) { 177 $self->{'statHead'} = "a4 a5 x7 d Q Q Q x80"; 178 $self->{'dsDef'} = "a20 a20 Q d d x56"; 179 $self->{'rraDef'} = "a20 x4 Q Q d x72"; 180 $self->{'pdpDef'} = "a30 x2 Q d x64"; 181 $self->{'cdpDef'} = "d Q x64"; 182 $self->{'liveHead'} = "L"; 183 $self->{'rraPtr'} = "Q"; 184 $self->{'element'} = "d"; 185 } elsif ( $archname eq 's390x-linux' ) { 186 $self->{'statHead'} = "a4 a5 x7 d Q Q Q x80"; 187 $self->{'dsDef'} = "a20 a20 Q d d x56"; 188 $self->{'rraDef'} = "a20 x4 Q Q d x72"; 189 $self->{'pdpDef'} = "a30 x2 Q d x64"; 190 $self->{'cdpDef'} = "d Q x64"; 191 $self->{'liveHead'} = "Q"; 192 $self->{'rraPtr'} = "Q"; 193 $self->{'element'} = "d"; 194 } else { 195 return; 196 } 197} 198 199# a utility subroutine to imitate C's sizeof() built-in 200sub sizeof { 201 my($template) = @_; 202 return (length(pack($template))); 203} 204 2051; 206 207# Local Variables: 208# mode: perl 209# indent-tabs-mode: nil 210# tab-width: 4 211# perl-indent-level: 4 212# End: 213