diff options
author | Haley Connelly <haley.connelly@10gen.com> | 2018-07-31 18:27:03 -0400 |
---|---|---|
committer | Haley Connelly <haley.connelly@10gen.com> | 2018-07-31 18:34:33 -0400 |
commit | 075d7fe467e12aa3dfa19aff27672a7a5b34aff0 (patch) | |
tree | fe54aa2b9079fd063b08a1fca09f195f12354ef8 /src/mongo/util | |
parent | 6711ab3bbc02ca98da1af2fe115f07e37bb076e4 (diff) | |
download | mongo-075d7fe467e12aa3dfa19aff27672a7a5b34aff0.tar.gz |
SERVER-23332 Expose query plan cache key in system.profile entry and query log lines
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/hex.cpp | 5 | ||||
-rw-r--r-- | src/mongo/util/hex.h | 5 | ||||
-rw-r--r-- | src/mongo/util/stringutils_test.cpp | 7 |
3 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/util/hex.cpp b/src/mongo/util/hex.cpp index 2d4a563c05b..48f433c388a 100644 --- a/src/mongo/util/hex.cpp +++ b/src/mongo/util/hex.cpp @@ -90,6 +90,11 @@ std::string integerToHex<unsigned long long>(unsigned long long val) { return integerToHexDef(val); } +std::string unsignedIntToFixedLengthHex(uint32_t val) { + char buf[9]; + invariant(snprintf(buf, 9, "%08X", val) == 8); + return std::string(buf, 8); +} std::string hexdump(const char* data, unsigned len) { verify(len < 1000000); diff --git a/src/mongo/util/hex.h b/src/mongo/util/hex.h index 382eb0bd86c..550fecc4cd5 100644 --- a/src/mongo/util/hex.h +++ b/src/mongo/util/hex.h @@ -111,6 +111,11 @@ inline std::string toHexLower(const void* inRaw, int len) { return out.str(); } +/** + * Returns the hex value with a fixed width of 8 chatacters. + */ +std::string unsignedIntToFixedLengthHex(uint32_t val); + /* @return a dump of the buffer as hex byte ascii output */ std::string hexdump(const char* data, unsigned len); } diff --git a/src/mongo/util/stringutils_test.cpp b/src/mongo/util/stringutils_test.cpp index 80bbfc5db10..a156471dc57 100644 --- a/src/mongo/util/stringutils_test.cpp +++ b/src/mongo/util/stringutils_test.cpp @@ -194,6 +194,13 @@ TEST(StringUtilsTest, VariousConversions) { integerToHex(std::numeric_limits<long long>::min())); } +TEST(StringUtilsTest, unsignedFixedLengthHex) { + ASSERT_EQUALS(unsignedIntToFixedLengthHex(std::numeric_limits<uint32_t>::max()), + std::string("FFFFFFFF")); + ASSERT_EQUALS(unsignedIntToFixedLengthHex(0), std::string("00000000")); + ASSERT_EQUALS(unsignedIntToFixedLengthHex(123), std::string("0000007B")); +} + TEST(StringUtilsTest, CanParseZero) { boost::optional<size_t> result = parseUnsignedBase10Integer("0"); ASSERT(result && *result == 0); |