客户端记录响应反序列化大小和响应反序列化耗时

@param responseCommand 响应体
194619
private void recordDeserializeResponse(RpcResponseCommand responseCommand, InvokeContext invokeContext) {
        if (!RpcInternalContext.isAttachmentEnable()) {
            return;
        }
        RpcInternalContext context = null;
        if (invokeContext != null) {
            // 客户端异步调用的情况下，上下文会放在InvokeContext中传递
            context = invokeContext.get(RemotingConstants.INVOKE_CTX_RPC_CTX);
        }
        if (context == null) {
            context = RpcInternalContext.getContext();
        }
        int cost = context.getStopWatch().tick().read();
        int respSize = RpcProtocol.getResponseHeaderLength()
            + responseCommand.getClazzLength()
            + responseCommand.getContentLength()
            + responseCommand.getHeaderLength();
        // 记录响应反序列化大小和响应反序列化耗时
        context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE, respSize);
        context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_DESERIALIZE_TIME, cost);
    }
825900
function sendCommand(sensor, cmd)
{
    // commands need to be terminated with a carriage return
    cmd += "\r";
    sensor.writeDataStr(cmd);

    var resp = "";
    while (sensor.dataAvailable(2000))
    {
        resp += sensor.readDataStr(1024);
    }

    if (!resp) 
    {
        console.log("Timed out waiting for response");
    }
    else
    {
        resp = sensor.stringCR2LF(resp);
        console.log("Returned (" + resp.length + " bytes):");
        console.log(resp);
    }
}
1264329
function cmd(method, params, callback, streamResults, returnRawData){

        var results = [];

        async.each(instances, function(instance, eachCallback){

            var itemFinished = function(error, result, data){

                var returnObj = {
                    error: error,
                    response: (result || {}).result,
                    instance: instance
                };
                if (returnRawData) returnObj.data = data;
                if (streamResults) callback(returnObj);
                else results.push(returnObj);
                eachCallback();
                itemFinished = function(){};
            };

            var requestJson = JSON.stringify({
                method: method,
                params: params,
                id: Date.now() + Math.floor(Math.random() * 10)
            });

            performHttpRequest(instance, requestJson, function(error, result, data){
                itemFinished(error, result, data);
            });


        }, function(){
            if (!streamResults){
                callback(results);
            }
        });

    }
1000394
function(self, commands, result, callback) {
  // Base case when there are no more commands to serialize
  if (commands.length === 0) return callback(null, result);

  // Pop off the zeroth command and serialize it
  var thisCommand = commands.shift();
  var originalCommandBuffer = thisCommand.toBin();

  // Check whether we and the server have agreed to use a compressor
  if (self.options.agreedCompressor && !hasUncompressibleCommands(thisCommand)) {
    // Transform originalCommandBuffer into OP_COMPRESSED
    var concatenatedOriginalCommandBuffer = Buffer.concat(originalCommandBuffer);
    var messageToBeCompressed = concatenatedOriginalCommandBuffer.slice(MESSAGE_HEADER_SIZE);

    // Extract information needed for OP_COMPRESSED from the uncompressed message
    var originalCommandOpCode = concatenatedOriginalCommandBuffer.readInt32LE(12);

    // Compress the message body
    compress(self, messageToBeCompressed, function(err, compressedMessage) {
      if (err) return callback(err, null);

      // Create the msgHeader of OP_COMPRESSED
      var msgHeader = Buffer.alloc(MESSAGE_HEADER_SIZE);
      msgHeader.writeInt32LE(MESSAGE_HEADER_SIZE + 9 + compressedMessage.length, 0); // messageLength
      msgHeader.writeInt32LE(thisCommand.requestId, 4); // requestID
      msgHeader.writeInt32LE(0, 8); // responseTo (zero)
      msgHeader.writeInt32LE(opcodes.OP_COMPRESSED, 12); // opCode

      // Create the compression details of OP_COMPRESSED
      var compressionDetails = Buffer.alloc(9);
      compressionDetails.writeInt32LE(originalCommandOpCode, 0); // originalOpcode
      compressionDetails.writeInt32LE(messageToBeCompressed.length, 4); // Size of the uncompressed compressedMessage, excluding the MsgHeader
      compressionDetails.writeUInt8(compressorIDs[self.options.agreedCompressor], 8); // compressorID

      // Push the concatenation of the OP_COMPRESSED message onto results
      result.push(Buffer.concat([msgHeader, compressionDetails, compressedMessage]));

      // Continue recursing through the commands array
      serializeCommands(self, commands, result, callback);
    });
  } else {
    // Push the serialization of the command onto results
    result.push(originalCommandBuffer);

    // Continue recursing through the commands array
    serializeCommands(self, commands, result, callback);
  }
}
426959
protected void handleResponse(Object control) {
		byte[] result = (byte[]) invokeMethod("getCookie", responseControlClass, control);
        if(result == null) {
            more = false;
        }
		this.cookie = new PagedResultsCookie(result);
        this.resultSize = (Integer) invokeMethod("getResultSize", responseControlClass, control);
	}
10329
private void xcmdOvertureResponse(DBGPXCmdOvertureCommandType overtureCmd,
			StringBuilder hdr, StringBuilder body) throws IOException
	{
		StringBuilder sb = new StringBuilder();

		sb.append("<xcmd_overture_response command=\"");
		sb.append(command);
		sb.append("\"");

		sb.append(" overtureCmd=\"");
		sb.append(overtureCmd);
		sb.append("\"");

		if (hdr != null)
		{
			sb.append(" ");
			sb.append(hdr);
		}

		sb.append(" transaction_id=\"");
		sb.append(transaction);
		sb.append("\"");

		if (body != null)
		{
			sb.append(">");
			sb.append(body);
			sb.append("</xcmd_overture_response>\n");
		} else
		{
			sb.append("/>\n");
		}

		write(sb);
	}
737704
function send_command(command, cb) {
        var cmd = commands[command.toUpperCase()];
        if(parseInt(cmd)) {
            post('/roap/api/command', `<?xml version='1.0' encoding='utf-8'?><command><name>HandleKeyInput</name><value>${cmd}</value></command>`, (body) => {
                try {
                    var doc = new dom().parseFromString(body);
                    if(cb) cb(xpath.select('//ROAPErrorDetail/text()', doc).toString() == 'OK')
                } catch(error) {
                    log(`error send_command:  ${error.message}`)
                    if(cb) cb(false)
                }
            });
        }
    }
442131
protected static String runCommand (String cmd)
    {
        try {
            Process p = Runtime.getRuntime().exec(cmd);
            BufferedReader cin = new BufferedReader(new InputStreamReader(p.getInputStream()));
            StringBuilder buffer= new StringBuilder();

            String line = "";
            while (line != null)
            {
                buffer.append(line);
                line = cin.readLine();
            }
            cin.close();

            return buffer.toString();
        } catch (IOException e) {
            // don't want to log anything for the client to know what we are doing.
            // This will almost always be thrown/caught when the cmd isn't there.
            return null;
        }
    }
801409
public static void setHeader(HttpServletResponse response, String name, Object value) {
		if (value instanceof String) {
			response.setHeader(name, (String) value);
		} else if (Date.class.isAssignableFrom(value.getClass())) {
			response.setDateHeader(name, ((Date) value).getTime());
		} else if (value instanceof Integer || "int".equals(value.getClass().getSimpleName().toLowerCase())) {
			response.setIntHeader(name, (Integer) value);
		} else {
			response.setHeader(name, value.toString());
		}
	}
198224
public static void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    String handler = getHandler(request);
    if (handler.startsWith(COMMAND_PATH)) {
      if (!checkForAjax(request, response)) {
        return;
      }
      StatusHandler.handleCommand(handler.substring(COMMAND_PATH.length() + 1), request, response);
    } else {
      handleStaticResources(handler, response);
    }
  }
59788
public void queryService(List<StringCommand> commands, final QueryServiceCallback cb, Object context){
        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.QueryService);

        List<QueryCommand> cs = new ArrayList<QueryCommand>();
        for(StringCommand c : commands){
            cs.add(c.getStringCommand());
        }

        QueryServiceProtocol p = new QueryServiceProtocol(cs);

        ProtocolCallback pcb = new ProtocolCallback(){

            @Override
            public void call(boolean result, Response response,
                    ErrorCode error, Object ctx) {
                List<ModelServiceInstance> rsp = null;
                if(response != null){
                    rsp = ((QueryServiceResponse) response).getInstances();
                }
                cb.call(result, rsp, error, ctx);
            }

        };

        connection.submitCallbackRequest(header, p, pcb, context);
    }
537190
public void setResponse(byte[] contentType, byte[] value) {
        int valueSize = (value == null) ? 0 : value.length;
        byte[] len = stringToBytes(String.valueOf(valueSize));
        int size = RES_200.length;
        if (contentType != null) {
            size += CONTENT_TYPE.length;
            size += contentType.length;
            size += TextCommandConstants.RETURN.length;
        }
        size += CONTENT_LENGTH.length;
        size += len.length;
        size += TextCommandConstants.RETURN.length;
        size += TextCommandConstants.RETURN.length;
        size += valueSize;
        this.response = ByteBuffer.allocate(size);
        response.put(RES_200);
        if (contentType != null) {
            response.put(CONTENT_TYPE);
            response.put(contentType);
            response.put(TextCommandConstants.RETURN);
        }
        response.put(CONTENT_LENGTH);
        response.put(len);
        response.put(TextCommandConstants.RETURN);
        response.put(TextCommandConstants.RETURN);
        if (value != null) {
            response.put(value);
        }
        response.flip();
    }
554487
private void respond(BufferedWriter out, String response) throws IOException {
        out.append(response);
        out.append("\n");
        out.flush();
    }
844189
public void writeCommand(Command command) throws Exception {

        checkConnected();

        switch (command.getKind()) {
        case PREPARE:
            writeCommand((PrepareCommand) command);
            break;
        case START:
            writeCommand((StartCommand) command);
            break;
        case ABORT:
            writeCommand((AbortCommand) command);
            break;
        case AWAIT:
            writeCommand((AwaitCommand) command);
            break;
        case NOTIFY:
            writeCommand((NotifyCommand) command);
            break;
        case CLOSE:
            writeCommand((CloseCommand) command);
            break;
        default:
            throw new IllegalArgumentException("Urecognized command kind: " + command.getKind());
        }
    }
393651
function queryCommandValue(command) {
        var func;

        if (editor.quirks.isHidden() || editor.removed) {
          return;
        }

        command = command.toLowerCase();
        if ((func = commands.value[command])) {
          return func(command);
        }

        // Browser commands
        try {
          return editor.getDoc().queryCommandValue(command);
        } catch (ex) {
          // Fails sometimes see bug: 1896577
        }
      }
52327
String doHandleCommand(final String command) {
        app.handleCommand(command);
        final String output = buffer.toString();
        buffer.setLength(0);
        return output;
    }
917975
function decoded(err, reply) {
  //console.error('got decoder err %s', err );
  //console.error('got decoder reply %j',reply );
  var res = new Response(this), req, cmd, args;
  if(err) {
    // return decoder errors to the client
    return res.send(err);
  }

  // we should only be handling array request types
  if(!Array.isArray(reply)) {
    return res.send(new Error('bad request, array expected'));
  }else if(!reply.length) {
    return res.send(new Error('bad request, empty array invalid'));
  }

  cmd = reply.shift();

  if(cmd instanceof Buffer) cmd = cmd.toString();

  if(typeof cmd !== 'string') {
    return res.send(new Error('bad request, string command expected'));
  }

  cmd = cmd.toLowerCase();

  // keep track of last command
  this._client.cmd = cmd;

  //console.error('got decoder cmd %s', cmd );
  //console.error('got decoder args %j', reply );

  req = new Request(this, cmd, reply);

  this.emit('command', req, res);
}