decode_packet_trace.py (12212:1ae8dc8fdb97) | decode_packet_trace.py (12213:e0083524df0c) |
---|---|
1#!/usr/bin/env python2 2 3# Copyright (c) 2013-2014 ARM Limited 4# All rights reserved 5# 6# The license below extends only to copyright in the software and shall 7# not be construed as granting a license to any other intellectual 8# property including but not limited to intellectual property relating --- 24 unchanged lines hidden (view full) --- 33# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37# 38# Authors: Andreas Hansson 39 40# This script is used to dump protobuf packet traces to ASCII | 1#!/usr/bin/env python2 2 3# Copyright (c) 2013-2014 ARM Limited 4# All rights reserved 5# 6# The license below extends only to copyright in the software and shall 7# not be construed as granting a license to any other intellectual 8# property including but not limited to intellectual property relating --- 24 unchanged lines hidden (view full) --- 33# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37# 38# Authors: Andreas Hansson 39 40# This script is used to dump protobuf packet traces to ASCII |
41# format. It assumes that protoc has been executed and already 42# generated the Python package for the packet messages. This can 43# be done manually using: 44# protoc --python_out=. --proto_path=src/proto src/proto/packet.proto 45# 46# The ASCII trace format uses one line per request on the format cmd, 47# addr, size, tick,flags. For example: 48# r,128,64,4000,0 49# w,232123,64,500000,0 | 41# format. |
50 | 42 |
43import os |
|
51import protolib | 44import protolib |
45import subprocess |
|
52import sys 53 | 46import sys 47 |
54# Import the packet proto definitions. If they are not found, attempt 55# to generate them automatically. 56try: 57 import packet_pb2 58except: 59 print "Did not find packet proto definitions, attempting to generate" 60 import os 61 util_dir = os.path.dirname(os.path.realpath(__file__)) 62 proto_dir = os.path.join(os.path.dirname(util_dir), 'src', 'proto') 63 proto_file = os.path.join(proto_dir, 'packet.proto') 64 from subprocess import call 65 error = call(['protoc', '--python_out=' + util_dir, 66 '--proto_path=' + proto_dir, proto_file]) 67 if not error: 68 print "Generated packet proto definitions" | 48util_dir = os.path.dirname(os.path.realpath(__file__)) 49# Make sure the proto definitions are up to date. 50subprocess.check_call(['make', '--quiet', '-C', util_dir, 'packet_pb2.py']) 51import packet_pb2 |
69 | 52 |
70 try: 71 import google.protobuf 72 except: 73 print "Please install Python protobuf module" 74 exit(-1) 75 76 import packet_pb2 77 else: 78 print "Failed to import packet proto definitions" 79 exit(-1) 80 | |
81def main(): 82 if len(sys.argv) != 3: 83 print "Usage: ", sys.argv[0], " <protobuf input> <ASCII output>" 84 exit(-1) 85 86 # Open the file in read mode 87 proto_in = protolib.openFileRd(sys.argv[1]) 88 --- 56 unchanged lines hidden --- | 53def main(): 54 if len(sys.argv) != 3: 55 print "Usage: ", sys.argv[0], " <protobuf input> <ASCII output>" 56 exit(-1) 57 58 # Open the file in read mode 59 proto_in = protolib.openFileRd(sys.argv[1]) 60 --- 56 unchanged lines hidden --- |