Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for profiling #332

Merged
merged 4 commits into from
Jul 16, 2018
Merged

Add support for profiling #332

merged 4 commits into from
Jul 16, 2018

Conversation

mrkkrp
Copy link
Member

@mrkkrp mrkkrp commented Jul 11, 2018

This PR adds support for building things with profiling.

@mrkkrp mrkkrp requested review from judah and mboes July 11, 2018 12:30
@mboes
Copy link
Member

mboes commented Jul 11, 2018

Fixes #324. cc @iphydf

@mrkkrp
Copy link
Member Author

mrkkrp commented Jul 11, 2018

OK, 7 tests fail with profiling. I'll look into this.

@iphydf
Copy link

iphydf commented Jul 11, 2018

My @haskell_clock test doesn't seem to work with this, yet. I haven't tested on travis, but it doesn't work locally. https://github.com/iphydf/repro259 is still a valid repro for my issue (with -c dbg).

@mrkkrp
Copy link
Member Author

mrkkrp commented Jul 14, 2018

This is ready.

@@ -175,7 +174,36 @@ def _process_chs_file(hs, cc, ghc_defs_dump, chs_file, chi_files=[]):

return hs_out, chi_out, idir

def _compilation_defaults(hs, cc, java, dep_info, srcs, extra_srcs, cpp_defines, compiler_flags, main_file = None, my_pkg_id = None):
def _output_file_ext(base, dynamic, profiling_enabled):
Copy link
Member

Choose a reason for hiding this comment

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

I find this function doesn't pay its own way and could be more harmful than good. The cheap option is to construct the file name extensions manually every time: .p_o_dyn etc. It should prove more readable. Also your line breaking below won't need to be as ugly, because the declare_compiled stuff will fit on one line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes and no... I think it reduces the possibility of typos somewhat, but the main reason is the with_profiling argument. If we "inline" _output_file_ext (with some beta-reduction) there will be a lot of conditionals of the form:

"." + ("_p" if with_profiling else "") + "dyn_o"

Etc. which is not much better and definitely not shorter. I'd leave the function "as is".

(Well another option would be something like this: ".p_dyn_o" if with_profiling else ".dyn_o" which is typo-prone I think and not really shorter either.)

Copy link
Member

Choose a reason for hiding this comment

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

ok

java,
dep_info,
srcs = ctx.files.srcs,
# NOTE We must make the object files compiled without profiling
Copy link
Member

Choose a reason for hiding this comment

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

Or use -fext-external-interpreter, which I believe should resolve this kind of problem. See https://ghc.haskell.org/trac/ghc/wiki/RemoteGHCi. I'm surprised it's still not the default - we should pass that flag systematically if not.

Copy link
Member Author

Choose a reason for hiding this comment

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

You meant -fexternal-interpreter I think?

https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html?highlight=#ghc-flag--fexternal-interpreter

This looks good, although I'm not sure it makes sense to spend more time switching to that as I've already spent more hours than I expected to spend with this. Also, right now we're doing what Cabal is doing here. Of course Cabal works that way because it needs to support older GHC, but maybe there are other undiscovered issues with -fexternal-interpreter? CC @facundominguez, he mentioned something like "there may be issues with that".

Let's open an issue for the future and leave this "as is" so I can spend more time on client's stuff instead of re-working the working solution that replicates what Cabal does?

Copy link
Member

Choose a reason for hiding this comment

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

Subtleties like this in the codebase make me uncomfortable, because they'll trip us up at some point in the future. If it works, then we can keep it for now. But at a minimum, file a ticket and link to it from the code, so that people know to look out.

-fexternal-interpreter was introduced specifically to solve this problem. We don't have to, and shouldn't, replicate anything in Cabal that is just a historical workaround. If this flag introduces other issues, we should make our decisions based on specific references, not hypotheticals (e.g. https://ghc.haskell.org/trac/ghc/ticket/14335).

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #338.

@@ -212,8 +250,11 @@ def _compilation_defaults(hs, cc, java, dep_info, srcs, extra_srcs, cpp_defines,
args.add(compiler_flags)
haddock_args.add(compiler_flags, before_each="--optghc")

# Output static and dynamic object files.
args.add(["-static", "-dynamic-too"])
Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly this hack is a workaround to an upstream issue in GHC. It would be good to call that out explicitly, and to look to the relevant upstream issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if there is a ticket for this, actually. CC @hvr

Copy link
Member

Choose a reason for hiding this comment

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

Look for one and file if not.

Copy link
Member Author

Choose a reason for hiding this comment

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

After some searching, opened https://ghc.haskell.org/trac/ghc/ticket/15394 for now. Even if it's a dupe, we'll know that soon.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a note in the source too.

@mboes mboes merged commit 476653d into master Jul 16, 2018
@mboes mboes deleted the mk/support-profiling branch July 16, 2018 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants