VirtualBox

Changeset 3170 in kBuild


Ignore:
Timestamp:
Mar 21, 2018 12:32:27 PM (7 years ago)
Author:
bird
Message:

kmkbuiltin: stats

Location:
trunk/src/kmk
Files:
6 edited

Legend:

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

    r3156 r3170  
    225225 kmk_DEFS += CONFIG_WITH_MAKE_STATS
    226226endif
     227ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     228 kmk_DEFS += CONFIG_WITH_KMK_BUILTIN_STATS
     229endif
    227230ifdef CONFIG_WITH_EVAL_COMPILER
    228231 kmk_DEFS += CONFIG_WITH_EVAL_COMPILER
     
    231234 kmk_DEFS += CONFIG_WITH_COMPILE_EVERYTHING
    232235endif
     236
    233237#ifeq ($(KBUILD_TYPE).$(USERNAME),debug.bird)
    234238# kmk_DEFS += CONFIG_WITH_COMPILER CONFIG_WITH_EVAL_COMPILER CONFIG_WITH_COMPILE_EVERYTHING
  • trunk/src/kmk/kmkbuiltin.c

    r3169 r3170  
    3636# include <io.h>
    3737#endif
     38
     39#include "makeint.h"
     40#include "job.h"
    3841#if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
    39 # include "makeint.h"
    40 # include "job.h"
    4142# include "w32/winchildren.h"
    4243#endif
     
    231232 * kmk built command.
    232233 */
    233 static const KMKBUILTINENTRY g_aBuiltins[] =
     234static const KMKBUILTINENTRY g_aBuiltIns[] =
    234235{
    235236#define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fMpSafe, fNeedEnv) \
     
    266267};
    267268
     269#ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     270/** Statistics running in parallel to g_aBuiltIns. */
     271struct
     272{
     273    big_int         cNs;
     274    unsigned        cTimes;
     275    unsigned        cAsyncTimes;
     276} g_aBuiltInStats[sizeof(g_aBuiltIns) / sizeof(g_aBuiltIns[0])];
     277#endif
     278
    268279
    269280int kmk_builtin_command_parsed(int argc, char **argv, struct child *pChild, char ***ppapszArgvToSpawn, pid_t *pPidSpawned)
     
    325336         * Look up the builtin command in the table.
    326337         */
    327         pEntry  = &g_aBuiltins[0];
    328         cLeft   = sizeof(g_aBuiltins) / sizeof(g_aBuiltins[0]);
     338        pEntry  = &g_aBuiltIns[0];
     339        cLeft   = sizeof(g_aBuiltIns) / sizeof(g_aBuiltIns[0]);
    329340        while (cLeft-- > 0)
    330341            if (   pEntry->uName.cchAndStart != cchAndStart
     
    340351#if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
    341352                if (pEntry->fMpSafe)
     353                {
    342354                    rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, pEntry->fNeedEnv ? pChild->environment : NULL,
    343355                                                 pChild, pPidSpawned);
     356# ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     357                    g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cAsyncTimes++;
     358# endif
     359                }
    344360                else
    345361#endif
     
    350366                     * Call the worker function, making sure to preserve umask.
    351367                     */
     368#ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     369                    big_int nsStart = nano_timestamp();
     370#endif
    352371                    int const iUmask = umask(0);        /* save umask */
    353372                    umask(iUmask);
     
    386405                    else
    387406                        rc = 99;
     407
    388408                    g_progname = "kmk";                 /* paranoia, make sure it's not pointing at a freed argv[0]. */
    389409                    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
    390415                }
    391416                return rc;
     
    411436#endif
    412437
     438#ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     439/**
     440 * Prints the statistiscs to the given output stream.
     441 */
     442int 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
  • trunk/src/kmk/kmkbuiltin.h

    r3169 r3170  
    139139extern int kBuiltinOptChDir(char *pszCwd, size_t cbCwdBuf, const char *pszValue);
    140140
     141#ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     142int kmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix);
    141143#endif
    142144
     145#endif
     146
  • trunk/src/kmk/main.c

    r3161 r3170  
    2727#ifdef KMK
    2828# include "kbuild.h"
     29#endif
     30#ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     31# include "kmkbuiltin.h"
    2932#endif
    3033
     
    41744177
    41754178  /* Allocators: */
    4176 #ifdef CONFIG_WITH_COMPILER
     4179# ifdef CONFIG_WITH_COMPILER
    41774180  kmk_cc_print_stats ();
    4178 #endif
     4181# endif
    41794182# ifndef CONFIG_WITH_STRCACHE2
    41804183  strcache_print_stats ("#");
     
    41944197  print_kbuild_define_stats ();
    41954198# endif
     4199# ifdef CONFIG_WITH_KMK_BUILTIN_STATS
     4200  kmk_builtin_print_stats (stdout, "# ");
     4201# endif
    41964202# ifdef CONFIG_WITH_COMPILER
    41974203  kmk_cc_print_stats ();
     
    42014207  printf (_("\n# Finished Make statistics on %s\n"), ctime (&when));
    42024208}
    4203 #endif
     4209#endif /* CONFIG_WITH_PRINT_STATS_SWITCH */
    42044210
    42054211static void
  • trunk/src/kmk/makeint.h

    r3162 r3170  
    11761176#endif
    11771177
    1178 #if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH)
     1178#if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH) || defined(CONFIG_WITH_KMK_BUILTIN_STATS)
    11791179/* misc.c */
    11801180extern big_int nano_timestamp (void);
  • trunk/src/kmk/misc.c

    r3140 r3170  
    11521152#endif /* CONFIG_WITH_PRINT_STATS_SWITCH */
    11531153
    1154 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     1154#if defined(CONFIG_WITH_PRINT_TIME_SWITCH) || defined(CONFIG_WITH_KMK_BUILTIN_STATS)
    11551155/* Get a nanosecond timestamp, from a monotonic time source if
    11561156   possible.  Returns -1 after calling error() on failure.  */
     
    12491249  return sz;
    12501250}
    1251 #endif /* CONFIG_WITH_PRINT_TIME_SWITCH */
    1252 
     1251#endif /* CONFIG_WITH_PRINT_TIME_SWITCH || defined(CONFIG_WITH_KMK_BUILTIN_STATS) */
     1252
Note: See TracChangeset for help on using the changeset viewer.

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