Add metrics_dump, a tool to format drm metrics
[ Merge of http://go/wvgerrit/59022 ] Android metrics are output by the adb shell command |dumpsys media.metrics|. They appear in bugreports and can also be requested interactively. Both the widevine and framework mediadrm metrics are base64 encoded protobufs detailing each of the metrics items. This tool prints them in a readable format. Test: wv android unit/integration tests Change-Id: Id1bc05b34693a3ca44dd3872a28a2337b3ce4d79
This commit is contained in:
89
libwvdrmengine/tools/metrics_dump/src/base64decode.cpp
Normal file
89
libwvdrmengine/tools/metrics_dump/src/base64decode.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
//
|
||||
// simple base64 decoder
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base64decode.h"
|
||||
|
||||
namespace base64 {
|
||||
|
||||
using namespace std;
|
||||
|
||||
string Base64::Decode(const string &encoded) {
|
||||
string s = encoded;
|
||||
|
||||
while (s.size() % 4 != 0) {
|
||||
s.append("=");
|
||||
}
|
||||
|
||||
size_t n = s.size();
|
||||
|
||||
size_t padding = 0;
|
||||
if (n >= 1 && s[n - 1] == '=') {
|
||||
padding = 1;
|
||||
|
||||
if (n >= 2 && s[n - 2] == '=') {
|
||||
padding = 2;
|
||||
|
||||
if (n >= 3 && s[n - 3] == '=') {
|
||||
padding = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We divide first to avoid overflow. It's OK to do this because we
|
||||
// already made sure that n % 4 == 0.
|
||||
size_t outLen = (n / 4) * 3 - padding;
|
||||
|
||||
std::unique_ptr<uint8_t> buffer(new uint8_t[outLen]);
|
||||
if (!buffer) {
|
||||
return "";
|
||||
}
|
||||
uint8_t *out = buffer.get();
|
||||
size_t j = 0;
|
||||
uint32_t accum = 0;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
char c = s[i];
|
||||
unsigned value;
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
value = c - 'A';
|
||||
} else if (c >= 'a' && c <= 'z') {
|
||||
value = 26 + c - 'a';
|
||||
} else if (c >= '0' && c <= '9') {
|
||||
value = 52 + c - '0';
|
||||
} else if (c == '+' || c == '-') {
|
||||
value = 62;
|
||||
} else if (c == '/' || c == '_') {
|
||||
value = 63;
|
||||
} else {
|
||||
if (c != '=') {
|
||||
std::cerr << "unexpected character in base64 decode:" << c << std::endl;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
|
||||
accum = (accum << 6) | value;
|
||||
|
||||
if (((i + 1) % 4) == 0) {
|
||||
if (j < outLen) {
|
||||
out[j++] = (accum >> 16);
|
||||
}
|
||||
if (j < outLen) {
|
||||
out[j++] = (accum >> 8) & 0xff;
|
||||
}
|
||||
if (j < outLen) {
|
||||
out[j++] = accum & 0xff;
|
||||
}
|
||||
|
||||
accum = 0;
|
||||
}
|
||||
}
|
||||
return string((char *)buffer.get(), outLen);
|
||||
}
|
||||
|
||||
} // namespace base64
|
||||
Reference in New Issue
Block a user