Changeset 2101 in kBuild
- Timestamp:
- Nov 24, 2008 11:35:56 PM (16 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/Makefile.am
r2091 r2101 144 144 -DCONFIG_PRETTY_COMMAND_PRINTING \ 145 145 -DCONFIG_WITH_PRINT_STATS_SWITCH \ 146 -DCONFIG_WITH_PRINT_TIME_SWITCH \ 146 147 -DCONFIG_WITH_RDONLY_VARIABLE_VALUE \ 147 148 -DCONFIG_WITH_LAZY_DEPS_VARS \ -
trunk/src/kmk/Makefile.kmk
r2091 r2101 170 170 CONFIG_PRETTY_COMMAND_PRINTING \ 171 171 CONFIG_WITH_PRINT_STATS_SWITCH \ 172 CONFIG_WITH_PRINT_TIME_SWITCH \ 172 173 CONFIG_WITH_RDONLY_VARIABLE_VALUE \ 173 174 CONFIG_WITH_LAZY_DEPS_VARS \ -
trunk/src/kmk/function.c
r2025 r2101 45 45 #if defined (CONFIG_WITH_MATH) || defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_FILE_SIZE) /* bird */ 46 46 # 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 47 typedef big_int math_int; 53 48 static char *math_int_to_variable_buffer (char *, math_int); 54 49 #endif … … 4102 4097 func_nanots (char *o, char **argv, const char *funcname) 4103 4098 { 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 ()); 4151 4100 } 4152 4101 #endif -
trunk/src/kmk/job.c
r2056 r2101 209 209 static int job_next_command (struct child *); 210 210 static int start_waiting_job (struct child *); 211 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH 212 static void print_job_time (struct child *); 213 #endif 211 214 212 215 … … 901 904 free_child (struct child *child) 902 905 { 906 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH 907 print_job_time (child); 908 #endif 903 909 if (!jobserver_tokens) 904 910 fatal (NILF, "INTERNAL: Freeing child 0x%08lx (%s) but no tokens left!\n", … … 1064 1070 if (!child->command_ptr) 1065 1071 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 1066 1077 1067 1078 /* Combine the flags parsed for the line itself with … … 1821 1832 c->command_lines = lines; 1822 1833 c->sh_batch_file = NULL; 1834 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH 1835 c->start_ts = -1; 1836 #endif 1823 1837 1824 1838 /* Cache dontcare flag because file->dontcare can be changed once we … … 3422 3436 #endif /* !HAPE_DUP2 && !_AMIGA */ 3423 3437 3438 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH 3439 /* Prints the time elapsed while executing the commands for the given job. */ 3440 void 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 3424 3459 /* On VMS systems, include special VMS functions. */ 3425 3460 -
trunk/src/kmk/job.h
r1993 r2101 67 67 unsigned int deleted:1; /* Nonzero if targets have been deleted. */ 68 68 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 69 72 }; 70 73 -
trunk/src/kmk/main.c
r2099 r2101 183 183 184 184 int print_stats_flag; 185 #endif 186 187 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH 188 /* Minimum number of seconds to report, -1 if disabled. */ 189 190 int print_time_min = -1; 191 static int default_print_time_min = -1; 192 static int no_val_print_time_min = 0; 193 static big_int make_start_ts = -1; 194 int print_time_width = 5; 185 195 #endif 186 196 … … 491 501 "print-stats" }, 492 502 #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 493 508 #ifdef KMK 494 { CHAR_MAX+1 2, positive_int, (char *) &process_priority, 1, 1, 0,509 { CHAR_MAX+14, positive_int, (char *) &process_priority, 1, 1, 0, 495 510 (char *) &process_priority, (char *) &process_priority, "priority" }, 496 { CHAR_MAX+1 4, positive_int, (char *) &process_affinity, 1, 1, 0,511 { CHAR_MAX+15, positive_int, (char *) &process_affinity, 1, 1, 0, 497 512 (char *) &process_affinity, (char *) &process_affinity, "affinity" }, 498 513 #endif … … 505 520 "no-keep-going" }, 506 521 #if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS) 507 { CHAR_MAX+1 5, flag, (char *) &make_expensive_statistics, 1, 1, 1, 0, 0,522 { CHAR_MAX+16, flag, (char *) &make_expensive_statistics, 1, 1, 1, 0, 0, 508 523 "statistics" }, 509 524 #endif … … 1313 1328 SetUnhandledExceptionFilter(handle_runtime_exceptions); 1314 1329 #endif /* !ELECTRIC_HEAP */ 1330 1331 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH 1332 make_start_ts = nano_timestamp (); 1333 #endif 1315 1334 1316 1335 /* start off assuming we have no shell */ … … 3566 3585 make_expensive_statistics ? "1" : "0", o_default, 1); 3567 3586 # 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 3568 3592 } 3569 3593 #endif … … 3811 3835 if (directory_before_chdir != 0) 3812 3836 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 3813 3850 3814 3851 log_working_directory (0); -
trunk/src/kmk/make.h
r2050 r2101 442 442 443 443 #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 450 typedef __int64 big_int; 451 # define BIG_INT_C(c) (c ## LL) 452 typedef unsigned __int64 big_uint; 453 # define BIG_UINT_C(c) (c ## ULL) 454 # else 455 # include <stdint.h> 456 typedef int64_t big_int; 457 # define BIG_INT_C(c) INT64_C(c) 458 typedef uint64_t big_uint; 459 # define BIG_UINT_C(c) UINT64_C(c) 460 # endif 461 #endif 444 462 445 463 … … 691 709 #ifdef CONFIG_PRETTY_COMMAND_PRINTING 692 710 extern int pretty_command_printing; 711 #endif 712 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH 713 extern int print_time_min, print_time_width; 693 714 #endif 694 715 #if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS) … … 896 917 extern char *func_breakpoint(char *o, char **argv, const char *funcname); 897 918 #endif 919 920 #if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH) 921 /* misc.c */ 922 extern big_int nano_timestamp (void); 923 extern int format_elapsed_nano (char *buf, size_t size, big_int ts); 924 #endif 925 -
trunk/src/kmk/misc.c
r2062 r2101 29 29 # if defined(__GLIBC__) || defined(HAVE_MALLINFO) 30 30 # 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> 31 37 # endif 32 38 #endif … … 1164 1170 #ifdef CONFIG_WITH_PRINT_STATS_SWITCH 1165 1171 /* Print heap statistics if supported by the platform. */ 1166 void print_heap_stats (void) 1172 void 1173 print_heap_stats (void) 1167 1174 { 1168 1175 /* Darwin / Mac OS X */ … … 1251 1258 #endif /* CONFIG_WITH_PRINT_STATS_SWITCH */ 1252 1259 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 1264 big_int 1265 nano_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 1317 int 1318 format_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.