summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbjj <bjj>2001-07-27 07:29:44 (GMT)
committerbjj <bjj>2001-07-27 07:29:44 (GMT)
commite0bf01e7ea71f121af163fca6995568c7c71eb1c (patch)
treecc9216cedd9e5b703ad238731aad411ea095169c
parentae1c936c4a610af266c79c61d7eba01edd2ffe15 (diff)
downloadmoo-cvs-e0bf01e7ea71f121af163fca6995568c7c71eb1c.zip
moo-cvs-e0bf01e7ea71f121af163fca6995568c7c71eb1c.tar.gz
moo-cvs-e0bf01e7ea71f121af163fca6995568c7c71eb1c.tar.bz2
moo-cvs-e0bf01e7ea71f121af163fca6995568c7c71eb1c.tar.xz
Add a 10th list element to queued_task() entries with the size in bytes
of the forked or suspended task.
-rw-r--r--tasks.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/tasks.c b/tasks.c
index 7bb5777..87cb9da 100644
--- a/tasks.c
+++ b/tasks.c
@@ -792,6 +792,12 @@ enqueue_ft(Program * program, activation a, Var * rt_env,
t->kind = TASK_FORKED;
t->t.forked.program = program;
+ /* The next line was not present before 1.8.2. a.rt_env was never
+ * accessed and was eventually overwritten by forked.rt_env in
+ * do_forked_task(). Makes no sense to store it two places, but here
+ * we are. Setting it in the activation simplifies forked_task_bytes()
+ */
+ a.rt_env = rt_env;
t->t.forked.a = a;
t->t.forked.rt_env = rt_env;
t->t.forked.f_index = f_index;
@@ -1412,12 +1418,47 @@ bf_task_id(Var arglist, Byte next, void *vdata, Objid progr)
return make_var_pack(r);
}
+static int
+activation_bytes(activation *ap)
+{
+ int total = sizeof(activation);
+ Var *v;
+ int i;
+
+ /* The MOO Way [tm] is double-billing to avoid the possibility
+ * of not billing at all, so the size of the prog is counted here
+ * even though it will be shared unless the verb was reprogrammed.
+ */
+ total += program_bytes(ap->prog);
+ for (i = 0; i < ap->prog->num_var_names; ++i)
+ total += value_bytes(ap->rt_env[i]);
+ for (v = ap->top_rt_stack - 1; v >= ap->base_rt_stack; v--)
+ total += value_bytes(*v);
+ /* XXX ignore bi_func_data, it's an opaque type. */
+ total += value_bytes(ap->temp) - sizeof(Var);
+ total += strlen(ap->verb) + 1;
+ total += strlen(ap->verbname) + 1;
+ return total;
+}
+
+static int
+forked_task_bytes(forked_task ft)
+{
+ int total = sizeof(forked_task);
+
+ /* ft.program is duplicated in ft.a */
+ total += activation_bytes(&ft.a) - sizeof(activation);
+ /* ft.rt_env is properly inside ft.a now */
+
+ return total;
+}
+
static Var
list_for_forked_task(forked_task ft)
{
Var list;
- list = new_list(9);
+ list = new_list(10);
list.v.list[1].type = TYPE_INT;
list.v.list[1].v.num = ft.id;
list.v.list[2].type = TYPE_INT;
@@ -1436,16 +1477,30 @@ list_for_forked_task(forked_task ft)
list.v.list[8].v.num = find_line_number(ft.program, ft.f_index, 0);
list.v.list[9].type = TYPE_OBJ;
list.v.list[9].v.obj = ft.a.this;
+ list.v.list[10].type = TYPE_INT;
+ list.v.list[10].v.num = forked_task_bytes(ft);
return list;
}
+static int
+suspended_task_bytes(vm the_vm)
+{
+ int total = sizeof(vmstruct);
+ int i;
+
+ for (i = 0; i <= the_vm->top_activ_stack; i++)
+ total += activation_bytes(the_vm->activ_stack + i);
+
+ return total;
+}
+
static Var
list_for_vm(vm the_vm)
{
Var list;
- list = new_list(9);
+ list = new_list(10);
list.v.list[1].type = TYPE_INT;
list.v.list[1].v.num = the_vm->task_id;
@@ -1464,6 +1519,8 @@ list_for_vm(vm the_vm)
list.v.list[8].v.num = suspended_lineno_of_vm(the_vm);
list.v.list[9].type = TYPE_OBJ;
list.v.list[9].v.obj = top_activ(the_vm).this;
+ list.v.list[10].type = TYPE_INT;
+ list.v.list[10].v.num = suspended_task_bytes(the_vm);
return list;
}
@@ -1951,6 +2008,10 @@ char rcsid_tasks[] = "$Id$";
/*
* $Log$
+ * Revision 1.7 2001/07/27 07:29:44 bjj
+ * Add a 10th list element to queued_task() entries with the size in bytes
+ * of the forked or suspended task.
+ *
* Revision 1.6 2001/03/12 03:25:17 bjj
* Added new package type BI_KILL which kills the task calling the builtin.
* Removed the static int task_killed in execute.c which wa tested on every