58
59
60 //----------------------------------------------------------
61 // Implementation of MemProfiler
62
63 MemProfilerTask* MemProfiler::_task = NULL;
64 FILE* MemProfiler::_log_fp = NULL;
65
66
67 bool MemProfiler::is_active() {
68 return _task != NULL;
69 }
70
71
72 void MemProfiler::engage() {
73 const char *log_name = "mprofile.log";
74 if (!is_active()) {
75 // Create log file
76 _log_fp = fopen(log_name , "w+");
77 if (_log_fp == NULL) {
78 fatal(err_msg("MemProfiler: Cannot create log file: %s", log_name));
79 }
80 fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n");
81 fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n");
82 fprintf(_log_fp, " used, total, used, total, total, total, total, total\n");
83 fprintf(_log_fp, "--------------------------------------------------------------------------\n");
84
85 _task = new MemProfilerTask(MemProfilingInterval);
86 _task->enroll();
87 }
88 }
89
90
91 void MemProfiler::disengage() {
92 if (!is_active()) return;
93 // Do one last trace at disengage time
94 do_trace();
95
96 // Close logfile
97 fprintf(_log_fp, "MemProfiler detached\n");
98 fclose(_log_fp);
|
58
59
60 //----------------------------------------------------------
61 // Implementation of MemProfiler
62
63 MemProfilerTask* MemProfiler::_task = NULL;
64 FILE* MemProfiler::_log_fp = NULL;
65
66
67 bool MemProfiler::is_active() {
68 return _task != NULL;
69 }
70
71
72 void MemProfiler::engage() {
73 const char *log_name = "mprofile.log";
74 if (!is_active()) {
75 // Create log file
76 _log_fp = fopen(log_name , "w+");
77 if (_log_fp == NULL) {
78 fatal("MemProfiler: Cannot create log file: %s", log_name);
79 }
80 fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n");
81 fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n");
82 fprintf(_log_fp, " used, total, used, total, total, total, total, total\n");
83 fprintf(_log_fp, "--------------------------------------------------------------------------\n");
84
85 _task = new MemProfilerTask(MemProfilingInterval);
86 _task->enroll();
87 }
88 }
89
90
91 void MemProfiler::disengage() {
92 if (!is_active()) return;
93 // Do one last trace at disengage time
94 do_trace();
95
96 // Close logfile
97 fprintf(_log_fp, "MemProfiler detached\n");
98 fclose(_log_fp);
|