Ignore:
Timestamp:
Mar 29, 2008, 2:49:27 AM (17 years ago)
Author:
bird
Message:

Added $(make-stats ) that provides access to memory and hash stats (if CONFIG_WITH_MAKE_STATS is defined).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/function.c

    r1409 r1438  
    116116
    117117static struct hash_table function_table;
     118
     119#ifdef CONFIG_WITH_MAKE_STATS
     120unsigned long make_stats_allocations = 0;
     121unsigned long make_stats_allocated = 0;
     122unsigned long make_stats_allocated_sum = 0;
     123unsigned long make_stats_ht_lookups = 0;
     124unsigned long make_stats_ht_collisions = 0;
     125#endif
    118126
    119127
     
    34603468#endif  /* CONFIG_WITH_OS2_LIBPATH */
    34613469
     3470#ifdef CONFIG_WITH_MAKE_STATS
     3471/* Retrieve make statistics. */
     3472static char *
     3473func_make_stats (char *o, char **argv, const char *funcname)
     3474{
     3475  char buf[512];
     3476  int len;
     3477
     3478  if (!argv[0] || (!argv[0][0] && !argv[1]))
     3479    {
     3480      len = sprintf (buf, "alloc-cur: %5lu %6luKB (/%3luMB)  hash: %5lu %2lu%%",
     3481                     make_stats_allocations,
     3482                     make_stats_allocated / 1024,
     3483                     make_stats_allocated_sum / (1024*1024),
     3484                     make_stats_ht_lookups,
     3485                     (make_stats_ht_collisions * 100) / make_stats_ht_lookups);
     3486      o = variable_buffer_output (o, buf, len);
     3487    }
     3488  else
     3489    {
     3490      /* selective */
     3491      int i;
     3492      for (i = 0; argv[i]; i++)
     3493        {
     3494          unsigned long val;
     3495          if (i != 0)
     3496            o = variable_buffer_output (o, " ", 1);
     3497          if (!strcmp(argv[i], "allocations"))
     3498            val = make_stats_allocations;
     3499          else if (!strcmp(argv[i], "allocated"))
     3500            val = make_stats_allocated;
     3501          else if (!strcmp(argv[i], "allocated_sum"))
     3502            val = make_stats_allocated_sum;
     3503          else if (!strcmp(argv[i], "ht_lookups"))
     3504            val = make_stats_ht_lookups;
     3505          else if (!strcmp(argv[i], "ht_collisions"))
     3506            val = make_stats_ht_collisions;
     3507          else if (!strcmp(argv[i], "ht_collisions_pct"))
     3508            val = (make_stats_ht_collisions * 100) / make_stats_ht_lookups;
     3509          else
     3510            { 
     3511              o = variable_buffer_output (o, argv[i], strlen (argv[i]));
     3512              continue;
     3513            }
     3514
     3515          len = sprintf (buf, "%ld", val);
     3516          o = variable_buffer_output (o, buf, len);
     3517        }
     3518    }
     3519  return o;
     3520}
     3521#endif
     3522
    34623523/* Lookup table for builtin functions.
    34633524
     
    35763637  { STRING_SIZE_TUPLE("libpath"),       1,  2,  1,  func_os2_libpath},
    35773638#endif
     3639#ifdef CONFIG_WITH_MAKE_STATS
     3640  { STRING_SIZE_TUPLE("make-stats"),    0, ~0,  0,  func_make_stats},
     3641#endif
    35783642#ifdef KMK_HELPERS
    35793643  { STRING_SIZE_TUPLE("kb-src-tool"),   1,  1,  0,  func_kbuild_source_tool},
Note: See TracChangeset for help on using the changeset viewer.