* gc.c (getrusage_time): works only if RUSAGE_SELF is defined right

now.

* gc.c (gc_profile_result): C99.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-08-11 11:11:27 +00:00
parent 9295fd4b59
commit 35b6abbca2
2 changed files with 34 additions and 26 deletions

View File

@ -1,3 +1,10 @@
Mon Aug 11 20:11:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (getrusage_time): works only if RUSAGE_SELF is defined right
now.
* gc.c (gc_profile_result): C99.
Mon Aug 11 18:57:38 2008 Yukihiro Matsumoto <matz@ruby-lang.org> Mon Aug 11 18:57:38 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_sample): rename #choice to #sample. in * array.c (rb_ary_sample): rename #choice to #sample. in

53
gc.c
View File

@ -113,11 +113,15 @@ typedef struct gc_profile_record {
static double static double
getrusage_time(void) getrusage_time(void)
{ {
#ifdef RUSAGE_SELF
struct rusage usage; struct rusage usage;
struct timeval time; struct timeval time;
getrusage(RUSAGE_SELF, &usage); getrusage(RUSAGE_SELF, &usage);
time = usage.ru_utime; time = usage.ru_utime;
return time.tv_sec + time.tv_usec * 1e-6; return time.tv_sec + time.tv_usec * 1e-6;
#else
return 0.0;
#endif
} }
#define GC_PROF_TIMER_START do {\ #define GC_PROF_TIMER_START do {\
@ -142,7 +146,7 @@ getrusage_time(void)
#define GC_PROF_TIMER_STOP do {\ #define GC_PROF_TIMER_STOP do {\
if (objspace->profile.run) {\ if (objspace->profile.run) {\
gc_time = getrusage_time() - gc_time;\ gc_time = getrusage_time() - gc_time;\
if(gc_time < 0) gc_time = 0;\ if (gc_time < 0) gc_time = 0;\
objspace->profile.record[count].gc_time = gc_time;\ objspace->profile.record[count].gc_time = gc_time;\
objspace->profile.count++;\ objspace->profile.count++;\
}\ }\
@ -2705,43 +2709,40 @@ gc_profile_result(void)
{ {
rb_objspace_t *objspace = &rb_objspace; rb_objspace_t *objspace = &rb_objspace;
VALUE record = gc_profile_record_get(); VALUE record = gc_profile_record_get();
VALUE result = rb_str_new2(""); VALUE result;
int i; int i;
char buf[1024];
if(objspace->profile.run && objspace->profile.count) { if (objspace->profile.run && objspace->profile.count) {
sprintf(buf, "GC %1$d invokes.\n", NUM2INT(gc_count(0))); result = rb_sprintf("GC %1$d invokes.\n", NUM2INT(gc_count(0)));
rb_str_concat(result, rb_str_new2(buf)); rb_str_cat2(result, "Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC Time(ms)\n");
rb_str_concat(result, rb_str_new2("Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC Time(ms)\n")); for (i = 0; i < (int)RARRAY_LEN(record); i++) {
for(i = 0; i < (int)RARRAY_LEN(record); i++) {
memset(buf, 0, 1024);
VALUE r = RARRAY_PTR(record)[i]; VALUE r = RARRAY_PTR(record)[i];
sprintf(buf, "%1$5d %2$19.3f %3$20d %4$20d %5$20d %6$30.20f\n", rb_str_catf(result, "%1$5d %2$19.3f %3$20d %4$20d %5$20d %6$30.20f\n",
i+1, NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_INVOKE_TIME")))), i+1, NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_INVOKE_TIME")))),
NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SIZE")))), NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SIZE")))),
NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")))), NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")))),
NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")))), NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")))),
NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_TIME"))))*100); NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_TIME"))))*100);
rb_str_concat(result, rb_str_new2(buf));
} }
#if GC_PROFILE_MORE_DETAIL #if GC_PROFILE_MORE_DETAIL
rb_str_concat(result, rb_str_new2("\n\n")); rb_str_concat(result, rb_str_new2("\n\n"));
rb_str_concat(result, rb_str_new2("More detail.\n")); rb_str_concat(result, rb_str_new2("More detail.\n"));
rb_str_concat(result, rb_str_new2("Index Allocate Increase Allocate Limit Use Slot Have Finalize Mark Time(ms) Sweep Time(ms)\n")); rb_str_concat(result, rb_str_new2("Index Allocate Increase Allocate Limit Use Slot Have Finalize Mark Time(ms) Sweep Time(ms)\n"));
for(i = 0; i < (int)RARRAY_LEN(record); i++) { for (i = 0; i < (int)RARRAY_LEN(record); i++) {
memset(buf, 0, 1024);
VALUE r = RARRAY_PTR(record)[i]; VALUE r = RARRAY_PTR(record)[i];
sprintf(buf, "%1$5d %2$17d %3$17d %4$9d %5$14s %6$25.20f %7$25.20f\n", rb_str_catf(result, "%1$5d %2$17d %3$17d %4$9d %5$14s %6$25.20f %7$25.20f\n",
i+1, NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_INCREASE")))), i+1, NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_INCREASE")))),
NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_LIMIT")))), NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_LIMIT")))),
NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SLOTS")))), NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SLOTS")))),
rb_hash_aref(r, ID2SYM(rb_intern("HAVE_FINALIZE")))? "true" : "false", rb_hash_aref(r, ID2SYM(rb_intern("HAVE_FINALIZE")))? "true" : "false",
NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_MARK_TIME"))))*100, NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_MARK_TIME"))))*100,
NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_SWEEP_TIME"))))*100); NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_SWEEP_TIME"))))*100);
rb_str_concat(result, rb_str_new2(buf));
} }
#endif #endif
} }
else {
result = rb_str_new2("");
}
return result; return result;
} }