next up previous contents index
Next: The Bartlett style mostly Up: Garbage Collection in the Prop Library Previous: The GC Protocol

Messages and Statistics

All garbage collectors use the following protocols for status reporting and statistics gathering.

   class GC {
   public:
      enum GCNotify {
         gc_no_notify,
         gc_notify_minor_collection,
         gc_notify_major_collection,
         gc_notify_weak_pointer_collection,
         gc_print_collection_time,
         gc_print_debugging_info
      }
      virtual int      verbosity() const;
      virtual void     set_verbosity(int);
      virtual ostream& get_console() const;
      virtual void     set_console(ostream&);
   };

   class GC {
   public:
      struct Statistics {
         const char *   algorithm;
         const char *   version;
         size_t         bytes_used;
         size_t         bytes_managed;
         size_t         bytes_free;
         struct timeval gc_user_time;
         struct timeval gc_system_time;
         struct timeval total_gc_user_time;
         struct timeval total_gc_system_time;
      }
      virtual Statistics statistics();
   };

Each collector has a current verbosity level, which can be set and reset using the methods set_verbosity(int) and verbosity() const. The verbosity level is actually a bit set containing flags of the type GC::GCNotify. A combination of these options can be used.

The current console of a collector is defaulted to the C++ stream cerr. It can be set and inspected with the methods set_console(ostream&) and ostream& get_console() respectively. For example, the user can redirect all garbage collection messages to a log file "gc.log" by executing the following during initialization:

   ofstream gc_log("gc.log");
   GC::get_default_gc().set_console(gc_log);



Allen Leung
Mon Apr 7 14:33:55 EDT 1997