mkatanbaf commented on code in PR #10967:
URL: https://github.com/apache/tvm/pull/10967#discussion_r852332550


##########
src/runtime/minrpc/minrpc_logger.h:
##########
@@ -0,0 +1,219 @@
+/*
+ * 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.
+ */
+
+#ifndef TVM_RUNTIME_MINRPC_MINRPC_LOGGER_H_
+#define TVM_RUNTIME_MINRPC_MINRPC_LOGGER_H_
+
+#include <tvm/runtime/c_runtime_api.h>
+
+#include <functional>
+#include <sstream>
+#include <string>
+#include <unordered_map>
+
+#include "minrpc_intrfc.h"
+#include "rpc_reference.h"
+
+namespace tvm {
+namespace runtime {
+
+#define PRINT_BYTES false
+
+/*!
+ * \brief Generates a user readeable log on the console
+ */
+class Logger {
+ public:
+  Logger() {}
+
+  void LogString(const char* s) { os_ << s; }
+
+  void LogStr(std::string s) { os_ << s; }
+
+  template <typename T>
+  void LogVal(const char* s, T val) {
+    os_ << s << val;
+  }
+
+  void LogDLDevice(const char* s, DLDevice* dev) {
+    os_ << s << "(" << dev->device_type << "," << dev->device_id << ")";
+  }
+
+  void LogDLData(const char* s, DLDataType* data) {
+    os_ << s << "(" << (uint16_t)data->code << "," << (uint16_t)data->bits << 
"," << data->lanes
+        << ")";
+  }
+
+  void LogHandleName(std::string name) {
+    if (name.length() > 0) {
+      os_ << " <" << name.c_str() << ">";
+    }
+  }
+
+  std::stringstream LogTime();
+  void LogTVMValue(int tcode, TVMValue value);
+  void OutputLog();
+
+ private:
+  std::stringstream os_;
+};
+
+/*!
+ * \brief A wrapper for a MinRPCReturns object, that also logs the responses.
+ *
+ * \tparam ReturnInterface* underlying MinRPCReturns that generates the 
responses.
+ */
+class MinRPCReturnsWithLog : public ReturnInterface {
+ public:
+  /*!
+   * \brief Constructor.
+   * \param io The IO handler.
+   */
+  explicit MinRPCReturnsWithLog(ReturnInterface* next) : next_(next), 
logger_() {}
+
+  ~MinRPCReturnsWithLog() {}
+
+  void ReturnVoid();
+
+  void ReturnHandle(void* handle);
+
+  void ReturnException(const char* msg);
+
+  void ReturnPackedSeq(const TVMValue* arg_values, const int* type_codes, int 
num_args);
+
+  void ReturnCopyAck(uint64_t* num_bytes, uint8_t** data_ptr);
+
+  void ReturnLastTVMError();
+
+  void ThrowError(RPCServerStatus code, RPCCode info = RPCCode::kNone);
+
+  void processValues(const TVMValue** values, const int** tcodes, int* 
num_args);
+
+  void resetCurrHandleName(RPCCode code);
+
+  void updateCurrHandleName(const char* name);
+
+  void getHandleName(void* handle);
+
+  void releaseHandleName(void* handle);
+
+  Logger* getLogger() { return &logger_; }
+
+ private:
+  void registerHandleName(void* handle);

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to