Feature #5291

Enabling GC Profiler GC_PROFILE_MORE_DETAIL and CALC_EXACT_MALLOC_SIZE

Added by Charlie Savage over 2 years ago. Updated over 2 years ago.

[ruby-core:39326]
Status:Closed
Priority:Normal
Assignee:-
Category:core
Target version:1.9.3

Description

I would like to hook ruby-prof into the new GC profiler. However, by default a lot of the profile stats are disabled by these two defines in gcc.c.

#define GCPROFILEMOREDETAIL 0
#define CALC
EXACTMALLOCSIZE 0

To turn on these stats, you have to modify the ruby source code! That is a high barrier for most people.

So would it be possible to:

  • Set them to 1 by default. Or would this be too much of a performance hit?

  • or -

  • Remove the lines entirely and then change the logic in the file from this:

#if GCPROFILEMORE_DETAIL

To this:

#if defined?(GCPROFILEMORE_DETAIL)

Then when buildig Ruby you could tell the compiler to define the symbols (-DGCPROFILEMORE_DETAIL).

  • or -

  • Add these two defines to the ./configure script so they end up in config.h. That would make it easy for users to enable them if they wish, and would be also allow ruby-prof to use them too.

Would a patch be accepted to do this?

Associated revisions

Revision 33243
Added by Koichi Sasada over 2 years ago

  • gc.c (GCPROFILEMOREDETAIL, CALCEXACTMALLOCSIZE): define macros only if they are not defined. fixes: [Ruby 1.9 - Feature #5291]

History

#1 Updated by Eric Wong over 2 years ago

Charlie Savage cfis@savagexi.com wrote:

#define CALCEXACTMALLOC_SIZE 0

I tried flipping this a few months back in trunk but didn't have time to
investigate what went wrong when I did. I'm not sure how much people
care for it or if it's even maintained/tested by anyone (I'm not sure
I care).

I have found (and helped fix at least one) 3rd-party extensions that had
an issue with this (due to a x*alloc() paired with a regular free() or
vice-versa). So I suspect this is a common (but currently non-fatal)
bug in other extensions, too.

Anyways, several (most?) malloc implementations support
mallocusablesize() (or similar) and have various hooks that could be
used to instrument malloc. Unfortunately the various extensions I know
of aren't compatible with each other (dlmalloc/ptmalloc, tcmalloc,
jemalloc).

#2 Updated by Charlie Savage over 2 years ago

FYI, pairing a xalloc with a free can be fatal on windows depending on how Ruby is built (mingw is safe, VC++ isn't) and what runtime c libaries are used. See the "Caution" note at the bottom of:

http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=vs.71%29.aspx

Thanks for fixing them!

#3 Updated by Koichi Sasada over 2 years ago

(2011/09/06 23:04), Charlie Savage wrote:

FYI, pairing a xalloc with a free can be fatal on windows depending on how Ruby is built (mingw is safe, VC++ isn't) and what runtime c libaries are used. See the "Caution" note at the bottom of:

Good point. This measurements can check such errors :P

--
// SASADA Koichi at atdot dot net

#4 Updated by Koichi Sasada over 2 years ago

(2011/09/06 22:05), Charlie Savage wrote:

Issue #5291 has been reported by Charlie Savage.


Feature #5291: Enabling GC Profiler GCPROFILEMOREDETAIL and CALCEXACTMALLOCSIZE
http://redmine.ruby-lang.org/issues/5291

Author: Charlie Savage
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: 1.9.3

I would like to hook ruby-prof into the new GC profiler. However, by default a lot of the profile stats are disabled by these two defines in gcc.c.

#define GCPROFILEMOREDETAIL 0
#define CALC
EXACTMALLOCSIZE 0

To turn on these stats, you have to modify the ruby source code! That is a high barrier for most people.

So would it be possible to:

  • Set them to 1 by default. Or would this be too much of a performance hit?

  • or -

  • Remove the lines entirely and then change the logic in the file from this:

#if GCPROFILEMORE_DETAIL

To this:

#if defined?(GCPROFILEMORE_DETAIL)

Then when buildig Ruby you could tell the compiler to define the symbols (-DGCPROFILEMORE_DETAIL).

  • or -

  • Add these two defines to the ./configure script so they end up in config.h. That would make it easy for users to enable them if they wish, and would be also allow ruby-prof to use them too.

Would a patch be accepted to do this?

How about it?

Index: gc.c
===================================================================
--- gc.c (revision 33165)
+++ gc.c (working copy)
@@ -93,7 +93,10 @@
int rubygcdebug_indent = 0;

/* for GC profile */
+#ifndef GCPROFILEMOREDETAIL
#define GC
PROFILEMOREDETAIL 0
+#endif
+
typedef struct gcprofilerecord {
double gctime;
double gc
marktime;
@@ -309,7 +312,9 @@
struct gc
list *next;
};

+#ifndef CALCEXACTMALLOCSIZE
#define CALC
EXACTMALLOCSIZE 0
+#endif

typedef struct rb_objspace {
struct {

--
// SASADA Koichi at atdot dot net

#5 Updated by Charlie Savage over 2 years ago

Yes, that would be much better. Is it too late for this to be part of 1.9.3?

Thank you!

Charlie

#6 Updated by Koichi Sasada over 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r33243.
Charlie, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • gc.c (GCPROFILEMOREDETAIL, CALCEXACTMALLOCSIZE): define macros only if they are not defined. fixes: [Ruby 1.9 - Feature #5291]

Also available in: Atom PDF