boottime.c 1.86 KB
Newer Older
1 2
/*
 *  GRUB  --  GRand Unified Bootloader
3
 *  Copyright (C) 2013  Free Software Foundation, Inc.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
 *
 *  GRUB is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  GRUB is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/command.h>
#include <grub/i18n.h>

GRUB_MOD_LICENSE ("GPLv3+");


static grub_err_t
grub_cmd_boottime (struct grub_command *cmd __attribute__ ((unused)),
		   int argc __attribute__ ((unused)),
		   char *argv[] __attribute__ ((unused)))
{
  struct grub_boot_time *cur;
  grub_uint64_t last_time = 0, start_time = 0;
  if (!grub_boot_time_head)
    {
      grub_puts_ (N_("No boot time statistics is available\n"));
      return 0;
    }
  start_time = last_time = grub_boot_time_head->tp;
  for (cur = grub_boot_time_head; cur; cur = cur->next)
    {
      grub_uint32_t tmabs = cur->tp - start_time;
      grub_uint32_t tmrel = cur->tp - last_time;
      last_time = cur->tp;

      grub_printf ("%3d.%03ds %2d.%03ds %s:%d %s\n", 
		   tmabs / 1000, tmabs % 1000, tmrel / 1000, tmrel % 1000, cur->file, cur->line,
		   cur->msg);
    }
 return 0;
}

static grub_command_t cmd_boottime;

GRUB_MOD_INIT(boottime)
{
  cmd_boottime =
    grub_register_command ("boottime", grub_cmd_boottime,
59
			   0, N_("Show boot time statistics."));
60 61 62 63 64 65
}

GRUB_MOD_FINI(boottime)
{
  grub_unregister_command (cmd_boottime);
}