Changeset 3170 for trunk/src/kmk/kmkbuiltin.c
- Timestamp:
- Mar 21, 2018, 1:32:27 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin.c
r3169 r3170 36 36 # include <io.h> 37 37 #endif 38 39 #include "makeint.h" 40 #include "job.h" 38 41 #if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 39 # include "makeint.h"40 # include "job.h"41 42 # include "w32/winchildren.h" 42 43 #endif … … 231 232 * kmk built command. 232 233 */ 233 static const KMKBUILTINENTRY g_aBuilt ins[] =234 static const KMKBUILTINENTRY g_aBuiltIns[] = 234 235 { 235 236 #define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fMpSafe, fNeedEnv) \ … … 266 267 }; 267 268 269 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 270 /** Statistics running in parallel to g_aBuiltIns. */ 271 struct 272 { 273 big_int cNs; 274 unsigned cTimes; 275 unsigned cAsyncTimes; 276 } g_aBuiltInStats[sizeof(g_aBuiltIns) / sizeof(g_aBuiltIns[0])]; 277 #endif 278 268 279 269 280 int kmk_builtin_command_parsed(int argc, char **argv, struct child *pChild, char ***ppapszArgvToSpawn, pid_t *pPidSpawned) … … 325 336 * Look up the builtin command in the table. 326 337 */ 327 pEntry = &g_aBuilt ins[0];328 cLeft = sizeof(g_aBuilt ins) / sizeof(g_aBuiltins[0]);338 pEntry = &g_aBuiltIns[0]; 339 cLeft = sizeof(g_aBuiltIns) / sizeof(g_aBuiltIns[0]); 329 340 while (cLeft-- > 0) 330 341 if ( pEntry->uName.cchAndStart != cchAndStart … … 340 351 #if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 341 352 if (pEntry->fMpSafe) 353 { 342 354 rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, pEntry->fNeedEnv ? pChild->environment : NULL, 343 355 pChild, pPidSpawned); 356 # ifdef CONFIG_WITH_KMK_BUILTIN_STATS 357 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cAsyncTimes++; 358 # endif 359 } 344 360 else 345 361 #endif … … 350 366 * Call the worker function, making sure to preserve umask. 351 367 */ 368 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 369 big_int nsStart = nano_timestamp(); 370 #endif 352 371 int const iUmask = umask(0); /* save umask */ 353 372 umask(iUmask); … … 386 405 else 387 406 rc = 99; 407 388 408 g_progname = "kmk"; /* paranoia, make sure it's not pointing at a freed argv[0]. */ 389 409 umask(iUmask); /* restore it */ 410 411 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 412 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cTimes++; 413 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cNs += nano_timestamp() - nsStart; 414 #endif 390 415 } 391 416 return rc; … … 411 436 #endif 412 437 438 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 439 /** 440 * Prints the statistiscs to the given output stream. 441 */ 442 int kmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix) 443 { 444 const unsigned cEntries = sizeof(g_aBuiltInStats) / sizeof(g_aBuiltInStats[0]); 445 unsigned i; 446 fprintf(pOutput, "\n%skmk built-in command statistics:\n", pszPrefix); 447 for (i = 0; i < cEntries; i++) 448 if (g_aBuiltInStats[i].cTimes > 0) 449 { 450 char szTotal[64]; 451 char szAvg[64]; 452 format_elapsed_nano(szTotal, sizeof(szTotal), g_aBuiltInStats[i].cNs); 453 format_elapsed_nano(szAvg, sizeof(szAvg), g_aBuiltInStats[i].cNs / g_aBuiltInStats[i].cTimes); 454 fprintf(pOutput, "%s kmk_builtin_%-9s: %4lu times, %9s total, %9s/call\n", 455 pszPrefix, g_aBuiltIns[i].uName.s.sz, g_aBuiltInStats[i].cTimes, szTotal, szAvg); 456 } 457 else if (g_aBuiltInStats[i].cAsyncTimes > 0) 458 fprintf(pOutput, "%s kmk_builtin_%-9s: %4lu times in worker thread\n", 459 pszPrefix, g_aBuiltIns[i].uName.s.sz, g_aBuiltInStats[i].cAsyncTimes); 460 } 461 #endif 462
Note:
See TracChangeset
for help on using the changeset viewer.