Loading logcat/logcat.cpp +11 −17 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include <atomic> #include <memory> #include <string> #include <utility> #include <vector> #include <android-base/file.h> Loading Loading @@ -565,23 +566,14 @@ static int setLogFormat(android_logcat_context_internal* context, return android_log_setPrintFormat(context->logformat, format); } static const char multipliers[][2] = { { "" }, { "K" }, { "M" }, { "G" } }; static unsigned long value_of_size(unsigned long value) { for (unsigned i = 0; (i < sizeof(multipliers) / sizeof(multipliers[0])) && (value >= 1024); value /= 1024, ++i) ; return value; } static const char* multiplier_of_size(unsigned long value) { unsigned i; static std::pair<unsigned long, const char*> format_of_size(unsigned long value) { static const char multipliers[][3] = {{""}, {"Ki"}, {"Mi"}, {"Gi"}}; size_t i; for (i = 0; (i < sizeof(multipliers) / sizeof(multipliers[0])) && (value >= 1024); value /= 1024, ++i) ; return multipliers[i]; return std::make_pair(value, multipliers[i]); } // String to unsigned int, returns -1 if it fails Loading Loading @@ -1472,12 +1464,14 @@ static int __logcat(android_logcat_context_internal* context) { if ((size < 0) || (readable < 0)) { reportErrorName(&getSizeFail, dev->device, allSelected); } else { auto size_format = format_of_size(size); auto readable_format = format_of_size(readable); std::string str = android::base::StringPrintf( "%s: ring buffer is %ld%sb (%ld%sb consumed)," " max entry is %db, max payload is %db\n", "%s: ring buffer is %lu %sB (%lu %sB consumed)," " max entry is %d B, max payload is %d B\n", dev->device, value_of_size(size), multiplier_of_size(size), value_of_size(readable), multiplier_of_size(readable), size_format.first, size_format.second, readable_format.first, readable_format.second, (int)LOGGER_ENTRY_MAX_LEN, (int)LOGGER_ENTRY_MAX_PAYLOAD); TEMP_FAILURE_RETRY(write(context->output_fd, Loading logcat/tests/logcat_test.cpp +17 −17 Original line number Diff line number Diff line Loading @@ -557,20 +557,17 @@ static int get_groups(const char* cmd) { while (fgets(buffer, sizeof(buffer), fp)) { int size, consumed, max, payload; char size_mult[3], consumed_mult[3]; char size_mult[4], consumed_mult[4]; long full_size, full_consumed; size = consumed = max = payload = 0; // NB: crash log can be very small, not hit a Kb of consumed space // doubly lucky we are not including it. if (6 != sscanf(buffer, "%*s ring buffer is %d%2s (%d%2s consumed)," " max entry is %db, max payload is %db", &size, size_mult, &consumed, consumed_mult, &max, &payload)) { fprintf(stderr, "WARNING: Parse error: %s", buffer); continue; } EXPECT_EQ(6, sscanf(buffer, "%*s ring buffer is %d %3s (%d %3s consumed)," " max entry is %d B, max payload is %d B", &size, size_mult, &consumed, consumed_mult, &max, &payload)) << "Parse error on: " << buffer; full_size = size; switch (size_mult[0]) { case 'G': Loading @@ -582,8 +579,10 @@ static int get_groups(const char* cmd) { case 'K': full_size *= 1024; /* FALLTHRU */ case 'b': case 'B': break; default: ADD_FAILURE() << "Parse error on multiplier: " << size_mult; } full_consumed = consumed; switch (consumed_mult[0]) { Loading @@ -596,8 +595,10 @@ static int get_groups(const char* cmd) { case 'K': full_consumed *= 1024; /* FALLTHRU */ case 'b': case 'B': break; default: ADD_FAILURE() << "Parse error on multiplier: " << consumed_mult; } EXPECT_GT((full_size * 9) / 4, full_consumed); EXPECT_GT(full_size, max); Loading Loading @@ -1232,10 +1233,9 @@ TEST(logcat, blocking_clear) { char size_mult[3], consumed_mult[3]; size = consumed = max = payload = 0; if (6 == sscanf(buffer, "events: ring buffer is %d%2s (%d%2s consumed)," " max entry is %db, max payload is %db", &size, size_mult, &consumed, consumed_mult, &max, &payload)) { "events: ring buffer is %d %3s (%d %3s consumed)," " max entry is %d B, max payload is %d B", &size, size_mult, &consumed, consumed_mult, &max, &payload)) { long full_size = size, full_consumed = consumed; switch (size_mult[0]) { Loading @@ -1248,7 +1248,7 @@ TEST(logcat, blocking_clear) { case 'K': full_size *= 1024; /* FALLTHRU */ case 'b': case 'B': break; } switch (consumed_mult[0]) { Loading @@ -1261,7 +1261,7 @@ TEST(logcat, blocking_clear) { case 'K': full_consumed *= 1024; /* FALLTHRU */ case 'b': case 'B': break; } EXPECT_GT(full_size, full_consumed); Loading Loading
logcat/logcat.cpp +11 −17 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include <atomic> #include <memory> #include <string> #include <utility> #include <vector> #include <android-base/file.h> Loading Loading @@ -565,23 +566,14 @@ static int setLogFormat(android_logcat_context_internal* context, return android_log_setPrintFormat(context->logformat, format); } static const char multipliers[][2] = { { "" }, { "K" }, { "M" }, { "G" } }; static unsigned long value_of_size(unsigned long value) { for (unsigned i = 0; (i < sizeof(multipliers) / sizeof(multipliers[0])) && (value >= 1024); value /= 1024, ++i) ; return value; } static const char* multiplier_of_size(unsigned long value) { unsigned i; static std::pair<unsigned long, const char*> format_of_size(unsigned long value) { static const char multipliers[][3] = {{""}, {"Ki"}, {"Mi"}, {"Gi"}}; size_t i; for (i = 0; (i < sizeof(multipliers) / sizeof(multipliers[0])) && (value >= 1024); value /= 1024, ++i) ; return multipliers[i]; return std::make_pair(value, multipliers[i]); } // String to unsigned int, returns -1 if it fails Loading Loading @@ -1472,12 +1464,14 @@ static int __logcat(android_logcat_context_internal* context) { if ((size < 0) || (readable < 0)) { reportErrorName(&getSizeFail, dev->device, allSelected); } else { auto size_format = format_of_size(size); auto readable_format = format_of_size(readable); std::string str = android::base::StringPrintf( "%s: ring buffer is %ld%sb (%ld%sb consumed)," " max entry is %db, max payload is %db\n", "%s: ring buffer is %lu %sB (%lu %sB consumed)," " max entry is %d B, max payload is %d B\n", dev->device, value_of_size(size), multiplier_of_size(size), value_of_size(readable), multiplier_of_size(readable), size_format.first, size_format.second, readable_format.first, readable_format.second, (int)LOGGER_ENTRY_MAX_LEN, (int)LOGGER_ENTRY_MAX_PAYLOAD); TEMP_FAILURE_RETRY(write(context->output_fd, Loading
logcat/tests/logcat_test.cpp +17 −17 Original line number Diff line number Diff line Loading @@ -557,20 +557,17 @@ static int get_groups(const char* cmd) { while (fgets(buffer, sizeof(buffer), fp)) { int size, consumed, max, payload; char size_mult[3], consumed_mult[3]; char size_mult[4], consumed_mult[4]; long full_size, full_consumed; size = consumed = max = payload = 0; // NB: crash log can be very small, not hit a Kb of consumed space // doubly lucky we are not including it. if (6 != sscanf(buffer, "%*s ring buffer is %d%2s (%d%2s consumed)," " max entry is %db, max payload is %db", &size, size_mult, &consumed, consumed_mult, &max, &payload)) { fprintf(stderr, "WARNING: Parse error: %s", buffer); continue; } EXPECT_EQ(6, sscanf(buffer, "%*s ring buffer is %d %3s (%d %3s consumed)," " max entry is %d B, max payload is %d B", &size, size_mult, &consumed, consumed_mult, &max, &payload)) << "Parse error on: " << buffer; full_size = size; switch (size_mult[0]) { case 'G': Loading @@ -582,8 +579,10 @@ static int get_groups(const char* cmd) { case 'K': full_size *= 1024; /* FALLTHRU */ case 'b': case 'B': break; default: ADD_FAILURE() << "Parse error on multiplier: " << size_mult; } full_consumed = consumed; switch (consumed_mult[0]) { Loading @@ -596,8 +595,10 @@ static int get_groups(const char* cmd) { case 'K': full_consumed *= 1024; /* FALLTHRU */ case 'b': case 'B': break; default: ADD_FAILURE() << "Parse error on multiplier: " << consumed_mult; } EXPECT_GT((full_size * 9) / 4, full_consumed); EXPECT_GT(full_size, max); Loading Loading @@ -1232,10 +1233,9 @@ TEST(logcat, blocking_clear) { char size_mult[3], consumed_mult[3]; size = consumed = max = payload = 0; if (6 == sscanf(buffer, "events: ring buffer is %d%2s (%d%2s consumed)," " max entry is %db, max payload is %db", &size, size_mult, &consumed, consumed_mult, &max, &payload)) { "events: ring buffer is %d %3s (%d %3s consumed)," " max entry is %d B, max payload is %d B", &size, size_mult, &consumed, consumed_mult, &max, &payload)) { long full_size = size, full_consumed = consumed; switch (size_mult[0]) { Loading @@ -1248,7 +1248,7 @@ TEST(logcat, blocking_clear) { case 'K': full_size *= 1024; /* FALLTHRU */ case 'b': case 'B': break; } switch (consumed_mult[0]) { Loading @@ -1261,7 +1261,7 @@ TEST(logcat, blocking_clear) { case 'K': full_consumed *= 1024; /* FALLTHRU */ case 'b': case 'B': break; } EXPECT_GT(full_size, full_consumed); Loading