2014-09-11 04:01:32 +04:00
|
|
|
/* g/t.c
|
2014-09-05 23:55:16 +04:00
|
|
|
**
|
|
|
|
** This file is in the public domain.
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
/* u3_ct_push(): push on trace stack.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_ct_push(u3_noun mon)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3R->bug.tax = u3nc(mon, u3R->bug.tax);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
/* u3_ct_mean(): push `[%mean roc]` on trace stack.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_ct_mean(u3_noun roc)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3R->bug.tax = u3nc(u3nc(c3__mean, roc), u3R->bug.tax);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
/* u3_ct_drop(): drop from meaning stack.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_ct_drop(void)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
c3_assert(u3_so(u3du(u3R->bug.tax)));
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun tax = u3R->bug.tax;
|
2014-09-05 23:55:16 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3R->bug.tax = u3k(u3t(tax));
|
|
|
|
u3z(tax);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 23:51:27 +04:00
|
|
|
extern void
|
|
|
|
u3_lo_tank(c3_l tab_l, u3_noun tac);
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
/* u3_ct_slog(): print directly.
|
2014-09-05 23:55:16 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_ct_slog(u3_noun hod)
|
2014-09-05 23:55:16 +04:00
|
|
|
{
|
2014-10-03 23:51:27 +04:00
|
|
|
if ( u3_yes == u3du(hod) ) {
|
|
|
|
u3_noun pri = u3h(hod);
|
|
|
|
|
|
|
|
switch ( pri ) {
|
|
|
|
case 3: printf(">>> "); break;
|
|
|
|
case 2: printf(">> "); break;
|
|
|
|
case 1: printf("> "); break;
|
|
|
|
}
|
|
|
|
u3_lo_tank(0, u3k(u3t(hod)));
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(hod);
|
2014-09-05 23:55:16 +04:00
|
|
|
}
|
2014-09-27 04:27:35 +04:00
|
|
|
|
|
|
|
/* u3_ct_heck(): profile point.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u3_ct_heck(u3_atom cog)
|
|
|
|
{
|
|
|
|
printf("ct: heck %s\r\n", u3_cr_string(cog));
|
|
|
|
|
|
|
|
if ( 0 == u3R->pro.day ) { u3R->pro.day = u3_cv_do("doss", 0); }
|
|
|
|
|
|
|
|
u3R->pro.day = u3_dc("pi-heck", cog, u3R->pro.day);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* u3_ct_samp(): sample.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u3_ct_samp(void)
|
|
|
|
{
|
|
|
|
if ( 0 == u3R->pro.day ) { u3R->pro.day = u3_cv_do("doss", 0); }
|
|
|
|
|
|
|
|
u3R->pro.day = u3_dc("pi-noon", u3k(u3R->pro.don), u3R->pro.day);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* u3_ct_come(): push on profile stack.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u3_ct_come(u3_atom cog)
|
|
|
|
{
|
|
|
|
printf("ct: come %s\r\n", u3_cr_string(cog));
|
|
|
|
|
|
|
|
u3R->pro.don = u3nc(cog, u3R->pro.don);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* u3_ct_flee(): pop off profile stack.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u3_ct_flee(void)
|
|
|
|
{
|
|
|
|
c3_assert(u3_so(u3du(u3R->pro.don)));
|
|
|
|
{
|
|
|
|
u3_noun tax = u3R->bug.tax;
|
|
|
|
|
|
|
|
u3R->bug.tax = u3k(u3t(tax));
|
|
|
|
u3z(tax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* u3_ct_damp(): print and clear profile data.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u3_ct_damp(void)
|
|
|
|
{
|
2014-09-27 22:37:04 +04:00
|
|
|
if ( 0 != u3R->pro.day ) {
|
|
|
|
u3_noun wol = u3_do("pi-tell", u3R->pro.day);
|
|
|
|
u3_cm_wall(wol);
|
2014-09-27 04:27:35 +04:00
|
|
|
|
2014-09-27 22:37:04 +04:00
|
|
|
u3R->pro.day = u3_cv_do("doss", 0);
|
|
|
|
}
|
2014-09-27 06:14:24 +04:00
|
|
|
|
2014-09-27 22:37:04 +04:00
|
|
|
if ( 0 != u3R->pro.nox_d ) {
|
|
|
|
printf("knox: %llu\r\n", (u3R->pro.nox_d / 1000ULL));
|
|
|
|
u3R->pro.nox_d = 0;
|
|
|
|
}
|
2014-09-27 04:27:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _ct_sigaction(): profile sigaction callback.
|
|
|
|
*/
|
2014-09-27 22:37:04 +04:00
|
|
|
void _ct_sigaction(c3_i x_i) { u3_ct_samp(); }
|
2014-09-27 04:27:35 +04:00
|
|
|
|
|
|
|
/* u3_ct_boot(): turn sampling on.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u3_ct_boot(void)
|
|
|
|
{
|
2014-09-27 06:14:24 +04:00
|
|
|
printf("ct: now profiling.\r\n");
|
2014-09-27 04:27:35 +04:00
|
|
|
|
2014-09-27 22:37:04 +04:00
|
|
|
printf("knox: %llu\r\n", (u3R->pro.nox_d / 1000ULL));
|
|
|
|
u3R->pro.nox_d = 0;
|
2014-09-27 04:27:35 +04:00
|
|
|
|
2014-11-05 03:29:08 +03:00
|
|
|
#if defined(U3_OS_osx)
|
2014-09-27 22:37:04 +04:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
struct itimerval itm_v;
|
|
|
|
struct sigaction sig_s;
|
2014-09-27 04:27:35 +04:00
|
|
|
|
2014-09-27 22:37:04 +04:00
|
|
|
sig_s.__sigaction_u.__sa_handler = _ct_sigaction;
|
|
|
|
sig_s.sa_mask = 0;
|
|
|
|
sig_s.sa_flags = 0;
|
|
|
|
sigaction(SIGPROF, &sig_s, 0);
|
|
|
|
|
|
|
|
itm_v.it_interval.tv_sec = 0;
|
|
|
|
itm_v.it_interval.tv_usec = 10000;
|
|
|
|
itm_v.it_value = itm_v.it_interval;
|
|
|
|
|
|
|
|
setitimer(ITIMER_PROF, &itm_v, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2014-11-05 03:29:08 +03:00
|
|
|
#elif defined(U3_OS_linux)
|
2014-09-27 04:27:35 +04:00
|
|
|
// TODO: support profiling on linux
|
2014-11-05 03:29:08 +03:00
|
|
|
#elif defined(U3_OS_bsd)
|
2014-09-27 04:27:35 +04:00
|
|
|
// TODO: support profiling on bsd
|
|
|
|
#else
|
|
|
|
#error "port: profiling"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* u3_ct_boff(): turn profile sampling off.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u3_ct_boff(void)
|
|
|
|
{
|
2014-11-05 03:29:08 +03:00
|
|
|
#if defined(U3_OS_osx)
|
2014-09-27 04:27:35 +04:00
|
|
|
struct sigaction sig_s;
|
|
|
|
struct itimerval itm_v;
|
|
|
|
|
2014-09-27 06:14:24 +04:00
|
|
|
printf("ct: end profiling.\r\n");
|
2014-09-27 04:27:35 +04:00
|
|
|
|
|
|
|
itm_v.it_interval.tv_sec = 0;
|
|
|
|
itm_v.it_interval.tv_usec = 0;
|
|
|
|
itm_v.it_value = itm_v.it_interval;
|
|
|
|
|
|
|
|
setitimer(ITIMER_PROF, &itm_v, 0);
|
|
|
|
sigaction(SIGPROF, &sig_s, 0);
|
|
|
|
|
|
|
|
u3_ct_damp();
|
2014-11-05 03:29:08 +03:00
|
|
|
#elif defined(U3_OS_linux)
|
2014-09-27 04:27:35 +04:00
|
|
|
// TODO: support profiling on linux
|
2014-11-05 03:29:08 +03:00
|
|
|
#elif defined(U3_OS_bsd)
|
2014-09-27 04:27:35 +04:00
|
|
|
// TODO: support profiling on bsd
|
|
|
|
#else
|
|
|
|
#error "port: profiling"
|
|
|
|
#endif
|
|
|
|
}
|