-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a blob_compare tool that compares two sbs files that may have t…
…he blobs in a different order PiperOrigin-RevId: 694055647
- Loading branch information
1 parent
5674c33
commit 213ea96
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <cstdint> | ||
#include <cstdio> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "compression/blob_store.h" | ||
#include "compression/io.h" | ||
#include "hwy/aligned_allocator.h" | ||
#include "hwy/base.h" | ||
|
||
namespace gcpp { | ||
|
||
// Compares two sbs files, ignoring the order of the blobs. | ||
// Gives up on the first mismatch. | ||
void CompareBlobs(const char* path1, const char* path2) { | ||
BlobReader reader1; | ||
HWY_ASSERT(reader1.Open(Path(path1)) == 0); | ||
BlobReader reader2; | ||
HWY_ASSERT(reader2.Open(Path(path2)) == 0); | ||
hwy::Span<const hwy::uint128_t> keys1 = reader1.Keys(); | ||
size_t total_matches = 0; | ||
size_t total_fails = 0; | ||
for (size_t i = 0; i < keys1.size(); ++i) { | ||
fprintf(stderr, "key %s, blob1 size=%zu, blob2 size=%zu\n", | ||
StringFromKey(keys1[i]).c_str(), reader1.BlobSize(keys1[i]), | ||
reader2.BlobSize(keys1[i])); | ||
std::vector<uint8_t> data1(reader1.BlobSize(keys1[i])); | ||
HWY_ASSERT(reader1.ReadOne(keys1[i], data1.data(), data1.size()) == 0); | ||
HWY_ASSERT(reader2.BlobSize(keys1[i]) == data1.size()); | ||
std::vector<uint8_t> data2(reader2.BlobSize(keys1[i])); | ||
HWY_ASSERT(reader2.ReadOne(keys1[i], data2.data(), data2.size()) == 0); | ||
size_t fails = 0; | ||
for (size_t j = 0; j < data1.size(); ++j) { | ||
if (data1[j] != data2[j]) { | ||
if (fails == 0) { | ||
fprintf(stderr, "key %s Mismatch at %zu\n", | ||
StringFromKey(keys1[i]).c_str(), j); | ||
} | ||
++fails; | ||
} | ||
} | ||
if (fails > 0) { | ||
fprintf(stderr, "key %s has %.2f%% Mismatch!\n", | ||
StringFromKey(keys1[i]).c_str(), 100.0 * fails / data1.size()); | ||
++total_fails; | ||
} else { | ||
fprintf(stderr, "key %s Matched!\n", StringFromKey(keys1[i]).c_str()); | ||
++total_matches; | ||
} | ||
} | ||
fprintf(stderr, "Total matches=%zu, mismatches=%zu\n", total_matches, | ||
total_fails); | ||
} | ||
|
||
} // namespace gcpp | ||
|
||
int main(int argc, char** argv) { | ||
if (argc != 3) { | ||
fprintf(stderr, "Usage: %s <sbs_path> <sbs_path>\n", argv[0]); | ||
return 1; | ||
} | ||
gcpp::CompareBlobs(argv[1], argv[2]); | ||
return 0; | ||
} |