~ubuntu-x-swat/xorg-server/xsmoke

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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/perl -w
#========================================================================
#
# xlogparse
#
# DESCRIPTION
#
# Parses Xlog.*.log format files and allows looking up data from it
#
# AUTHOR
#   Bryce W. Harrington <bryce@bryceharrington.org>
#
# COPYRIGHT
#   Copyright (C) 2007 Bryce W. Harrington
#   All Rights Reserved.
#
#   This program is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
#========================================================================

use strict;
use Pod::Usage;
use Getopt::Long qw(:config no_ignore_case bundling);

#------------------------------------------------------------------------
# Global variables
#------------------------------------------------------------------------
use vars qw($VERSION $NAME);
$VERSION              = '1.00';
$NAME                 = 'xlogparse';

our $opt_version      = 0;   # Prints the version and exits
our $opt_help         = 0;   # Prints a brief help message
our $opt_helplong     = 0;   # Prints a long help message
our $opt_man          = 0;   # Prints a manual page (detailed help)
our $opt_debug        = 1;   # Prints debug messages
our $opt_summary      = 0;
our $opt_devices      = 0;
our $opt_modules      = 0;

Getopt::Long::Configure ("bundling", "no_ignore_case");
GetOptions(
           "version|V",        # Prints the version and exits
           "help|h",           # Prints a brief help message
           "helplong|H",       # Prints a long help message
           "man|M",            # Prints a manual page (detailed help)
           "debug|D=i",        # Prints debug messages
           "summary",          # Prints a summary of the xorg log
           "devices",          # List configured drivers
           "modules",          # List loaded modules
           ) or pod2usage(-verbose => 0, -exitstatus => 0);

version_and_exit() if $opt_version;
pod2usage(-verbose => 0, -exitstatus => 0) if $opt_help;
pod2usage(-verbose => 1, -exitstatus => 0) if $opt_helplong;

if (! $opt_devices && ! $opt_modules) {
    $opt_summary = 1;
}

#========================================================================
# Subroutines
#------------------------------------------------------------------------

=head2 version_and_exit()

Displays text describing the version of the script

=cut

sub version_and_exit
{
    print "$NAME version $VERSION\n";
    print "Copyright (C) 2007 Bryce W. Harrington <bryce\@bryceharrington.org>\n";
    print "This program is free software; you can redistribute it and/or\n";
    print "modify it under the same terms as Perl itself.\n";
    exit(0);
}


# Tool for parsing Xorg.*.log formatted files

sub process_record {
    my $content = shift || return undef;
    my %rec;

    $rec{line} = $content;

    if ($content =~ /^\((\w+)\)/) {
        $rec{type} = $1;
    } else {
        $rec{type} = 'XX';
    }

    if ($content =~ /XINPUT: Adding extended input device "(.*:?)" \(type:\s+(.*:?)\)/) {
        $rec{device}->{name}  = $1;
        $rec{device}->{class} = 'input';
        $rec{device}->{type}  = $2;
    }

    # Get module information
    if ($content =~ /^\(II\) Module (\w+):/) {
        $rec{module}->{name} = $1;
        if ($content =~ /vendor="(.*:?)"/m) {
            $rec{module}->{vendor} = $1;
        }
        if ($content =~ /module version = (.*)/) {
            $rec{module}->{version} = $1;
        }
        if ($content =~ /class: (.*)/) {
            $rec{module}->{class} = $1;
        }
        if ($content =~ /ABI class:\s+(.*:?), version\s+(.*:?)/) {
            $rec{module}->{abi_name} = $1;
            $rec{module}->{abi_version} = $2;
        }
    }

    return \%rec;
}

my @Log;

my $buffer;
foreach my $line (<>) {
    if ($line =~ m/^\(/) {
        if (defined $buffer) {
            push @Log, process_record($buffer);
            $buffer = '';
        }
    }
    $buffer .= $line;
}
if (defined $buffer) {
    push @Log, process_record($buffer);
}


my $log_count = @Log;

my @info = grep { $_->{type} eq "II" } @Log;
my $info_count = @info;

my @notimpl = grep { $_->{type} eq "NI" } @Log;
my $notimpl_count = @notimpl;

my @notices = grep { $_->{type} eq "!!" } @Log;
my $notice_count = @notices;

my @errors = grep { $_->{type} eq "EE" } @Log;
my $error_count = @errors;

my @warnings = grep { $_->{type} eq "WW" } @Log;
my $warning_count = @warnings;

my @devices = grep { defined $_->{device} } @Log;
my $device_count = @devices;

my @modules = grep { defined $_->{module} } @Log;
my $module_count = @modules;

if ($opt_summary) {
    print "\n";
    print "Log contains $log_count entries\n";
    print "  - $info_count info messages\n";
    print "  - $error_count errors\n";
    print "  - $warning_count warnings\n";
    print "  - $device_count devices\n";
}

if ($opt_devices) {
    print "\n";
    print "Input Devices:\n";
    foreach my $device (@devices) {
        printf("  + %-12s %-20s %-s\n",
               $device->{device}->{class},
               $device->{device}->{name},
               $device->{device}->{type});
    }
}

if ($opt_modules) {
    if ($opt_summary) {
        print "\n";
        print "Modules:\n";
        printf("  + %-10s %-10s %-s\n",
               "MODULE", "VERSION", "VENDOR");
    } else {
        printf("%-10s %-10s %-30s %-s\n",
               "MODULE", "VERSION", "ABI-NAME", "VENDOR");
    }
    my $last_cat = '';
    foreach my $module (sort { $a->{module}->{abi_name} cmp $b->{module}->{abi_name} } @modules) {
        if ($opt_summary) {
            if ($module->{module}->{abi_name} ne $last_cat) {
                printf("\n %s\n", $module->{module}->{abi_name});
                $last_cat = $module->{module}->{abi_name};
            }
            printf("  + %-10s %-10s %-s\n",
                   $module->{module}->{name},
                   $module->{module}->{version},
                   $module->{module}->{vendor}
                   );
        } else {
            my $abi_name = $module->{module}->{abi_name};
            $abi_name =~ s/X.Org\s+//;
            $abi_name =~ s/\s/-/g;
            printf("%-10s %-10s %-30s %-s\n",
                   $module->{module}->{name},
                   $module->{module}->{version},
                   $abi_name,
                   $module->{module}->{vendor}
                   );
        }
    }
}




#########################################################################

__END__


=head1 NAME

B<xlogparse> - Parses Xlog.*.log format files and allows looking up data
from it


=head1 SYNOPSIS

treport [options] [ [ options ] ]

 Options:
   -V, --version=boolean         Prints the version and exits
   -h, --help=boolean            Prints a brief help message
   -H, --helplong=boolean        Prints a long help message
       --man=boolean             Prints a manual page (detailed help)
   -D, --debug=integer           Prints debug messages

=head1 DESCRIPTION

Parses Xlog.*.log format files and allows looking up data from it

=head1 OPTIONS

=over 8

=item B<-V>, B<--version>

Prints the version and exits

=item B<-h>, B<--help>

Prints a brief help message

=item B<-H>, B<--helplong>

Prints a long help message

=item B<--man>

Prints a manual page (detailed help)

=item B<-D> I<D>, B<--debug>=I<D>

Prints debug messages


=back

See B<xlogparse> -h for a summary of options.


=head1 PREREQUISITES

L<Pod::Usage>,
L<Getopt::Long>

=head1 BUGS

None known.

=head1 VERSION

1.00

=head1 SEE ALSO

L<perl(1)>


=head1 AUTHOR

Bryce W. Harrington E<lt>bryce@bryceharrington.orgE<gt>

L<http://www.bryceharrington.org|http://www.bryceharrington.org>

=head1 COPYRIGHT

Copyright (C) 2007 Bryce W. Harrington.
All Rights Reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 REVISION

Revision: $Revision: 1.1.1.1 $

=cut