/[Sack]/trunk/bin/sack.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bin/sack.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations)
Mon Sep 21 20:32:51 2009 UTC (14 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 2016 byte(s)
reset time on each call of report
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Time::HiRes qw(time);
7 use Data::Dump qw(dump);
8 use File::Slurp;
9 use Getopt::Long;
10
11
12 my $path = '/data/isi/full.txt';
13 my $limit = 10000;
14 my $offset = 0;
15 my @views;
16
17
18 GetOptions(
19 'path=s' => \$path,
20 'offset=i' => \$offset,
21 'limit=i' => \$limit,
22 'view=s' => \@views,
23 ) or die $!;
24
25 my $t = time;
26
27 use lib '/srv/webpac2/lib/';
28 use WebPAC::Input::ISI;
29 my $input = WebPAC::Input::ISI->new(
30 path => $path,
31 offset => $offset,
32 limit => $limit,
33 );
34
35
36 sub report {
37 my $description = shift;
38 my $dt = time - $t;
39 printf "%s in %1.4fs %.2f/s\n", $description, $dt, $input->size / $dt;
40 $t = time;
41 }
42
43
44 report $input->size . ' records loaded';
45
46 mkdir 'out' unless -e 'out';
47
48 our $out;
49
50 our $cache;
51
52 sub run_views {
53 @views = sort glob 'views/*.pl' unless @views;
54 warn "# views ", dump @views;
55
56 foreach my $view ( @views ) {
57
58 my ( $nr, $package ) = ( $1, $2 )
59 if $view =~ m{/(\d+)\.([^/]+(\.pl)?$)};
60
61 undef $out;
62
63 next if system("perl -c $view") != 0;
64
65 my $code = read_file $view;
66 warn "## CODE\n$code\n## CODE\n";
67
68 my $affected = 0;
69 $t = time;
70
71 foreach my $pos ( $offset + 1 .. $offset + $input->size ) {
72 my $rec = $cache->{$pos} ||= $input->fetch_rec( $pos );
73 if ( ! $rec ) {
74 warn "END at $pos";
75 last;
76 }
77
78 eval "$code";
79 if ( $@ ) {
80 warn "ERROR [$pos] $@\n";
81 } else {
82 $affected++;
83 }
84 };
85
86 report "$affected affected records $view";
87
88 if ( defined $out ) {
89 my $dump = dump $out;
90 my $len = length $dump;
91 my $path = "out/$nr.$package";
92 print "out $view $offset/$limit $len bytes $path"
93 , ( $len < 10000 ? " \$out = $dump" : ' SAVED ONLY' )
94 , "\n"
95 ;
96
97 unlink "$path.last" if -e "$path.last";
98 rename $path, "$path.last";
99 write_file $path, $dump;
100 report "save $path";
101 } else {
102 warn "W: no \$out defined!";
103 }
104
105 }
106 }
107
108 run_views;
109
110 while ( 1 ) {
111
112 print "sack> ";
113 my $cmd = <STDIN>;
114
115 if ( $cmd =~ m{(vi|\\e|out)}i ) {
116 system "vi out/*";
117 } else {
118 run_views;
119 }
120
121 }
122

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26