Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Fix terminal size at 80x24, write bzip2'ed ttyrecs #97

Merged
merged 3 commits into from
Oct 21, 2020

Conversation

heiner
Copy link
Contributor

@heiner heiner commented Oct 21, 2020

  • Setting the terminal size makes sure our ttyrecs will be 80x24, which is both the minimum size and the size of the majority of ttyrecs on alt.org
  • Writing bzip2'd ttyrecs should save up to 80% of disk space. Only downside is that we can no longer peek into running ttyrecs this way, which was sometimes useful for debugging. To go back to that mode, we can #undefine NLE_BZ2_TTYRECS.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 21, 2020
@heiner heiner force-pushed the terminal-ttyrec-stuff branch 2 times, most recently from 79d2da8 to fdb89d4 Compare October 21, 2020 11:33
Heinrich Kuttler added 2 commits October 21, 2020 13:38
This saves a lot of space (ttyrecs compress by 80%+). Only downside
is that we can no longer peek into running ttyrecs this way, which
was sometimes useful for debugging. To go back to that mode, we
can #undefine NLE_BZ2_TTYRECS.
Copy link
Contributor

@cdmatters cdmatters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me (the odd nit) but I wish there was a test. :(. A bit of a pain to do, I will try to run by hand to verify.

@@ -139,7 +139,7 @@
#define TIMED_DELAY
#endif

/* #define AVOID_WIN_IOCTL */ /* ensure USE_WIN_IOCTL remains undefined */
#define AVOID_WIN_IOCTL /* ensure USE_WIN_IOCTL remains undefined */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment could probably be added to, to help future clarity.

Suggested change
#define AVOID_WIN_IOCTL /* ensure USE_WIN_IOCTL remains undefined */
/*
* ensure USE_WIN_IOCTL remains undefined
* USE_WIN_IOCTL can set LI and CO global variables for terminal size, which we fix in nle.c
*/
#define AVOID_WIN_IOCTL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting of the comment can obvs change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where you're coming from, but I'd like to stick with the policy of not unduly changing the original NetHack source files, and this is one of them.

Comment on lines +26 to +29
#ifdef NLE_BZ2_TTYRECS
void *ttyrec_bz2;
#endif

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef NLE_BZ2_TTYRECS
void *ttyrec_bz2;
#endif
#ifdef NLE_BZ2_TTYRECS
void *ttyrec_bz2;
#else
FILE *ttyrec;
#endif

I'm curious: why aren't we doing ^^^ ? We never write to the file if the macro is set. Do we not just run the risk of confusion by keeping this pointer around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Who exactly is responsible for this FILE is a bit of a tricky question. For now, I'd like to keep it around for debugging and to allow flushing (although we don't do that currently).

src/nle.c Show resolved Hide resolved
@@ -201,7 +201,7 @@ def __init__(

if self.savedir:
self._ttyrec_pattern = os.path.join(
self.savedir, "nle.%i.%%i.ttyrec" % os.getpid()
self.savedir, "nle.%i.%%i.ttyrec.bz2" % os.getpid()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pid is always going to be unique within the folder? Are we saving all ttyrecs to there or only the last N?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we are either saving all ttyrecs or none.

The pid is going to be the process id of the user's process which won't be reassigned until that process stops.

@@ -31,6 +34,12 @@ init_nle(FILE *ttyrec)
assert(ttyrec != NULL);
nle->ttyrec = ttyrec;

#ifdef NLE_BZ2_TTYRECS
int bzerror;
nle->ttyrec_bz2 = BZ2_bzWriteOpen(&bzerror, ttyrec, 9, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the 9?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heiner heiner merged commit db18df0 into master Oct 21, 2020
@heiner heiner deleted the terminal-ttyrec-stuff branch October 21, 2020 13:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants