Opened 7 years ago

Closed 7 years ago

#4512 closed bug (fixed)

EventLog does not play well with forkProcess

Reported by: adept Owned by: simonmar
Priority: high Milestone: 7.0.2
Component: Runtime System Version: 7.0.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I am trying to see an eventlog of process that daemonizes itself via forkProcess.

Unfortunately, as parent process dies, he writes out his eventlog (or at least a header part, I haven't checked exactly), and eventlog of the child process is then appended to the same file.

As a result, neither ghc-events nor threadscope is able to read the eventlog file.

I've modified the program so that it would not fork, and generated "good" eventlog. I'm attaching it and "bad" eventlog as well so you can see the difference by yourself.

Perhaps "+RTS -ls" could write output to filename that includes the PID of the process, like "program.$PID.eventlog"?

Attachments (3)

good.eventlog (2.0 KB) - added by adept 7 years ago.
Good eventlog from modified version of the program that does not fork
bad.eventlog (3.9 KB) - added by adept 7 years ago.
Bad eventlog from the version that uses forkProcess
4512.bundle (13.9 KB) - added by adept 7 years ago.
Reopening eventlog after fork()

Download all attachments as: .zip

Change History (11)

Changed 7 years ago by adept

Attachment: good.eventlog added

Good eventlog from modified version of the program that does not fork

Changed 7 years ago by adept

Attachment: bad.eventlog added

Bad eventlog from the version that uses forkProcess

comment:1 Changed 7 years ago by igloo

Milestone: 7.0.2
Priority: normalhigh

comment:2 Changed 7 years ago by adept

Owner: set to adept

Well, here is a plan: when forked child process does initEventLogging, it should detect that prog_name.evenlog is already opened and being written to by another process.

It could be done with: 1)OS locks 2)file-based locking (*.pid files or something similar) 3)using "static int alreadyWriting", which would be populated by parent process.

I'm inclined to go with (3). Forked child will check to see whether parent process is alreadyWriting and will use different filename if necessary.

Comments?

comment:3 Changed 7 years ago by adept

Status: newpatch

Attached patch fixes the problem. Please review.

Changed 7 years ago by adept

Attachment: 4512.bundle added

Reopening eventlog after fork()

comment:4 in reply to:  3 Changed 7 years ago by simonmar

Owner: changed from adept to simonmar

Replying to adept:

Attached patch fixes the problem. Please review.

Looks fine. I'll validate and push.

comment:5 Changed 7 years ago by simonmar

Status: patchmerge

Thanks, pushed:

Fri Dec  3 13:39:50 GMT 2010  Dmitry Astapov <dastapov@gmail.com>
  * Fixes for #4512: EventLog.c - provides ability to terminate event logging, Schedule.c - uses them in forkProcess.

comment:6 Changed 7 years ago by simonmar

A couple more fixes were required to this patch:

Fri Dec 10 09:39:06 GMT 2010  Simon Marlow <marlowsd@gmail.com>
  * allocate enough room for the longer filename (addendum to #4512)

Fri Dec 10 09:39:51 GMT 2010  Simon Marlow <marlowsd@gmail.com>
  * Only reset the event log if logging is turned on (addendum to #4512)

comment:7 Changed 7 years ago by igloo

First merged.

comment:8 Changed 7 years ago by igloo

Resolution: fixed
Status: mergeclosed

Last 2 also merged.

Note: See TracTickets for help on using tickets.