public String toBinaryString() throws IOException {
    org.apache.hadoop.hive.ql.plan.api.Query q = getQueryPlan();
    try {
      TMemoryBuffer tmb = new TMemoryBuffer(q.toString().length() * 5);
      TBinaryProtocol oprot = new TBinaryProtocol(tmb);
      q.write(oprot);
      byte[] buf = new byte[tmb.length()];
      tmb.read(buf, 0, tmb.length());
      return new String(buf);
    } catch (TException e) {
      LOG.warn("Unable to produce query plan binary string", e);
      return q.toString();
    }
  }
Extract all the counters from tasks and operators.
ql/src/java/org/apache/hadoop/hive/ql/QueryPlan.java