You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2018/04/26 16:39:34 UTC

[2/5] impala git commit: IMPALA-6913: Simple parser for Impala profile logs.

IMPALA-6913: Simple parser for Impala profile logs.

It's hard to find an example of how to parse the profiles in Impala test
logs, so I've added it to the bin/ directory. The parser's not
full-featured, but it may be useful to others. It handles three
common cases of Thrift-encoded profiles that we see.

Change-Id: Ib1174c65b002f9b71eccb0b56f875449f00eae39
Reviewed-on: http://gerrit.cloudera.org:8080/9265
Reviewed-by: Tim Armstrong <ta...@cloudera.com>
Reviewed-by: Bharath Vissapragada <bh...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/4f811988
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/4f811988
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/4f811988

Branch: refs/heads/2.x
Commit: 4f811988f2408a181d34fe31907072014bbeef74
Parents: 4c285b9
Author: Philip Zeyliger <ph...@cloudera.com>
Authored: Thu Feb 8 15:11:29 2018 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Thu Apr 26 04:33:16 2018 +0000

----------------------------------------------------------------------
 bin/parse-thrift-profile.py | 79 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/4f811988/bin/parse-thrift-profile.py
----------------------------------------------------------------------
diff --git a/bin/parse-thrift-profile.py b/bin/parse-thrift-profile.py
new file mode 100755
index 0000000..5f8485f
--- /dev/null
+++ b/bin/parse-thrift-profile.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env impala-python
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# Parses a base64-encoded profile provided via stdin. It accepts
+# three common formats:
+#
+# 1. Impala profile logs of the format
+#    "<ts> <queryid> <base64encoded, compressed thrift profile>"
+# 2. Just the base64-encoded compressed thrift profile
+# 3. Base-64 encoded uncompressed thrift profile.
+#
+# In all cases, the script expects one profile per line.
+#
+# For example:
+#
+# $ cat logs/cluster_test/custom_cluster_tests/profiles/impala_profile_log \
+#      | head -n 1 | awk '{ print $3 }' | parse-profile.py
+# TRuntimeProfileTree(nodes=[TRuntimeProfileNode(info_strings_display_order=....
+#
+# or
+#
+# $ bin/parse-thrift-profile.py logs/custom_cluster_tests/profiles/impala_profile_log_1.1-1523657191158
+# 2018-04-13T15:06:34.144000 e44af7f93edb8cd6:1b1f801600000000 TRuntimeProfileTree(nodes=[TRuntimeProf...
+
+
+from thrift.protocol import TCompactProtocol
+from thrift.TSerialization import deserialize
+from RuntimeProfile.ttypes import TRuntimeProfileTree
+
+import base64
+import datetime
+import sys
+import zlib
+
+if len(sys.argv) == 1 or sys.argv[1] == "-":
+  input_data = sys.stdin
+elif len(sys.argv) == 2:
+  input_data = file(sys.argv[1])
+else:
+  print >> sys.stderr, "Usage: %s [file]" % (sys.argv[0],)
+  sys.exit(1)
+
+for line in input_data:
+  space_separated = line.split(" ")
+  if len(space_separated) == 3:
+    ts = int(space_separated[0])
+    print datetime.datetime.fromtimestamp(ts/1000.0).isoformat(), space_separated[1],
+    base64_encoded = space_separated[2]
+  elif len(space_separated) == 1:
+    base64_encoded = space_separated[0]
+  else:
+    raise Exception("Unexpected line: " + line)
+  possibly_compressed = base64.b64decode(base64_encoded)
+  # Handle both compressed and uncompressed Thrift profiles
+  try:
+    thrift = zlib.decompress(possibly_compressed)
+  except zlib.error:
+    thrift = possibly_compressed
+
+  tree = TRuntimeProfileTree()
+  deserialize(tree, thrift, protocol_factory=TCompactProtocol.TCompactProtocolFactory())
+  tree.validate()
+  print tree