Skip to content

measure runtime by method #37

@jackfreed

Description

@jackfreed

Hi all,

i would like to measure the runtimes each call is taking and group it by the jsonrpc method using the following code:

func handleRequest(ctx context.Context, rc io.ReadCloser) bytes.Buffer {
	var res bytes.Buffer

	codec := jsonrpc2.NewServerCodecContext(ctx, struct {
		io.ReadCloser
		io.Writer
	}{
		rc,
		&res,
	}, nil)

	err := rpc.ServeRequest(codec)
	if err != nil {
		log.WithError(err).Error("rpc.ServeRequest")
	}

	fmt.Printf("%+v\n", codec)

	return res
}

the data i am looking for is already in the "codec" variable after rpc.ServeRequest:

&{encmutex:{state:0 sema:0} dec:0xc00157fce0 enc:0xc004b47540 c:{ReadCloser:{Reader:0xc00137b8c0} Writer:0xc00137b8f0} srv:0xc0000ec140 ctx:0xc00137b7d0 req:{Version:2.0 Method:System.Hello Params:0xc0053867e0 ID:} mutex:{state:0 sema:0} seq:1 pending:map[]

but i am unable to access it due to "req" not being exported.

Is there really no other way but to decode the json a second time just to get the method name?

Many thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions