VirtualBox

Changeset 2101 in kBuild


Ignore:
Timestamp:
Nov 24, 2008 11:35:56 PM (16 years ago)
Author:
bird
Message:

kmk: Implemented new switch --print-time. Fixes #65.

Location:
trunk/src/kmk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.am

    r2091 r2101  
    144144        -DCONFIG_PRETTY_COMMAND_PRINTING \
    145145        -DCONFIG_WITH_PRINT_STATS_SWITCH \
     146        -DCONFIG_WITH_PRINT_TIME_SWITCH \
    146147        -DCONFIG_WITH_RDONLY_VARIABLE_VALUE \
    147148        -DCONFIG_WITH_LAZY_DEPS_VARS \
  • trunk/src/kmk/Makefile.kmk

    r2091 r2101  
    170170        CONFIG_PRETTY_COMMAND_PRINTING \
    171171        CONFIG_WITH_PRINT_STATS_SWITCH \
     172        CONFIG_WITH_PRINT_TIME_SWITCH \
    172173        CONFIG_WITH_RDONLY_VARIABLE_VALUE \
    173174        CONFIG_WITH_LAZY_DEPS_VARS \
  • trunk/src/kmk/function.c

    r2025 r2101  
    4545#if defined (CONFIG_WITH_MATH) || defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_FILE_SIZE) /* bird */
    4646# include <ctype.h>
    47 # ifdef _MSC_VER
    48 typedef __int64 math_int;
    49 # else
    50 #  include <stdint.h>
    51 typedef int64_t math_int;
    52 # endif
     47typedef big_int math_int;
    5348static char *math_int_to_variable_buffer (char *, math_int);
    5449#endif
     
    41024097func_nanots (char *o, char **argv, const char *funcname)
    41034098{
    4104   math_int ts;
    4105 
    4106 #if defined (WINDOWS32)
    4107   static int s_state = -1;
    4108   static LARGE_INTEGER s_freq;
    4109 
    4110   if (s_state == -1)
    4111     s_state = QueryPerformanceFrequency (&s_freq);
    4112   if (s_state)
    4113     {
    4114       LARGE_INTEGER pc;
    4115       if (!QueryPerformanceCounter (&pc))
    4116         {
    4117           s_state = 0;
    4118           return func_nanots (o, argv, funcname);
    4119         }
    4120       ts = (math_int)((long double)pc.QuadPart / (long double)s_freq.QuadPart * 1000000000);
    4121     }
    4122   else
    4123     {
    4124       /* fall back to low resolution system time. */
    4125       LARGE_INTEGER bigint;
    4126       FILETIME ft = {0,0};
    4127       GetSystemTimeAsFileTime (&ft);
    4128       bigint.u.LowPart = ft.dwLowDateTime;
    4129       bigint.u.HighPart = ft.dwLowDateTime;
    4130       ts = bigint.QuadPart * 100;
    4131     }
    4132 
    4133 /* FIXME: Linux and others have the realtime clock_* api, detect and use it. */
    4134 
    4135 #elif HAVE_GETTIMEOFDAY
    4136   struct timeval tv;
    4137   if (!gettimeofday (&tv, NULL))
    4138     ts = (math_int)tv.tv_sec * 1000000000
    4139        + tv.tv_usec * 1000;
    4140   else
    4141     {
    4142       error (NILF, _("$(nanots): gettimeofday failed"));
    4143       ts = 0;
    4144     }
    4145 
    4146 #else
    4147 # error "PORTME"
    4148 #endif
    4149 
    4150   return math_int_to_variable_buffer (o, ts);
     4099  return math_int_to_variable_buffer (o, nano_timestamp ());
    41514100}
    41524101#endif
  • trunk/src/kmk/job.c

    r2056 r2101  
    209209static int job_next_command (struct child *);
    210210static int start_waiting_job (struct child *);
     211#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     212static void print_job_time (struct child *);
     213#endif
    211214
    212215
     
    901904free_child (struct child *child)
    902905{
     906#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     907  print_job_time (child);
     908#endif
    903909  if (!jobserver_tokens)
    904910    fatal (NILF, "INTERNAL: Freeing child 0x%08lx (%s) but no tokens left!\n",
     
    10641070  if (!child->command_ptr)
    10651071    goto next_command;
     1072
     1073#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     1074  if (child->start_ts == -1)
     1075    child->start_ts = nano_timestamp ();
     1076#endif
    10661077
    10671078  /* Combine the flags parsed for the line itself with
     
    18211832  c->command_lines = lines;
    18221833  c->sh_batch_file = NULL;
     1834#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     1835  c->start_ts = -1;
     1836#endif
    18231837
    18241838  /* Cache dontcare flag because file->dontcare can be changed once we
     
    34223436#endif /* !HAPE_DUP2 && !_AMIGA */
    34233437
     3438#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     3439/* Prints the time elapsed while executing the commands for the given job. */
     3440void print_job_time (struct child *c)
     3441{
     3442  if (   !handling_fatal_signal
     3443      && print_time_min != -1
     3444      && c->start_ts != -1)
     3445    {
     3446      big_int elapsed = nano_timestamp () - c->start_ts;
     3447      if (elapsed >= print_time_min * BIG_INT_C(1000000000))
     3448        {
     3449          char buf[64];
     3450          int len = format_elapsed_nano (buf, sizeof (buf), elapsed);
     3451          if (len > print_time_width)
     3452            print_time_width = len;
     3453          message (1, _("%*s - %s"), print_time_width, buf, c ->file->name);
     3454        }
     3455    }
     3456}
     3457#endif
     3458
    34243459/* On VMS systems, include special VMS functions.  */
    34253460
  • trunk/src/kmk/job.h

    r1993 r2101  
    6767    unsigned int deleted:1;     /* Nonzero if targets have been deleted.  */
    6868    unsigned int dontcare:1;    /* Saved dontcare flag.  */
     69#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     70    big_int start_ts;           /* nano_timestamp of the first command.  */
     71#endif
    6972  };
    7073
  • trunk/src/kmk/main.c

    r2099 r2101  
    183183
    184184int print_stats_flag;
     185#endif
     186
     187#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     188/* Minimum number of seconds to report, -1 if disabled. */
     189
     190int print_time_min = -1;
     191static int default_print_time_min = -1;
     192static int no_val_print_time_min = 0;
     193static big_int make_start_ts = -1;
     194int print_time_width = 5;
    185195#endif
    186196
     
    491501       "print-stats" },
    492502#endif
     503#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     504    { CHAR_MAX+12, positive_int, (char *) &print_time_min, 1, 1, 0,
     505      (char *) &no_val_print_time_min, (char *) &default_print_time_min,
     506      "print-time" },
     507#endif
    493508#ifdef KMK
    494     { CHAR_MAX+12, positive_int, (char *) &process_priority, 1, 1, 0,
     509    { CHAR_MAX+14, positive_int, (char *) &process_priority, 1, 1, 0,
    495510      (char *) &process_priority, (char *) &process_priority, "priority" },
    496     { CHAR_MAX+14, positive_int, (char *) &process_affinity, 1, 1, 0,
     511    { CHAR_MAX+15, positive_int, (char *) &process_affinity, 1, 1, 0,
    497512      (char *) &process_affinity, (char *) &process_affinity, "affinity" },
    498513#endif
     
    505520      "no-keep-going" },
    506521#if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
    507     { CHAR_MAX+15, flag, (char *) &make_expensive_statistics, 1, 1, 1, 0, 0,
     522    { CHAR_MAX+16, flag, (char *) &make_expensive_statistics, 1, 1, 1, 0, 0,
    508523       "statistics" },
    509524#endif
     
    13131328  SetUnhandledExceptionFilter(handle_runtime_exceptions);
    13141329#endif /* !ELECTRIC_HEAP */
     1330
     1331#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     1332  make_start_ts = nano_timestamp ();
     1333#endif
    13151334
    13161335  /* start off assuming we have no shell */
     
    35663585                     make_expensive_statistics ? "1" : "0", o_default, 1);
    35673586# endif
     3587#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     3588    sprintf (val, "%u", print_time_min);
     3589    define_variable ("KMK_OPTS_PRINT_TIME", sizeof("KMK_OPTS_PRINT_TIME") - 1,
     3590                     val, o_default, 1);
     3591#endif
    35683592  }
    35693593#endif
     
    38113835      if (directory_before_chdir != 0)
    38123836        chdir (directory_before_chdir);
     3837
     3838#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     3839      if (print_time_min != -1)
     3840        {
     3841          big_int elapsed = nano_timestamp () - make_start_ts;
     3842          if (elapsed >= print_time_min * BIG_INT_C(1000000000))
     3843            {
     3844              char buf[64];
     3845              format_elapsed_nano (buf, sizeof (buf), elapsed);
     3846              message (1, _("%*s"), print_time_width, buf);
     3847            }
     3848        }
     3849#endif
    38133850
    38143851      log_working_directory (0);
  • trunk/src/kmk/make.h

    r2050 r2101  
    442442
    443443#define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
     444
     445#if defined (CONFIG_WITH_MATH) \
     446 || defined (CONFIG_WITH_NANOTS) \
     447 || defined (CONFIG_WITH_FILE_SIZE) \
     448 || defined (CONFIG_WITH_PRINT_TIME_SWITCH) /* bird */
     449# ifdef _MSC_VER
     450typedef __int64 big_int;
     451#  define BIG_INT_C(c)      (c ## LL)
     452typedef unsigned __int64 big_uint;
     453#  define BIG_UINT_C(c)     (c ## ULL)
     454# else
     455#  include <stdint.h>
     456typedef int64_t big_int;
     457#  define BIG_INT_C(c)      INT64_C(c)
     458typedef uint64_t big_uint;
     459#  define BIG_UINT_C(c)     UINT64_C(c)
     460# endif
     461#endif
    444462
    445463
     
    691709#ifdef CONFIG_PRETTY_COMMAND_PRINTING
    692710extern int pretty_command_printing;
     711#endif
     712#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     713extern int print_time_min, print_time_width;
    693714#endif
    694715#if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
     
    896917extern char *func_breakpoint(char *o, char **argv, const char *funcname);
    897918#endif
     919
     920#if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH)
     921/* misc.c */
     922extern big_int nano_timestamp (void);
     923extern int format_elapsed_nano (char *buf, size_t size, big_int ts);
     924#endif
     925
  • trunk/src/kmk/misc.c

    r2062 r2101  
    2929# if defined(__GLIBC__) || defined(HAVE_MALLINFO)
    3030#  include <malloc.h>
     31# endif
     32#endif
     33
     34#if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH)
     35# ifdef WINDOWS32
     36#  include <Windows.h>
    3137# endif
    3238#endif
     
    11641170#ifdef CONFIG_WITH_PRINT_STATS_SWITCH
    11651171/* Print heap statistics if supported by the platform. */
    1166 void print_heap_stats (void)
     1172void
     1173print_heap_stats (void)
    11671174{
    11681175  /* Darwin / Mac OS X */
     
    12511258#endif /* CONFIG_WITH_PRINT_STATS_SWITCH */
    12521259
     1260#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     1261/* Get a nanosecond timestamp, from a monotonic time source if
     1262   possible.  Returns -1 after calling error() on failure.  */
     1263
     1264big_int
     1265nano_timestamp (void)
     1266{
     1267  big_int ts;
     1268#if defined (WINDOWS32)
     1269  static int s_state = -1;
     1270  static LARGE_INTEGER s_freq;
     1271
     1272  if (s_state == -1)
     1273    s_state = QueryPerformanceFrequency (&s_freq);
     1274  if (s_state)
     1275    {
     1276      LARGE_INTEGER pc;
     1277      if (!QueryPerformanceCounter (&pc))
     1278        {
     1279          s_state = 0;
     1280          return nano_timestamp ();
     1281        }
     1282      ts = (big_int)((long double)pc.QuadPart / (long double)s_freq.QuadPart * 1000000000);
     1283    }
     1284  else
     1285    {
     1286      /* fall back to low resolution system time. */
     1287      LARGE_INTEGER bigint;
     1288      FILETIME ft = {0,0};
     1289      GetSystemTimeAsFileTime (&ft);
     1290      bigint.u.LowPart = ft.dwLowDateTime;
     1291      bigint.u.HighPart = ft.dwLowDateTime;
     1292      ts = bigint.QuadPart * 100;
     1293    }
     1294
     1295#elif HAVE_GETTIMEOFDAY
     1296/* FIXME: Linux and others have the realtime clock_* api, detect and use it. */
     1297  struct timeval tv;
     1298  if (!gettimeofday (&tv, NULL))
     1299    ts = (big_int)tv.tv_sec * 1000000000
     1300       + tv.tv_usec * 1000;
     1301  else
     1302    {
     1303      error (NILF, _("gettimeofday failed"));
     1304      ts = -1;
     1305    }
     1306
     1307#else
     1308# error "PORTME"
     1309#endif
     1310
     1311  return ts;
     1312}
     1313
     1314/* Formats the elapsed time (nano seconds) in the manner easiest
     1315   to read, with millisecond percision for larger numbers.  */
     1316
     1317int
     1318format_elapsed_nano (char *buf, size_t size, big_int ts)
     1319{
     1320  int sz;
     1321  if (ts < 1000)
     1322    sz = sprintf (buf, "%uns", (unsigned)ts);
     1323  else if (ts < 100000)
     1324    sz = sprintf (buf, "%u.%03uus",
     1325                  (unsigned)(ts / 1000),
     1326                  (unsigned)(ts % 1000));
     1327  else
     1328    {
     1329      ts /= 1000;
     1330      if (ts < 1000)
     1331        sz = sprintf (buf, "%uus", (unsigned)ts);
     1332      else if (ts < 100000)
     1333        sz = sprintf (buf, "%u.%03ums",
     1334                      (unsigned)(ts / 1000),
     1335                      (unsigned)(ts % 1000));
     1336      else
     1337        {
     1338          ts /= 1000;
     1339          if (ts < BIG_INT_C(60000))
     1340            sz = sprintf (buf,
     1341                          "%u.%03us",
     1342                          (unsigned)(ts / 1000),
     1343                          (unsigned)(ts % 1000));
     1344          else
     1345            sz = sprintf (buf,
     1346                          "%um%u.%03us",
     1347                          (unsigned)( ts / BIG_INT_C(60000)),
     1348                          (unsigned)((ts % BIG_INT_C(60000)) / 1000),
     1349                          (unsigned)((ts % BIG_INT_C(60000)) % 1000));
     1350        }
     1351    }
     1352  if (sz >= size)
     1353    fatal (NILF, _("format_elapsed_nano buffer overflow: %d written, %d buffer"),
     1354           sz, size);
     1355  return sz;
     1356}
     1357#endif /* CONFIG_WITH_PRINT_TIME_SWITCH */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette