Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] test: rewrite sysprof test using managed execution
Date: Tue, 5 Dec 2023 12:59:01 +0000	[thread overview]
Message-ID: <ZW8elZf1WILNTXRL@tarantool.org> (raw)
In-Reply-To: <ZW8Wnb-7zCk10FZi@root>

Sergey,

On 05.12.23, Sergey Kaplun wrote:
> Hi, Igor!
> Thanks for the fixes!
> Please, consider my comments below.
> 

<snipped>

> 
> > 
> > > 
> > > > > +#define STREAM_BUFFER_SIZE (8 * 1024 * 1024)
> > > > > +#define DEVNULL -1
> > > 
> > > `DEVNULL` name is misleading (like we've actually opened `/dev/null`).
> > > Maybe `DUMMY_FD` is better? Also, I suppose we can drop the `fd` field
> > > at all. We can just use static structure in this translation unit and
> > > compare pointer against it, so there is no need for an additional field
> > > fd in the structure itself.
> > 
> > I see little reasoning in this suggestion: the approach with the
> > structure is quite straight-forward and copied from another sysprof test
> > implemented in C. Re naming: I prefer to leave it as is.
> 
> I don't get why it is straight-forward. This approach with unused fields
> is just misleading. In
> <test/tarantool-c-tests/misclib-sysprof-capi.test.c> the `fd` field is
> used since the "/dev/null" is opened and data written to it.
> 
> Also, since we can use custom writer, that test may be updated wo using
> `fd` too. But this should be done as a separate refactoring patch.
> 
> > 
> > In general, your nit is nice, but I believe it should be applied
> > for the patch moving <ptrace> tricks to utils library.
> 
> I don't see any relations with ptrace here. It's just the usage of
> sysprof's C API.

Well, I've finally got your original idea. Here it is:

================================================================================

diff --git a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
index 6bf7562f..8967abc4 100644
--- a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
+++ b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
@@ -53,35 +53,26 @@
 extern void *lj_ff_tostring(void);
 extern void *lj_fff_res1(void);
 
-/* Sysprof "/dev/null" stream helpers. {{{ */
+/* Sysprof dummy stream helpers. {{{ */
 
 /*
  * Yep, 8Mb. Tuned in order not to bother the platform with too
  * often flushes.
  */
 #define STREAM_BUFFER_SIZE (8 * 1024 * 1024)
-#define DEVNULL -1
 
-struct devnull_ctx {
-	/*
-	 * XXX: Dummy file descriptor to be used as "/dev/null"
-	 * context indicator in writer and on_stop callback.
-	 */
-	int fd;
+struct dummy_ctx {
 	/* Buffer for data recorded by sysprof. */
 	uint8_t buf[STREAM_BUFFER_SIZE];
 };
 
+static struct dummy_ctx context;
+
 static int stream_new(struct luam_Sysprof_Options *options)
 {
-	struct devnull_ctx *ctx = calloc(1, sizeof(struct devnull_ctx));
-	if (ctx == NULL)
-		return PROFILE_ERRIO;
-
-	/* Set "/dev/null" context indicator. */
-	ctx->fd = DEVNULL;
-	options->ctx = ctx;
-	options->buf = ctx->buf;
+	/* Set dummy context. */
+	options->ctx = &context;
+	options->buf = (uint8_t *)&context.buf;
 	options->len = STREAM_BUFFER_SIZE;
 
 	return PROFILE_SUCCESS;
@@ -89,21 +80,19 @@ static int stream_new(struct luam_Sysprof_Options *options)
 
 static int stream_delete(void *rawctx, uint8_t *buf)
 {
-	struct devnull_ctx *ctx = rawctx;
-	assert(ctx->fd == DEVNULL);
-	free(ctx);
+	assert(rawctx == &context);
+	/* XXX: No need to release context memory. Just return. */
 	return PROFILE_SUCCESS;
 }
 
 static size_t stream_writer(const void **buf_addr, size_t len, void *rawctx)
 {
-	struct devnull_ctx *ctx = rawctx;
-	assert(ctx->fd == DEVNULL);
+	assert(rawctx == &context);
 	/* Do nothing, just return back to the profiler. */
 	return STREAM_BUFFER_SIZE;
 }
 
-/* }}} Sysprof "/dev/null" stream helpers. */
+/* }}} Sysprof dummy stream helpers. */
 
 static int tracee(const char *luacode)
 {

================================================================================

> 

<snipped>

> 
> > > 
> > > Typo: s/<lj_fff_res1>/the <lj_fff_res1>/
> > > 
> > > > > +	 * FIXME: Make this part test agnostic.
> > > 
> > > Typo: s/test agnostic/test-agnostic/
> > > 
> > > Nit: TODO looks more valid for me (since it's working).
> > > Feel free to ignore.
> > 
> > Fixed.
> > 
> > ================================================================================
> > 
> > diff --git a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
> > index 44421812..036f8141 100644
> > --- a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
> > +++ b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
> > @@ -153,8 +153,8 @@ static int tracee(const char *luacode)
> >  
> >  	/*
> >  	 * XXX: The only event to be streamed must be FFUNC at
> > -	 * <lj_fff_res1> instruction.
> > -	 * FIXME: Make this part test agnostic.
> > +	 * the <lj_fff_res1> instruction.
> > +	 * TODO: Make this part test agnostic.
> 
> Typo: s/test agnostic/test-agnostic/

Fixed (again).

================================================================================

diff --git a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
index 8967abc4..a1c4a3ed 100644
--- a/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
+++ b/test/tarantool-c-tests/gh-8594-sysprof-ffunc-crash.test.c
@@ -143,7 +143,7 @@ static int tracee(const char *luacode)
 	/*
 	 * XXX: The only event to be streamed must be FFUNC at
 	 * the <lj_fff_res1> instruction.
-	 * TODO: Make this part test agnostic.
+	 * TODO: Make this part test-agnostic.
 	 */
 	assert(luaM_sysprof_report(&counters) == PROFILE_SUCCESS);
 	assert(counters.samples == 1);

================================================================================

> 

<snipped>

> > > -- 
> > > Best regards,
> > > Sergey Kaplun
> > 
> > -- 
> > Best regards,
> > IM
> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM

  reply	other threads:[~2023-12-05 12:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28 14:53 [Tarantool-patches] [PATCH luajit 0/2] Use ptrace for sysprof tests Igor Munkin via Tarantool-patches
2023-11-28 14:53 ` [Tarantool-patches] [PATCH luajit 1/2] test: disable buffering for the C test engine Igor Munkin via Tarantool-patches
2023-12-03 12:25   ` Maxim Kokryashkin via Tarantool-patches
2023-12-04  9:48     ` Igor Munkin via Tarantool-patches
2023-12-04  8:46   ` Sergey Kaplun via Tarantool-patches
2023-12-04  9:50     ` Igor Munkin via Tarantool-patches
2023-11-28 14:53 ` [Tarantool-patches] [PATCH luajit 2/2] test: rewrite sysprof test using managed execution Igor Munkin via Tarantool-patches
2023-12-03 14:17   ` Maxim Kokryashkin via Tarantool-patches
2023-12-05  8:37     ` Sergey Kaplun via Tarantool-patches
2023-12-05 12:04       ` Igor Munkin via Tarantool-patches
2023-12-05 12:25         ` Sergey Kaplun via Tarantool-patches
2023-12-05 12:59           ` Igor Munkin via Tarantool-patches [this message]
2023-12-05 15:08             ` Sergey Kaplun via Tarantool-patches
2023-12-05 11:34     ` Igor Munkin via Tarantool-patches
2023-12-05 13:23       ` Maxim Kokryashkin via Tarantool-patches
2023-11-28 16:14 ` [Tarantool-patches] [PATCH luajit 0/2] Use ptrace for sysprof tests Sergey Bronnikov via Tarantool-patches
2024-01-10  8:50 ` Igor Munkin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZW8elZf1WILNTXRL@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 2/2] test: rewrite sysprof test using managed execution' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox