send slog hints over the king/serf pipe

This commit is contained in:
Joe Bryan 2019-04-11 12:53:15 -07:00
parent 3eaa470d98
commit 4873309e81
2 changed files with 86 additions and 64 deletions

View File

@ -72,6 +72,15 @@
:: r: replacement event (at date)
::
[p=@ q=@ r=(pair date ovum)]
==
:: send slog hint while computing event
::
$: %slog
:: p: event number
:: q: priority
:: r: output tank
::
[p=@ q=@ r=tank]
== ==
:: +writ: from lord to serf
::
@ -350,6 +359,14 @@ _serf_send_complete(u3_noun vir)
vir));
}
/* _serf_send_slog(): send hint output.
*/
static void
_serf_send_slog(u3_noun hod)
{
_serf_send(u3nt(c3__slog, u3i_chubs(1, &u3V.evt_d), hod));
}
/* _serf_lame(): event failed, replace with error event.
*/
static void
@ -734,67 +751,6 @@ _serf_poke(void* vod_p, u3_noun mat)
}
}
#ifdef U3_EVENT_TIME_DEBUG
/* _serf_slog_time(): slog timelapse.
*/
static void
_serf_slog_time(void)
{
static int old;
static struct timeval b4, f2, d0;
static c3_d b4_d;
c3_w ms_w;
if ( old ) {
gettimeofday(&f2, 0);
timersub(&f2, &b4, &d0);
ms_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000);
if (ms_w > 1) {
#if 0
fprintf(stderr, "%6d.%02dms: %9d ",
ms_w, (int) (d0.tv_usec % 1000) / 10,
((int) (u3R->pro.nox_d - b4_d)));
#else
fprintf(stderr, "%6d.%02dms ",
ms_w, (int) (d0.tv_usec % 1000) / 10);
#endif
gettimeofday(&b4, 0);
b4_d = u3R->pro.nox_d;
}
else {
printf(" ");
}
}
else {
gettimeofday(&b4, 0);
b4_d = u3R->pro.nox_d;
}
old = 1;
}
#endif
/* _serf_slog(): print directly.
*/
static void
_serf_slog(u3_noun hod)
{
#ifdef U3_EVENT_TIME_DEBUG
_serf_slog_time();
#endif
if ( c3y == u3du(hod) ) {
u3_noun pri = u3h(hod);
switch ( pri ) {
case 3: fprintf(stderr, ">>> "); break;
case 2: fprintf(stderr, ">> "); break;
case 1: fprintf(stderr, "> "); break;
}
u3_pier_tank(0, u3k(u3t(hod)));
}
u3z(hod);
}
/* u3_serf_boot(): send startup message to manager.
*/
void
@ -872,7 +828,7 @@ main(c3_i argc, c3_c* argv[])
*/
{
u3V.evt_d = u3m_boot_new(dir_c);
u3t_init_slog(_serf_slog);
u3t_init_slog(_serf_send_slog);
}
/* configure pipe to lord process

View File

@ -879,6 +879,55 @@ _pier_work_play(u3_pier* pir_u,
_pier_boot_ready(pir_u);
}
/* _pier_work_slog(): print directly.
*/
static void
_pier_work_slog(u3_writ* wit_u, c3_w pri_w, u3_noun tan)
{
#ifdef U3_EVENT_TIME_DEBUG
{
static int old;
static struct timeval b4, f2, d0;
static c3_d b4_d;
c3_w ms_w;
if ( old ) {
gettimeofday(&f2, 0);
timersub(&f2, &b4, &d0);
ms_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000);
if (ms_w > 1) {
#if 0
fprintf(stderr, "%6d.%02dms: %9d ",
ms_w, (int) (d0.tv_usec % 1000) / 10,
((int) (u3R->pro.nox_d - b4_d)));
#else
fprintf(stderr, "%6d.%02dms ",
ms_w, (int) (d0.tv_usec % 1000) / 10);
#endif
gettimeofday(&b4, 0);
b4_d = u3R->pro.nox_d;
}
else {
printf(" ");
}
}
else {
gettimeofday(&b4, 0);
b4_d = u3R->pro.nox_d;
}
old = 1;
}
#endif
switch ( pri_w ) {
case 3: fprintf(stderr, ">>> "); break;
case 2: fprintf(stderr, ">> "); break;
case 1: fprintf(stderr, "> "); break;
}
u3_pier_tank(0, tan);
}
/* _pier_work_exit(): handle subprocess exit.
*/
static void
@ -1009,6 +1058,25 @@ _pier_work_poke(void* vod_p,
}
break;
}
case c3__slog: {
if ( (c3n == u3r_qual(jar, 0, &p_jar, &q_jar, &r_jar)) ||
(c3n == u3ud(p_jar)) ||
(u3r_met(6, p_jar) != 1) ||
(c3n == u3ud(q_jar)) ||
(u3r_met(3, q_jar) > 1) )
{
goto error;
}
else {
c3_d evt_d = u3r_chub(0, p_jar);
c3_w pri_w = u3r_word(0, q_jar);
u3_writ* wit_u = _pier_writ_find(pir_u, evt_d);
_pier_work_slog(wit_u, pri_w, u3k(r_jar));
}
break;
}
}
u3z(jar); u3z(mat);
@ -1903,7 +1971,6 @@ _pier_wall(u3_noun wol)
FILE* fil_u = u3_term_io_hija();
u3_noun wal = wol;
fil_u = stderr; // XX
while ( u3_nul != wal ) {
_pier_tape(fil_u, u3k(u3h(wal)));
@ -1942,7 +2009,6 @@ u3_pier_punt(c3_l tab_l, u3_noun tac)
if ( c3__leaf == u3h(act) ) {
FILE* fil_u = u3_term_io_hija();
fil_u = stderr; // XX
_pier_tape(fil_u, u3k(u3t(act)));
putc(13, fil_u);
putc(10, fil_u);