lima-1.0b5/
lima-1.0b5/driver/
lima-1.0b5/driver/ChangeLog.old/
lima-1.0b5/driver/Win32/
lima-1.0b5/driver/compat/
lima-1.0b5/driver/include/
lima-1.0b5/driver/testsuite/
lima-1.0b5/driver/testsuite/clone/
lima-1.0b5/driver/testsuite/command/
lima-1.0b5/driver/testsuite/data/
lima-1.0b5/driver/testsuite/etc/
lima-1.0b5/driver/testsuite/include/
lima-1.0b5/driver/testsuite/inherit/
lima-1.0b5/driver/testsuite/inherit/master/
lima-1.0b5/driver/testsuite/log/
lima-1.0b5/driver/testsuite/single/
lima-1.0b5/driver/testsuite/single/tests/compiler/
lima-1.0b5/driver/testsuite/single/tests/efuns/
lima-1.0b5/driver/testsuite/single/tests/operators/
lima-1.0b5/driver/testsuite/u/
lima-1.0b5/driver/tmp/
lima-1.0b5/etc/
lima-1.0b5/lib/WWW/help/
lima-1.0b5/lib/cmds/
lima-1.0b5/lib/cmds/create/
lima-1.0b5/lib/cmds/player/attic/
lima-1.0b5/lib/contrib/bboard/
lima-1.0b5/lib/contrib/boards/
lima-1.0b5/lib/contrib/marriage/
lima-1.0b5/lib/contrib/roommaker/
lima-1.0b5/lib/contrib/transient_effect/
lima-1.0b5/lib/daemons/channel/
lima-1.0b5/lib/daemons/imud/
lima-1.0b5/lib/data/
lima-1.0b5/lib/data/config/
lima-1.0b5/lib/data/links/
lima-1.0b5/lib/data/news/
lima-1.0b5/lib/data/players/
lima-1.0b5/lib/data/secure/
lima-1.0b5/lib/domains/
lima-1.0b5/lib/domains/std/2.4.5/maze1/
lima-1.0b5/lib/domains/std/2.4.5/npc/
lima-1.0b5/lib/domains/std/2.4.5/post_dir/
lima-1.0b5/lib/domains/std/2.4.5/sub/
lima-1.0b5/lib/domains/std/camera/
lima-1.0b5/lib/domains/std/config/
lima-1.0b5/lib/domains/std/cult/
lima-1.0b5/lib/domains/std/effects/
lima-1.0b5/lib/domains/std/misc/
lima-1.0b5/lib/domains/std/monsters/
lima-1.0b5/lib/domains/std/recorder/
lima-1.0b5/lib/domains/std/rooms/
lima-1.0b5/lib/domains/std/rooms/beach/
lima-1.0b5/lib/domains/std/rooms/labyrinth/
lima-1.0b5/lib/domains/std/school/
lima-1.0b5/lib/domains/std/school/O/
lima-1.0b5/lib/domains/std/spells/
lima-1.0b5/lib/domains/std/spells/stock-mage/
lima-1.0b5/lib/domains/std/spells/stock-priest/
lima-1.0b5/lib/help/
lima-1.0b5/lib/help/admin/
lima-1.0b5/lib/help/hints/General_Questions/
lima-1.0b5/lib/help/hints/Pirate_Quest/
lima-1.0b5/lib/help/player/
lima-1.0b5/lib/help/player/bin/
lima-1.0b5/lib/help/player/quests/
lima-1.0b5/lib/help/wizard/
lima-1.0b5/lib/help/wizard/coding/guilds/
lima-1.0b5/lib/help/wizard/coding/rooms/
lima-1.0b5/lib/help/wizard/lib/daemons/
lima-1.0b5/lib/help/wizard/lib/lfun/
lima-1.0b5/lib/help/wizard/lib/std/
lima-1.0b5/lib/help/wizard/mudos_doc/
lima-1.0b5/lib/help/wizard/mudos_doc/applies/
lima-1.0b5/lib/help/wizard/mudos_doc/applies/interactive/
lima-1.0b5/lib/help/wizard/mudos_doc/applies/parsing/
lima-1.0b5/lib/help/wizard/mudos_doc/concepts/
lima-1.0b5/lib/help/wizard/mudos_doc/driver/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/arrays/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/buffers/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/compile/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/filesystem/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/floats/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/functions/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/general/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/mappings/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/mixed/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/numbers/
lima-1.0b5/lib/help/wizard/mudos_doc/efuns/parsing/
lima-1.0b5/lib/help/wizard/mudos_doc/lpc/constructs/
lima-1.0b5/lib/help/wizard/mudos_doc/lpc/types/
lima-1.0b5/lib/include/driver/
lima-1.0b5/lib/log/
lima-1.0b5/lib/obj/admtool/
lima-1.0b5/lib/obj/admtool/internal/
lima-1.0b5/lib/obj/admtool/mudinfo/
lima-1.0b5/lib/obj/admtool/secure/
lima-1.0b5/lib/obj/secure/
lima-1.0b5/lib/obj/secure/cmd/
lima-1.0b5/lib/obj/secure/mailers/
lima-1.0b5/lib/obj/secure/shell/
lima-1.0b5/lib/obj/secure/shell/classes/
lima-1.0b5/lib/obj/tasktool/
lima-1.0b5/lib/obj/tasktool/internal/
lima-1.0b5/lib/open/
lima-1.0b5/lib/secure/
lima-1.0b5/lib/secure/cgi/
lima-1.0b5/lib/secure/modules/
lima-1.0b5/lib/secure/simul_efun/
lima-1.0b5/lib/std/adversary/
lima-1.0b5/lib/std/adversary/advancement/
lima-1.0b5/lib/std/adversary/armor/
lima-1.0b5/lib/std/adversary/blows/
lima-1.0b5/lib/std/adversary/death/
lima-1.0b5/lib/std/adversary/formula/
lima-1.0b5/lib/std/adversary/health/
lima-1.0b5/lib/std/adversary/pulse/
lima-1.0b5/lib/std/adversary/wield/
lima-1.0b5/lib/std/classes/event_info/
lima-1.0b5/lib/std/container/
lima-1.0b5/lib/std/living/
lima-1.0b5/lib/std/modules/contrib/
lima-1.0b5/lib/std/patterns/
lima-1.0b5/lib/std/race/
lima-1.0b5/lib/std/race/restricted/
lima-1.0b5/lib/std/room/
lima-1.0b5/lib/tmp/
lima-1.0b5/lib/trans/
lima-1.0b5/lib/trans/admincmds/
lima-1.0b5/lib/trans/obj/
lima-1.0b5/lib/wiz/
/* Do not remove the headers from this file! see /USAGE for more info. */

//:COMMAND
//USAGE profile
//      profile <filename>
//      profile -total <filename>
//      profile all
//
//This displays time taken processing specified functions.
//To use this, the driver must be compiled with the PROFILE_FUNCTIONS option
//defined (in local_options).
//
//Using profile without any argument displays the "top 10" objects,
//together with the total time taken executing functions within them.
//
//Using profile <name> displays the time taken in each individual function
//within the specified object, split betwen "self" and "children", together
//with the number of calls involved.
//
//Using profile -total <name> produces a similar display, but sorted on the
//"Total" column rather than "Self"
//
//The "profile all" option is likely to produce a "Too long evaluation" error,
//unless you increase the max eval cost, but it should provide details of
//time taken by functions in the 20 "worst" objects.

inherit CMD;

#ifdef __PROFILE_FUNCTIONS__
void profile_all(function compare)
{
  mapping *prof;
  mapping *worst = ({});
  object ob;
  mapping item;

  foreach (ob in objects())
  {
    prof = function_profile(ob);
    prof = filter(prof, (: $1["calls"] :));
    prof = sort_array(prof, compare);
    prof = prof[0..9];
    map(prof, (: $1["name"] = $(file_name(ob)) + "::" + $1["name"] :) );
    worst += prof;
  }
  worst = sort_array(worst, compare);
  worst = worst[0..19];

  outf("%-40s %5s %8s %8s %8s\n", "Name", "Calls", "Self", "Children", "Total");
  foreach (item in worst)
  {
    outf("%-40s %5i %8i %8i %8i\n",
        item["name"], item["calls"], item["self"], item["children"],
        item["self"] + item["children"]);
  }
}

int total(mapping *info)
{
  int ret;
  mapping item;

  foreach (item in info)
    ret += item["self"];
  return ret;
}

protected void top_ten()
{
  mixed *tmp;
  int i, j;

  tmp = map(objects((: !clonep($1) :)),
      (: ({ $1, total(function_profile($1)) }) :));
// We could use sort_array() here, but that's an inefficient way
// to get the top 10 when there are lots of objects.

  for (i = 0; i < 10; i++)
  {
    mixed foo;

    for (j = i; j < sizeof(tmp); j++)
      if (tmp[i][1] < tmp[j][1])
      {
        foo = tmp[i];
        tmp[i] = tmp[j];
        tmp[j] = foo;
      }
    outf("%60-O %i\n", tmp[i][0], tmp[i][1]);
  }
}
#endif

private void main(string str)
{
#ifndef __PROFILE_FUNCTIONS__
  out("Function profiling not enabled.\n");
  return;
#else
  mapping *prof;
  mapping item;
  string obname;
  object ob;
  function compare;

  if (!str)
  {
    top_ten();
    return;
  }

  if (sscanf(str, "-total %s", str))
  {
    compare = (: $2["self"] + $2["children"] - $1["self"] - $1["children"] :
);
  } else {
    compare = (: $2["self"] - $1["self"] :);
  }

  if (str == "all")
  {
    profile_all(compare);
    return;
  }

  obname = evaluate_path(str);

  if (!(ob = find_object(obname)))
  {
    out("Can't find object " + obname + "\n");
    return;
  }

  prof = function_profile(ob);
  prof = filter(prof, (: $1["calls"] :));
  prof = sort_array(prof, compare);

  outf("%-30s %5s %8s %8s %8s\n", "Name", "Calls", "Self", "Children", "Total");
  foreach (item in prof)
  {
    outf("%-30s %5i %8i %8i %8i\n",
        item["name"], item["calls"], item["self"], item["children"],
        item["self"] + item["children"]);
  }
#endif
}