| 301 |
ashish |
1 |
// Copyright (c) 2007-2008 Facebook
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
//
|
|
|
15 |
// See accompanying file LICENSE or visit the Scribe site at:
|
|
|
16 |
// http://developers.facebook.com/scribe/
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
#include <stdio.h>
|
|
|
20 |
#include <iostream>
|
|
|
21 |
#include <fstream>
|
|
|
22 |
#include <sstream>
|
|
|
23 |
#include <string>
|
|
|
24 |
|
|
|
25 |
#define MAX_MESSAGE_LENGTH 1024
|
|
|
26 |
|
|
|
27 |
void usage() {
|
|
|
28 |
fprintf(stderr, "usage: resultChecker clientname file(s)\n");
|
|
|
29 |
fprintf(stderr, "Reads files and counts log entries for the specified client.\n");
|
|
|
30 |
fprintf(stderr, "Prints the number of messages and out of order messages in each file.\n");
|
|
|
31 |
fprintf(stderr, "Entries must be formatted (\"%%s-%%d...\", client_name, sequence_number)\n");
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
int main(int argc, char** argv) {
|
|
|
35 |
|
|
|
36 |
if (argc < 3) {
|
|
|
37 |
usage();
|
|
|
38 |
return 1;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
std::string clientname(argv[1]);
|
|
|
42 |
|
|
|
43 |
int last_entry = -1;
|
|
|
44 |
int bad_this_file = 0;
|
|
|
45 |
int entries_this_file = 0;
|
|
|
46 |
int total_bad = 0;
|
|
|
47 |
int total_entries = 0;
|
|
|
48 |
|
|
|
49 |
for (int i = 2; i < argc; ++i) {
|
|
|
50 |
|
|
|
51 |
entries_this_file = 0;
|
|
|
52 |
bad_this_file = 0;
|
|
|
53 |
|
|
|
54 |
std::ifstream infile(argv[i]);
|
|
|
55 |
if (!infile.good()) {
|
|
|
56 |
fprintf(stderr, "Failed to open input file: %s\n", argv[i]);
|
|
|
57 |
continue;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
while (infile.good()) {
|
|
|
61 |
char buffer[MAX_MESSAGE_LENGTH];
|
|
|
62 |
buffer[0] = 0;
|
|
|
63 |
while (0 == infile.peek()) {
|
|
|
64 |
infile.get();
|
|
|
65 |
}
|
|
|
66 |
infile.getline(buffer, MAX_MESSAGE_LENGTH - 1);
|
|
|
67 |
if (buffer[0] != 0) {
|
|
|
68 |
char* separator = strchr(buffer, '-');
|
|
|
69 |
if (separator && buffer + strlen(buffer) > separator) {
|
|
|
70 |
char name[MAX_MESSAGE_LENGTH];
|
|
|
71 |
strncpy(name, buffer, separator - buffer);
|
|
|
72 |
name[separator - buffer] = 0;
|
|
|
73 |
int entry = atoi(separator + 1);
|
|
|
74 |
if (0 == clientname.compare(name)) {
|
|
|
75 |
++entries_this_file;
|
|
|
76 |
if (entry != last_entry + 1) {
|
|
|
77 |
fprintf(stderr, "Out of order entry: <%d> follows <%d>\n", entry, last_entry);
|
|
|
78 |
++bad_this_file;
|
|
|
79 |
}
|
|
|
80 |
last_entry = entry;
|
|
|
81 |
} // client matches
|
|
|
82 |
} // line was parsed
|
|
|
83 |
} // line isn't empty
|
|
|
84 |
} // for each line
|
|
|
85 |
infile.close();
|
|
|
86 |
|
|
|
87 |
printf("File <%s>: <%d> total <%d> out of order\n", argv[i], entries_this_file, bad_this_file);
|
|
|
88 |
total_bad += bad_this_file;
|
|
|
89 |
total_entries += entries_this_file;
|
|
|
90 |
|
|
|
91 |
} // for each requested file
|
|
|
92 |
|
|
|
93 |
printf("Total: <%d> matching entries <%d> out of order\n", total_entries, total_bad);
|
|
|
94 |
|
|
|
95 |
return 0;
|
|
|
96 |
}
|