| 37 | namespace tools { |
| 38 | |
| 39 | void ReadLog(const std::string& full_path) { |
| 40 | std::string fname = ParseFileNameFromPath(full_path); |
| 41 | std::ofstream my_cout(fname + "_result.txt"); |
| 42 | FILE* fd_r = fopen(full_path.c_str(), "rb"); |
| 43 | if (fd_r == NULL) { |
| 44 | printf("fopen failed: %s\n", full_path.c_str()); |
| 45 | return; |
| 46 | } |
| 47 | SequentialFile* rf = NewSeqFile(full_path, fd_r); |
| 48 | std::string scratch; |
| 49 | bool for_snapshot = false; |
| 50 | if (full_path.find(fedb::log::ZLIB_COMPRESS_SUFFIX) != std::string::npos |
| 51 | || full_path.find(fedb::log::SNAPPY_COMPRESS_SUFFIX) != std::string::npos) { |
| 52 | for_snapshot = true; |
| 53 | } |
| 54 | Reader reader(rf, NULL, true, 0, for_snapshot); |
| 55 | Status status; |
| 56 | uint64_t success_cnt = 0; |
| 57 | do { |
| 58 | Slice value; |
| 59 | status = reader.ReadRecord(&value, &scratch); |
| 60 | if (!status.ok()) { |
| 61 | break; |
| 62 | } |
| 63 | ::fedb::api::LogEntry entry; |
| 64 | entry.ParseFromString(value.ToString()); |
| 65 | if (entry.ts_dimensions_size() == 0) { |
| 66 | my_cout << entry.ts() << std::endl; |
| 67 | } else { |
| 68 | for (int i = 0; i < entry.ts_dimensions_size(); i++) { |
| 69 | my_cout << entry.ts_dimensions(i).idx() << "\t" << |
| 70 | entry.ts_dimensions(i).ts() << std::endl; |
| 71 | } |
| 72 | } |
| 73 | if (entry.dimensions_size() == 0) { |
| 74 | my_cout << entry.pk() << std::endl; |
| 75 | } else { |
| 76 | for (int i = 0; i < entry.dimensions_size(); i++) { |
| 77 | my_cout << entry.dimensions(i).idx() << "\t" |
| 78 | << entry.dimensions(i).key().c_str() << std::endl; |
| 79 | } |
| 80 | } |
| 81 | success_cnt++; |
| 82 | } while (status.ok()); |
| 83 | my_cout.close(); |
| 84 | printf("--------success_cnt: %lu\n", success_cnt); |
| 85 | } |
| 86 | |
| 87 | } // namespace tools |
| 88 | } // namespace fedb |
no test coverage detected