الفرق بين المراجعتين ل"Ruby/GC::Profiler"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب' <noinclude>{{DISPLAYTITLE: منشئ ملفات تعريف جمع البيانات المهملة (GC::Profiler) في روبي}}</noinclude> = منشئ ملفات تع...')
 
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: منشئ ملفات تعريف جمع البيانات المهملة (GC::Profiler) في روبي}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: منشئ ملفات تعريف جمع البيانات المهملة (GC::Profiler) في روبي}}</noinclude>يوفر مُنشئ ملفات تعريف جمع البيانات المهملة <code>GC::Profiler</code> الوصول إلى معلومات عن تشغيلات GC بما في ذلك الوقت والطول وحجم مساحة الكائن.
  
= منشئ ملفات تعريف جمع البيانات المهملة (GC::Profiler) =
+
أمثلة:<syntaxhighlight lang="ruby">
يوفر مُنشئ ملفات تعريف جمع البيانات المهملة GC::Profiler الوصول إلى معلومات عن تشغيلات GC بما في ذلك الوقت والطول وحجم مساحة الكائن.
+
GC::Profiler.enable
 
+
require 'rdoc/rdoc'
أمثلة:
+
GC::Profiler.report
 
+
GC::Profiler.disable
انظر أيضًا GC.count و GC.malloc_allocated_size و GC.malloc_allocations
+
</syntaxhighlight>انظر أيضًا <code>GC.count</code> و <code>GC.malloc_allocated_size</code> و <code>GC.malloc_allocations</code>.
  
 
=== توابع الصنف العام ===
 
=== توابع الصنف العام ===
  
 
==== <code>GC::Profiler.clear → nil</code> ====
 
==== <code>GC::Profiler.clear → nil</code> ====
مسح بيانات مُنشئ ملفات تعريف GC.
+
مسح بيانات مُنشئ ملفات تعريف <code>[[Ruby/GC|GC]]</code>.
 +
 
 +
أمثلة<syntaxhighlight lang="ruby">
 +
 +
              static VALUE
 +
gc_profile_clear(void)
 +
{
 +
    rb_objspace_t *objspace = &rb_objspace;
 +
    if (GC_PROFILE_RECORD_DEFAULT_SIZE * 2 < objspace->profile.size) {
 +
        objspace->profile.size = GC_PROFILE_RECORD_DEFAULT_SIZE * 2;
 +
        objspace->profile.records = realloc(objspace->profile.records, sizeof(gc_profile_record) * objspace->profile.size);
 +
        if (!objspace->profile.records) {
 +
            rb_memerror();
 +
        }
 +
    }
 +
    MEMZERO(objspace->profile.records, gc_profile_record, objspace->profile.size);
 +
    objspace->profile.next_index = 0;
 +
    objspace->profile.current_record = 0;
 +
    return Qnil;
 +
}
 +
       
 +
</syntaxhighlight>
  
 
==== <code>GC::Profiler.disable → nil</code> ====
 
==== <code>GC::Profiler.disable → nil</code> ====
إيقاف مُنشئ ملفات تعريف GC.
+
إيقاف مُنشئ ملفات تعريف <code>[[Ruby/GC|GC]]</code>.
 +
 
 +
أمثلة<syntaxhighlight lang="ruby">
 +
 
 +
              static VALUE
 +
gc_profile_disable(void)
 +
{
 +
    rb_objspace_t *objspace = &rb_objspace;
 +
 
 +
    objspace->profile.run = FALSE;
 +
    objspace->profile.current_record = 0;
 +
    return Qnil;
 +
}
 +
</syntaxhighlight>
  
 
==== <code>GC::Profiler.enable → nil</code> ====
 
==== <code>GC::Profiler.enable → nil</code> ====
بدء منشئ ملفات تعريف GC.
+
بدء منشئ ملفات تعريف <code>[[Ruby/GC|GC]]</code>.
 +
 
 +
أمثلة<syntaxhighlight lang="ruby">
 +
 +
              static VALUE
 +
gc_profile_enable(void)
 +
{
 +
    rb_objspace_t *objspace = &rb_objspace;
 +
    objspace->profile.run = TRUE;
 +
    objspace->profile.current_record = 0;
 +
    return Qnil;
 +
}
 +
</syntaxhighlight>
  
 
==== <code>GC::Profiler.enabled? → true or false</code> ====
 
==== <code>GC::Profiler.enabled? → true or false</code> ====
الحالة الحالية لوضع مُنشئ ملفات تعريف GC.
+
الحالة الحالية لوضع مُنشئ ملفات تعريف <code>[[Ruby/GC|GC]]</code>.
 +
 
 +
أمثلة<syntaxhighlight lang="ruby">
 +
 +
              static VALUE
 +
gc_profile_enable_get(VALUE self)
 +
{
 +
    rb_objspace_t *objspace = &rb_objspace;
 +
    return objspace->profile.run ? Qtrue : Qfalse;
 +
}
 +
           
 +
</syntaxhighlight>
  
 
==== <code>GC::Profiler.raw_data → [Hash, ...]‎</code> ====
 
==== <code>GC::Profiler.raw_data → [Hash, ...]‎</code> ====
إعادة مصفوفة Array من تجزئات بيانات ملفات التعريف الأولية الفردية مُرتَّبة من الأقدم إلى الأحدث بواسطة ‎:GC_INVOKE_TIME.
+
إعادة مصفوفة <code>[[Ruby/Array|Array]]</code> من تجزئات بيانات ملفات التعريف الأولية الفردية مُرتَّبة من الأقدم إلى الأحدث بواسطة ‎:<code>GC_INVOKE_TIME</code>.
  
فعلى سبيل المثال:
+
فعلى سبيل المثال:<syntaxhighlight lang="ruby">
 
+
[
وتعني المفاتيح:
+
  {
 +
    :GC_TIME=>1.3000000000000858e-05,
 +
    :GC_INVOKE_TIME=>0.010634999999999999,
 +
    :HEAP_USE_SIZE=>289640,
 +
    :HEAP_TOTAL_SIZE=>588960,
 +
    :HEAP_TOTAL_OBJECTS=>14724,
 +
    :GC_IS_MARKED=>false
 +
  },
 +
  # ...
 +
]
 +
</syntaxhighlight>وتعني المفاتيح:
  
 
===== <code>‎:GC_TIME</code> =====
 
===== <code>‎:GC_TIME</code> =====
الوقت المنقضي Time بالثواني لتشغيل GC هذا.
+
الوقت المنقضي <code>[[Ruby/Time|Time]]</code> بالثواني لتشغيل <code>[[Ruby/GC|GC]]</code> هذا.
  
 
===== <code>:GC_INVOKE_TIME</code> =====
 
===== <code>:GC_INVOKE_TIME</code> =====
الوقت المنقضي Time بالثواني من بدء التشغيل وحتى استدعاء GC.
+
الوقت المنقضي <code>[[Ruby/Time|Time]]</code> بالثواني من بدء التشغيل وحتى استدعاء <code>[[Ruby/GC|GC]]</code>.
  
 
===== <code>‎:HEAP_USE_SIZE</code> =====
 
===== <code>‎:HEAP_USE_SIZE</code> =====
سطر 47: سطر 114:
 
إعادة <code>true</code> إذا كان GC في مرحلة التحديد.
 
إعادة <code>true</code> إذا كان GC في مرحلة التحديد.
  
إذا بُنيَ روبي مع GC_PROFILE_MORE_DETAIL، سيكون من الممكن أيضا الوصول إلى مفاتيح التجزئة التالية:
+
إذا بُنيَ روبي مع <code>GC_PROFILE_MORE_DETAIL</code>، سيكون من الممكن أيضا الوصول إلى مفاتيح التجزئة التالية:<syntaxhighlight lang="ruby">
 +
:GC_MARK_TIME
 +
:GC_SWEEP_TIME
 +
:ALLOCATE_INCREASE
 +
:ALLOCATE_LIMIT
 +
:HEAP_USE_PAGES
 +
:HEAP_LIVE_OBJECTS
 +
:HEAP_FREE_OBJECTS
 +
:HAVE_FINALIZE
 +
</syntaxhighlight>أمثلة<syntaxhighlight lang="ruby">
 +
 +
              static VALUE
 +
gc_profile_record_get(void)
 +
{
 +
    VALUE prof;
 +
    VALUE gc_profile = rb_ary_new();
 +
    size_t i;
 +
    rb_objspace_t *objspace = (&rb_objspace);
 +
 
 +
    if (!objspace->profile.run) {
 +
        return Qnil;
 +
    }
 +
 
 +
    for (i =0; i < objspace->profile.next_index; i++) {
 +
        gc_profile_record *record = &objspace->profile.records[i];
 +
 
 +
        prof = rb_hash_new();
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_FLAGS")), gc_info_decode(0, rb_hash_new(), record->flags));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DBL2NUM(record->gc_time));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DBL2NUM(record->gc_invoke_time));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SIZE")), SIZET2NUM(record->heap_use_size));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")), SIZET2NUM(record->heap_total_size));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")), SIZET2NUM(record->heap_total_objects));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_IS_MARKED")), Qtrue);
 +
#if GC_PROFILE_MORE_DETAIL
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DBL2NUM(record->gc_mark_time));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DBL2NUM(record->gc_sweep_time));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_INCREASE")), SIZET2NUM(record->allocate_increase));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_LIMIT")), SIZET2NUM(record->allocate_limit));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_PAGES")), SIZET2NUM(record->heap_use_pages));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_LIVE_OBJECTS")), SIZET2NUM(record->heap_live_objects));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_FREE_OBJECTS")), SIZET2NUM(record->heap_free_objects));
 +
 
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("REMOVING_OBJECTS")), SIZET2NUM(record->removing_objects));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("EMPTY_OBJECTS")), SIZET2NUM(record->empty_objects));
 +
 
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("HAVE_FINALIZE")), (record->flags & GPR_FLAG_HAVE_FINALIZE) ? Qtrue : Qfalse);
 +
#endif
 +
 
 +
#if RGENGC_PROFILE > 0
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("OLD_OBJECTS")), SIZET2NUM(record->old_objects));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBERED_NORMAL_OBJECTS")), SIZET2NUM(record->remembered_normal_objects));
 +
        rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBERED_SHADY_OBJECTS")), SIZET2NUM(record->remembered_shady_objects));
 +
#endif
 +
        rb_ary_push(gc_profile, prof);
 +
    }
 +
 
 +
    return gc_profile;
 +
}
 +
</syntaxhighlight>
  
 
==== <code>GC::Profiler.report</code> ====
 
==== <code>GC::Profiler.report</code> ====
  
 
==== <code>GC::Profiler.report(io)‎</code> ====
 
==== <code>GC::Profiler.report(io)‎</code> ====
كتابة ‎::result إلى ‎$stdout أو كائن IO المُعطي.
+
كتابة ‎<code>::result</code> إلى <code>‎$stdout</code> أو كائن <code>IO</code> المُعطي.
 +
 
 +
أمثلة<syntaxhighlight lang="ruby">
 +
 +
              static VALUE
 +
gc_profile_report(int argc, VALUE *argv, VALUE self)
 +
{
 +
    VALUE out;
 +
 
 +
    if (argc == 0) {
 +
        out = rb_stdout;
 +
    }
 +
    else {
 +
        rb_scan_args(argc, argv, "01", &out);
 +
    }
 +
    gc_profile_dump_on(out, rb_io_write);
 +
 
 +
    return Qnil;
 +
}
 +
     
 +
</syntaxhighlight>
  
 
==== <code>GC::Profiler.result → String</code> ====
 
==== <code>GC::Profiler.result → String</code> ====
إعادة تقرير بيانات ملف التعريف مثل:
+
إعادة تقرير بيانات ملف التعريف مثل:<syntaxhighlight lang="ruby">
 +
GC 1 invokes.
 +
Index    Invoke Time(sec)      Use Size(byte)    Total Size(byte)        Total Object                    GC time(ms)
 +
    1              0.012              159240              212940                10647        0.00000000000001530000
 +
</syntaxhighlight>أمثلة<syntaxhighlight lang="ruby">
 +
 +
              static VALUE
 +
gc_profile_result(void)
 +
{
 +
    VALUE str = rb_str_buf_new(0);
 +
    gc_profile_dump_on(str, rb_str_buf_append);
 +
    return str;
 +
}
 +
</syntaxhighlight>
  
 
==== <code>GC::Profiler.total_time → float</code> ====
 
==== <code>GC::Profiler.total_time → float</code> ====
 
إجمالي الوقت المستخدم لتجميع البيانات المهملة بالثواني.
 
إجمالي الوقت المستخدم لتجميع البيانات المهملة بالثواني.
 +
 +
أمثلة<syntaxhighlight lang="ruby">
 +
 +
              static VALUE
 +
gc_profile_total_time(VALUE self)
 +
{
 +
    double time = 0;
 +
    rb_objspace_t *objspace = &rb_objspace;
 +
 +
    if (objspace->profile.run && objspace->profile.next_index > 0) {
 +
        size_t i;
 +
        size_t count = objspace->profile.next_index;
 +
 +
        for (i = 0; i < count; i++) {
 +
            time += objspace->profile.records[i].gc_time;
 +
        }
 +
    }
 +
    return DBL2NUM(time);
 +
}
 +
       
 +
</syntaxhighlight>
  
 
= مصادر =
 
= مصادر =
* صفحة GC::Profiler في توثيق روبي الرسمي.
+
* [http://ruby-doc.org/core-2.5.1/GC/Profiler.html صفحة GC::Profiler في توثيق روبي الرسمي].
 
[[تصنيف:Ruby]]
 
[[تصنيف:Ruby]]
 
[[تصنيف:Ruby Methods]]
 
[[تصنيف:Ruby Methods]]

مراجعة 21:53، 22 أكتوبر 2018

يوفر مُنشئ ملفات تعريف جمع البيانات المهملة GC::Profiler الوصول إلى معلومات عن تشغيلات GC بما في ذلك الوقت والطول وحجم مساحة الكائن.

أمثلة:

GC::Profiler.enable
require 'rdoc/rdoc'
GC::Profiler.report
GC::Profiler.disable

انظر أيضًا GC.count و GC.malloc_allocated_size و GC.malloc_allocations.

توابع الصنف العام

GC::Profiler.clear → nil

مسح بيانات مُنشئ ملفات تعريف GC.

أمثلة

 
               static VALUE
gc_profile_clear(void)
{
    rb_objspace_t *objspace = &rb_objspace;
    if (GC_PROFILE_RECORD_DEFAULT_SIZE * 2 < objspace->profile.size) {
        objspace->profile.size = GC_PROFILE_RECORD_DEFAULT_SIZE * 2;
        objspace->profile.records = realloc(objspace->profile.records, sizeof(gc_profile_record) * objspace->profile.size);
        if (!objspace->profile.records) {
            rb_memerror();
        }
    }
    MEMZERO(objspace->profile.records, gc_profile_record, objspace->profile.size);
    objspace->profile.next_index = 0;
    objspace->profile.current_record = 0;
    return Qnil;
}

GC::Profiler.disable → nil

إيقاف مُنشئ ملفات تعريف GC.

أمثلة

               static VALUE
gc_profile_disable(void)
{
    rb_objspace_t *objspace = &rb_objspace;

    objspace->profile.run = FALSE;
    objspace->profile.current_record = 0;
    return Qnil;
}

GC::Profiler.enable → nil

بدء منشئ ملفات تعريف GC.

أمثلة

 
               static VALUE
gc_profile_enable(void)
{
    rb_objspace_t *objspace = &rb_objspace;
    objspace->profile.run = TRUE;
    objspace->profile.current_record = 0;
    return Qnil;
}

GC::Profiler.enabled? → true or false

الحالة الحالية لوضع مُنشئ ملفات تعريف GC.

أمثلة

 
               static VALUE
gc_profile_enable_get(VALUE self)
{
    rb_objspace_t *objspace = &rb_objspace;
    return objspace->profile.run ? Qtrue : Qfalse;
}

GC::Profiler.raw_data → [Hash, ...]‎

إعادة مصفوفة Array من تجزئات بيانات ملفات التعريف الأولية الفردية مُرتَّبة من الأقدم إلى الأحدث بواسطة ‎:GC_INVOKE_TIME.

فعلى سبيل المثال:

[
  {
     :GC_TIME=>1.3000000000000858e-05,
     :GC_INVOKE_TIME=>0.010634999999999999,
     :HEAP_USE_SIZE=>289640,
     :HEAP_TOTAL_SIZE=>588960,
     :HEAP_TOTAL_OBJECTS=>14724,
     :GC_IS_MARKED=>false
  },
  # ...
]

وتعني المفاتيح:

‎:GC_TIME

الوقت المنقضي Time بالثواني لتشغيل GC هذا.

:GC_INVOKE_TIME

الوقت المنقضي Time بالثواني من بدء التشغيل وحتى استدعاء GC.

‎:HEAP_USE_SIZE

إجمالي ‫ذاكرة‬ ‫التكدس‬ المستخدمة بوحدة البايت.

:HEAP_TOTAL_SIZE

إجمالي ‫ذاكرة‬ ‫التكدس‬ بوحدة البايت.

:HEAP_TOTAL_OBJECTS

إجمالي عدد الكائنات.

‎:GC_IS_MARKED

إعادة true إذا كان GC في مرحلة التحديد.

إذا بُنيَ روبي مع GC_PROFILE_MORE_DETAIL، سيكون من الممكن أيضا الوصول إلى مفاتيح التجزئة التالية:

:GC_MARK_TIME
:GC_SWEEP_TIME
:ALLOCATE_INCREASE
:ALLOCATE_LIMIT
:HEAP_USE_PAGES
:HEAP_LIVE_OBJECTS
:HEAP_FREE_OBJECTS
:HAVE_FINALIZE

أمثلة

 
               static VALUE
gc_profile_record_get(void)
{
    VALUE prof;
    VALUE gc_profile = rb_ary_new();
    size_t i;
    rb_objspace_t *objspace = (&rb_objspace);

    if (!objspace->profile.run) {
        return Qnil;
    }

    for (i =0; i < objspace->profile.next_index; i++) {
        gc_profile_record *record = &objspace->profile.records[i];

        prof = rb_hash_new();
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_FLAGS")), gc_info_decode(0, rb_hash_new(), record->flags));
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DBL2NUM(record->gc_time));
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DBL2NUM(record->gc_invoke_time));
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SIZE")), SIZET2NUM(record->heap_use_size));
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")), SIZET2NUM(record->heap_total_size));
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")), SIZET2NUM(record->heap_total_objects));
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_IS_MARKED")), Qtrue);
#if GC_PROFILE_MORE_DETAIL
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DBL2NUM(record->gc_mark_time));
        rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DBL2NUM(record->gc_sweep_time));
        rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_INCREASE")), SIZET2NUM(record->allocate_increase));
        rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_LIMIT")), SIZET2NUM(record->allocate_limit));
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_PAGES")), SIZET2NUM(record->heap_use_pages));
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_LIVE_OBJECTS")), SIZET2NUM(record->heap_live_objects));
        rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_FREE_OBJECTS")), SIZET2NUM(record->heap_free_objects));

        rb_hash_aset(prof, ID2SYM(rb_intern("REMOVING_OBJECTS")), SIZET2NUM(record->removing_objects));
        rb_hash_aset(prof, ID2SYM(rb_intern("EMPTY_OBJECTS")), SIZET2NUM(record->empty_objects));

        rb_hash_aset(prof, ID2SYM(rb_intern("HAVE_FINALIZE")), (record->flags & GPR_FLAG_HAVE_FINALIZE) ? Qtrue : Qfalse);
#endif

#if RGENGC_PROFILE > 0
        rb_hash_aset(prof, ID2SYM(rb_intern("OLD_OBJECTS")), SIZET2NUM(record->old_objects));
        rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBERED_NORMAL_OBJECTS")), SIZET2NUM(record->remembered_normal_objects));
        rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBERED_SHADY_OBJECTS")), SIZET2NUM(record->remembered_shady_objects));
#endif
        rb_ary_push(gc_profile, prof);
    }

    return gc_profile;
}

GC::Profiler.report

GC::Profiler.report(io)‎

كتابة ‎::result إلى ‎$stdout أو كائن IO المُعطي.

أمثلة

 
               static VALUE
gc_profile_report(int argc, VALUE *argv, VALUE self)
{
    VALUE out;

    if (argc == 0) {
        out = rb_stdout;
    }
    else {
        rb_scan_args(argc, argv, "01", &out);
    }
    gc_profile_dump_on(out, rb_io_write);

    return Qnil;
}

GC::Profiler.result → String

إعادة تقرير بيانات ملف التعريف مثل:

GC 1 invokes.
Index    Invoke Time(sec)       Use Size(byte)     Total Size(byte)         Total Object                    GC time(ms)
    1               0.012               159240               212940                10647         0.00000000000001530000

أمثلة

 
               static VALUE
gc_profile_result(void)
{
    VALUE str = rb_str_buf_new(0);
    gc_profile_dump_on(str, rb_str_buf_append);
    return str;
}

GC::Profiler.total_time → float

إجمالي الوقت المستخدم لتجميع البيانات المهملة بالثواني.

أمثلة

 
               static VALUE
gc_profile_total_time(VALUE self)
{
    double time = 0;
    rb_objspace_t *objspace = &rb_objspace;

    if (objspace->profile.run && objspace->profile.next_index > 0) {
        size_t i;
        size_t count = objspace->profile.next_index;

        for (i = 0; i < count; i++) {
            time += objspace->profile.records[i].gc_time;
        }
    }
    return DBL2NUM(time);
}

مصادر