File: Format.pm

package info (click to toggle)
cricket 1.0.5-23
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,940 kB
  • sloc: perl: 8,276; ansic: 329; sh: 162; makefile: 60; sql: 16
file content (209 lines) | stat: -rw-r--r-- 7,009 bytes parent folder | download | duplicates (5)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# -- perl --

# RRD::Format: constants useful when digging around in an RRD file
# from Perl
#
#    Copyright (C) 1998 Jeff R. Allen and WebTV Networks, Inc.
#
#    This program 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; either version 2 of the License, or
#    (at your option) any later version.
#
#    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; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# PORTING:
#
# Because RRD datafiles are defined in terms of C structures,
# different C compilers will pad them differently. Thus, this
# file needs to be updated to understand the various file
# layouts. To add support for an unsupported architecture,
# add a section to setArch that matches your architecture.

# The simple C program getFormat.c (which is in the util directory)
# can probably be trusted to find the correct format strings
# for your architecture. Instructions on how to use it are in
# the comments at the beginning of the program.
# Please send patches in, as you find
# formats for your specific architecture.

package RRD::Format;
require Exporter;

@ISA    = qw(Exporter);
@EXPORT = qw(sizeof);

sub new {
    my($class) = @_;
    my($self) = {};
    bless($self, $class);
    return $self;
}

sub format {
    my($self, $fmt) = @_;
    return $self->{$fmt};
}

sub isOld {
    my($str) = @_;
    return ($str eq "mrtg");
}

sub setArch {
    my($self, $archname) = @_;

    $self->{'cookie'}       = "RRD";
    $self->{'float_cookie'} = 8.642135e130;

    $self->{'DST_COUNTER'}  = 0;
    $self->{'DST_ABSOLUTE'} = 1;
    $self->{'DST_GAUGE'}    = 2;
    $self->{'DST_DERIVE'}   = 3;

    $self->{'CF_AVERAGE'} = 0;
    $self->{'CF_MINIMUM'} = 1;
    $self->{'CF_MAXIMUM'} = 2;
    # new cf functions
    $self->{'CF_LAST'} = 3;
    $self->{'CF_HWPREDICT'} = 4;
    $self->{'CF_SEASONAL'} = 5;
    $self->{'CF_DEVPREDICT'} = 6;
    $self->{'CF_DEVSEASONAL'} = 7;
    $self->{'CF_FAILURES'} = 8;

    $self->{'LAST_DS_LEN'} = 30;    # Tobias says, "DO NOT CHANGE THIS" :)

    $archname =~ s/-multi-thread//g;
    $archname =~ s/-thread-multi//g;
    $archname =~ s/-thread//g;

    if ($archname eq "sun4-solaris" ||
         $archname eq "MSWin32-x86" || $archname eq "MSWin32-x86-object" ||
         $archname eq "irix-o32" || $archname eq "sparc-linux") {

        $self->{'newOld'} = "A4";
        $self->{'statHead'} = "a4 a5 x7 d L L L x4 x80";
        $self->{'dsDef'} = "a20 a20 L x4 d d x56";
        $self->{'rraDef'} = "a20 L L x4 d x72";
        $self->{'pdpDef'} = "a30 x2 L x4 d x64";
        $self->{'cdpDef'} = "d L x4 x64";

        $self->{'liveHead'} = "L";
        $self->{'liveHead3'} = "L L";
        $self->{'rraPtr'} = "L";
        $self->{'element'} = "d";

        return 1;

    } elsif ($archname =~ /^aix|i.?86/i) {
        # Matija.Grabnar@arnes.si says that these formats
        # work for Solaris x86 too. And Patrick Myers <pjm@mcc.ac.uk>
        # says it works for i386-freebsd. Cool. And John Banner
        # <jbanner@UVic.Ca> says it works on AIX. And Dave Mangot
        # <dave@epylon.com> says it works on i386-openbsd. Peter Evans
        # <peter@gol.com> found a bug with Solaris 8/x86 which has been
        # fixed.

        # So, let's simplify and just say, 'if it has i.86 in the name,
        # use this format.

        $self->{'newOld'} = "A4";
        $self->{'statHead'} = "a4 a5 x3 d L L L x80";
        $self->{'dsDef'} = "a20 a20 L x4 d d x56";
        $self->{'rraDef'} = "a20 L L d x72";
        $self->{'pdpDef'} = "a30 x2 L x4 d x64";
        $self->{'cdpDef'} = "d L x4 x64";

        $self->{'liveHead'} = "L";
        $self->{'liveHead3'} = "L L";
        $self->{'rraPtr'} = "L";
        $self->{'element'} = "d";

        return 1;
    } elsif ( $archname eq 'alpha-dec_osf') {
        # Thanks to Melissa D. Binde <binde@amazon.com> for
        # finding this (and a major foobar in getFormat.c)

        $self->{'statHead'} = "a4 a5 x7 d L L L x80";
        $self->{'dsDef'} = "a20 a20 L d d x56";
        $self->{'rraDef'} = "a20 L L d x72";
        $self->{'pdpDef'} = "a30 x2 L d x64";
        $self->{'cdpDef'} = "d L x64";

        $self->{'liveHead'} = "L";
        $self->{'rraPtr'} = "L";
        $self->{'element'} = "d";

    } elsif ( $archname =~ 'PA-RISC' or $archname eq 'powerpc-linux') {
        $self->{'statHead'} = "a4 a5 x7 d L L L x4 x80";
        $self->{'dsDef'} = "a20 a20 L x4 d d x56";
        $self->{'rraDef'} = "a20 L L x4 d x72";
        $self->{'pdpDef'} = "a30 x2 L x4 d x64";
        $self->{'cdpDef'} = "d L x4 x64";
        $self->{'liveHead'} = "L";
        $self->{'rraPtr'} = "L";
        $self->{'element'} = "d";
    } elsif ( $archname eq 'alpha-linux' or $archname eq 'alpha-linux-gnu') {
        $self->{'statHead'} = "a4 a5 x7 d Q Q Q x80";
        $self->{'dsDef'} = "a20 a20 Q d d x56";
        $self->{'rraDef'} = "a20 x4 Q Q d x72";
        $self->{'pdpDef'} = "a30 x2 Q d x64";
        $self->{'cdpDef'} = "d Q x64";
        $self->{'liveHead'} = "Q";
        $self->{'rraPtr'} = "Q";
        $self->{'element'} = "d";
    } elsif ( $archname =~ /^x86_64-linux/ ) {
        $self->{'statHead'} = "a4 a5 x7 d Q Q Q x80";
        $self->{'dsDef'} = "a20 a20 Q d d x56";
        $self->{'rraDef'} = "a20 x4 Q Q d x72";
        $self->{'liveHead'} = "Q Q";
        $self->{'liveHead3'} = "Q Q";
        $self->{'pdpDef'} = "a30 x2 Q d x64";
        $self->{'cdpDef'} = "d Q x64";
        $self->{'rraPtr'} = "Q";
        $self->{'element'} = "d";
    } elsif ( $archname eq 'sparc64-netbsd' ) {
        $self->{'statHead'} = "a4 a5 x7 d Q Q Q x80";
        $self->{'dsDef'} = "a20 a20 Q d d x56";
        $self->{'rraDef'} = "a20 x4 Q Q d x72";
        $self->{'pdpDef'} = "a30 x2 Q d x64";
        $self->{'cdpDef'} = "d Q x64";
        $self->{'liveHead'} = "L";
        $self->{'rraPtr'} = "Q";
        $self->{'element'} = "d";
    } elsif ( $archname eq 's390x-linux' ) {
        $self->{'statHead'} = "a4 a5 x7 d Q Q Q x80";
        $self->{'dsDef'} = "a20 a20 Q d d x56";
        $self->{'rraDef'} = "a20 x4 Q Q d x72";
        $self->{'pdpDef'} = "a30 x2 Q d x64";
        $self->{'cdpDef'} = "d Q x64";
        $self->{'liveHead'} = "Q";
        $self->{'rraPtr'} = "Q";
        $self->{'element'} = "d";
    } else {
        return;
    }
}

# a utility subroutine to imitate C's sizeof() built-in
sub sizeof {
    my($template) = @_;
    return (length(pack($template)));
}

1;

# Local Variables:
# mode: perl
# indent-tabs-mode: nil
# tab-width: 4
# perl-indent-level: 4
# End: