shrub/g/t.c

190 lines
3.3 KiB
C
Raw Normal View History

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-11-06 03:20:01 +03:00
/* u3t_push(): push on trace stack.
2014-09-05 23:55:16 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_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-11-06 03:20:01 +03:00
/* u3t_mean(): push `[%mean roc]` on trace stack.
2014-09-05 23:55:16 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_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-11-06 03:20:01 +03:00
/* u3t_drop(): drop from meaning stack.
2014-09-05 23:55:16 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_drop(void)
2014-09-05 23:55:16 +04:00
{
2014-11-05 04:18:47 +03:00
c3_assert(_(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-11-06 03:20:01 +03:00
/* u3t_slog(): print directly.
2014-09-05 23:55:16 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_slog(u3_noun hod)
2014-09-05 23:55:16 +04:00
{
2014-11-05 04:18:47 +03:00
if ( c3y == u3du(hod) ) {
2014-10-03 23:51:27 +04:00
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
2014-11-06 03:20:01 +03:00
/* u3t_heck(): profile point.
2014-09-27 04:27:35 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_heck(u3_atom cog)
2014-09-27 04:27:35 +04:00
{
2014-11-06 03:20:01 +03:00
printf("ct: heck %s\r\n", u3r_string(cog));
2014-09-27 04:27:35 +04:00
2014-11-06 03:20:01 +03:00
if ( 0 == u3R->pro.day ) { u3R->pro.day = u3v_do("doss", 0); }
2014-09-27 04:27:35 +04:00
u3R->pro.day = u3_dc("pi-heck", cog, u3R->pro.day);
}
2014-11-06 03:20:01 +03:00
/* u3t_samp(): sample.
2014-09-27 04:27:35 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_samp(void)
2014-09-27 04:27:35 +04:00
{
2014-11-06 03:20:01 +03:00
if ( 0 == u3R->pro.day ) { u3R->pro.day = u3v_do("doss", 0); }
2014-09-27 04:27:35 +04:00
u3R->pro.day = u3_dc("pi-noon", u3k(u3R->pro.don), u3R->pro.day);
}
2014-11-06 03:20:01 +03:00
/* u3t_come(): push on profile stack.
2014-09-27 04:27:35 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_come(u3_atom cog)
2014-09-27 04:27:35 +04:00
{
2014-11-06 03:20:01 +03:00
printf("ct: come %s\r\n", u3r_string(cog));
2014-09-27 04:27:35 +04:00
u3R->pro.don = u3nc(cog, u3R->pro.don);
}
2014-11-06 03:20:01 +03:00
/* u3t_flee(): pop off profile stack.
2014-09-27 04:27:35 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_flee(void)
2014-09-27 04:27:35 +04:00
{
2014-11-05 04:18:47 +03:00
c3_assert(_(u3du(u3R->pro.don)));
2014-09-27 04:27:35 +04:00
{
u3_noun tax = u3R->bug.tax;
u3R->bug.tax = u3k(u3t(tax));
u3z(tax);
}
}
2014-11-06 03:20:01 +03:00
/* u3t_damp(): print and clear profile data.
2014-09-27 04:27:35 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_damp(void)
2014-09-27 04:27:35 +04:00
{
2014-09-27 22:37:04 +04:00
if ( 0 != u3R->pro.day ) {
u3_noun wol = u3_do("pi-tell", u3R->pro.day);
2014-11-06 03:20:01 +03:00
u3m_wall(wol);
2014-09-27 04:27:35 +04:00
2014-11-06 03:20:01 +03:00
u3R->pro.day = u3v_do("doss", 0);
2014-09-27 22:37:04 +04:00
}
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-11-06 03:20:01 +03:00
void _ct_sigaction(c3_i x_i) { u3t_samp(); }
2014-09-27 04:27:35 +04:00
2014-11-06 03:20:01 +03:00
/* u3t_boot(): turn sampling on.
2014-09-27 04:27:35 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_boot(void)
2014-09-27 04:27:35 +04:00
{
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
#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
#elif defined(U3_OS_linux)
2014-09-27 04:27:35 +04:00
// TODO: support profiling on linux
#elif defined(U3_OS_bsd)
2014-09-27 04:27:35 +04:00
// TODO: support profiling on bsd
#else
#error "port: profiling"
#endif
}
2014-11-06 03:20:01 +03:00
/* u3t_boff(): turn profile sampling off.
2014-09-27 04:27:35 +04:00
*/
void
2014-11-06 03:20:01 +03:00
u3t_boff(void)
2014-09-27 04:27:35 +04: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);
2014-11-06 03:20:01 +03:00
u3t_damp();
#elif defined(U3_OS_linux)
2014-09-27 04:27:35 +04:00
// TODO: support profiling on linux
#elif defined(U3_OS_bsd)
2014-09-27 04:27:35 +04:00
// TODO: support profiling on bsd
#else
#error "port: profiling"
#endif
}