-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
115 additions
and
28 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
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,68 @@ | ||
#include "proto.h" | ||
|
||
#include <cstdint> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
int main(int argc, char** argv) { | ||
if (argc < 2) { | ||
std::cerr << "Usage: " << argv[0] << " <perfetto trace proto file>" << std::endl; | ||
return 1; | ||
} | ||
const char* filename = argv[1]; | ||
std::cout << "Reading file " << filename << std::endl; | ||
std::ifstream file(argv[1], std::ios::binary); | ||
std::vector<uint8_t> buffer(std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}); | ||
if (buffer.empty()) { | ||
std::cerr << "File " << filename << " is empty."; | ||
return 1; | ||
} | ||
|
||
int trace_packets = 0; | ||
size_t trace_packet_size = 0; | ||
int padding = 0; | ||
size_t padding_size = 0; | ||
|
||
size_t at = 0; | ||
while (at < buffer.size()) { | ||
uint64_t tag = 0; | ||
at += proto::read_varint(tag, &buffer[at], buffer.size() - at); | ||
if (tag == 0) { | ||
std::cerr << "Invalid tag at offset " << at << std::endl; | ||
return 1; | ||
} | ||
|
||
proto::wire_type type = static_cast<proto::wire_type>(tag & 0x7); | ||
if (type != proto::wire_type::len) { | ||
std::cerr << "Tag was not wire_type::len" << std::endl; | ||
return 1; | ||
} | ||
tag >>= 3; | ||
|
||
uint64_t len = -1; | ||
at += proto::read_varint(len, &buffer[at], buffer.size() - at); | ||
if (len > buffer.size() - at) { | ||
std::cerr << "Protobuf len is larger than file size" << std::endl; | ||
return 1; | ||
} | ||
at += len; | ||
|
||
switch (tag) { | ||
case 1: | ||
trace_packets++; | ||
trace_packet_size += len; | ||
// TODO: Dig into deeper protobufs. | ||
break; | ||
case 2: | ||
padding++; | ||
padding_size += len; | ||
break; | ||
} | ||
} | ||
|
||
std::cout << "End of protobuf" << std::endl; | ||
std::cout << " Trace packets: " << trace_packets << " (" << trace_packet_size << " bytes)" << std::endl; | ||
std::cout << " Padding: " << padding << " (" << padding_size << " bytes)" << std::endl; | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,16 +1,17 @@ | ||
#!/bin/bash | ||
|
||
pthread_trace="$1" | ||
target="$2" | ||
is_perfetto_trace="$1" | ||
pthread_trace="$2" | ||
target="$3" | ||
|
||
shift | ||
shift | ||
shift | ||
|
||
fail() { rc=$?; (( $# )) && printf '%s\n' "$*" >&2; exit $(( rc == 0 ? 1 : rc )); } | ||
|
||
trace=$(mktemp) | ||
|
||
exec 5>&1 | ||
output=$(PTHREAD_TRACE_BUFFER_SIZE_KB=1 PTHREAD_TRACE_PATH=$trace LD_PRELOAD="$pthread_trace" "$target" "$@" 2>&1 | tee >(cat - >&5)) | ||
PTHREAD_TRACE_BUFFER_SIZE_KB=1 PTHREAD_TRACE_PATH=$trace LD_PRELOAD="$pthread_trace" "$target" "$@" | ||
|
||
echo "$output" | grep "pthread_trace: Recorded.*KB trace" > /dev/null || fail "Did not find pthread_trace report in output" | ||
$is_perfetto_trace $trace || fail "ERROR: $trace is not a valid perfetto trace" |
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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#!/bin/bash | ||
|
||
target="$1" | ||
is_perfetto_trace="$1" | ||
target="$2" | ||
|
||
shift | ||
shift | ||
|
||
fail() { rc=$?; (( $# )) && printf '%s\n' "$*" >&2; exit $(( rc == 0 ? 1 : rc )); } | ||
|
||
trace=$(mktemp) | ||
|
||
exec 5>&1 | ||
output=$(PTHREAD_TRACE_BUFFER_SIZE_KB=1 PTHREAD_TRACE_PATH=$trace "$target" "$@" 2>&1 | tee >(cat - >&5)) | ||
PTHREAD_TRACE_BUFFER_SIZE_KB=1 PTHREAD_TRACE_PATH=$trace "$target" "$@" | ||
|
||
echo "$output" | grep "pthread_trace: Recorded.*KB trace" > /dev/null || fail "Did not find pthread_trace report in output" | ||
$is_perfetto_trace $trace || fail "ERROR: $trace is not a valid perfetto trace" |
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