/* Returns the statHash */ ScmObj Scm_ProfilerRawResult(void) { ScmVM *vm = Scm_VM(); if (vm->prof == NULL) return SCM_FALSE; if (vm->prof->state == SCM_PROFILER_INACTIVE) return SCM_FALSE; if (vm->prof->state == SCM_PROFILER_RUNNING) Scm_ProfilerStop(); if (vm->prof->errorOccurred > 0) { Scm_Warn("profiler: An error has been occurred during saving profiling samples. The result may not be accurate"); } Scm_ProfilerCountBufferFlush(vm); /* collect samples in the current buffer */ collect_samples(vm->prof); /* collect samples in the saved file */ off_t off; SCM_SYSCALL(off, lseek(vm->prof->samplerFd, 0, SEEK_SET)); if (off == (off_t)-1) { Scm_ProfilerReset(); Scm_Error("profiler: seek failed in retrieving sample data"); } for (;;) { ssize_t r = read(vm->prof->samplerFd, vm->prof->samples, sizeof(ScmProfSample[1]) * SCM_PROF_SAMPLES_IN_BUFFER); if (r <= 0) break; vm->prof->currentSample = r / sizeof(ScmProfSample[1]); collect_samples(vm->prof); } vm->prof->currentSample = 0; #if defined(GAUCHE_WINDOWS) if (vm->prof->samplerFd >= 0) { close(vm->prof->samplerFd); vm->prof->samplerFd = -1; unlink(vm->prof->samplerFileName); } #else /* !GAUCHE_WINDOWS */ if (ftruncate(vm->prof->samplerFd, 0) < 0) { Scm_SysError("profiler: failed to truncate temporary file"); } #endif /* !GAUCHE_WINDOWS */ return SCM_OBJ(vm->prof->statHash); }
/* Returns the statHash */ ScmObj Scm_ProfilerRawResult(void) { ScmVM *vm = Scm_VM(); if (vm->prof == NULL) return SCM_FALSE; if (vm->prof->state == SCM_PROFILER_INACTIVE) return SCM_FALSE; if (vm->prof->state == SCM_PROFILER_RUNNING) Scm_ProfilerStop(); if (vm->prof->errorOccurred > 0) { Scm_Warn("profiler: An error has been occurred during saving profiling samples. The result may not be accurate"); } Scm_ProfilerCountBufferFlush(vm); /* collect samples in the current buffer */ collect_samples(vm->prof); /* collect samples in the saved file */ off_t off; SCM_SYSCALL(off, lseek(vm->prof->samplerFd, 0, SEEK_SET)); if (off == (off_t)-1) { Scm_ProfilerReset(); Scm_Error("profiler: seek failed in retrieving sample data"); } ScmObj sampler_port = Scm_MakePortWithFd(SCM_FALSE, SCM_PORT_INPUT, vm->prof->samplerFd, SCM_PORT_BUFFER_FULL, FALSE); for (;;) { ssize_t r = read(vm->prof->samplerFd, vm->prof->samples, sizeof(ScmProfSample[1]) * SCM_PROF_SAMPLES_IN_BUFFER); if (r <= 0) break; vm->prof->currentSample = r / sizeof(ScmProfSample[1]); collect_samples(vm->prof); } vm->prof->currentSample = 0; if (ftruncate(vm->prof->samplerFd, 0) < 0) { Scm_SysError("profiler: failed to truncate temporary file"); } return SCM_OBJ(vm->prof->statHash); }