[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Findutils-patches] [PATCH] Update estimated success rates from a survey
From: |
James Youngman |
Subject: |
[Findutils-patches] [PATCH] Update estimated success rates from a survey of a real file system. |
Date: |
Fri, 1 Jan 2016 09:39:35 +0000 |
* find/pred.c (print_optlist): output now distinguishes more
clearly between estimated and actual success rates.
* find/parser.c (insert_type): Use estimated success rates
computed by surveying a real file system. Use 4 digits of
precision for est_success_rate.
* find/tree.c (print_tree): Consistently use 4 digits of precision
for est_success_rate.
---
find/parser.c | 32 +++++++++++++++++++++++---------
find/pred.c | 34 +++++++++++++++++-----------------
find/tree.c | 2 +-
3 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/find/parser.c b/find/parser.c
index b57cdda..31f504b 100644
--- a/find/parser.c
+++ b/find/parser.c
@@ -2716,7 +2716,7 @@ insert_type (char **argv, int *arg_ptr,
{
mode_t type_cell;
struct predicate *our_pred;
- float rate = 0.5;
+ float rate = 0.01;
const char *typeletter;
if (collect_arg (argv, arg_ptr, &typeletter))
@@ -2729,28 +2729,38 @@ insert_type (char **argv, int *arg_ptr,
return false;
}
+ /* From a real system here are the counts of files by type:
+ Type Count Fraction
+ f 4410884 0.875
+ d 464722 0.0922
+ l 156662 0.0311
+ b 4476 0.000888
+ c 2233 0.000443
+ s 80 1.59e-05
+ p 38 7.54e-06
+ */
switch (typeletter[0])
{
case 'b': /* block special */
type_cell = S_IFBLK;
- rate = 0.01f;
+ rate = 0.000888f;
break;
case 'c': /* character special */
type_cell = S_IFCHR;
- rate = 0.01f;
+ rate = 0.000443f;
break;
case 'd': /* directory */
type_cell = S_IFDIR;
- rate = 0.4f;
+ rate = 0.0922f;
break;
case 'f': /* regular file */
type_cell = S_IFREG;
- rate = 0.95f;
+ rate = 0.875f;
break;
case 'l': /* symbolic link */
#ifdef S_IFLNK
type_cell = S_IFLNK;
- rate = 0.1f;
+ rate = 0.0311f;
#else
error (EXIT_FAILURE, 0,
_("-type %c is not supported because symbolic links "
@@ -2761,7 +2771,7 @@ insert_type (char **argv, int *arg_ptr,
case 'p': /* pipe */
#ifdef S_IFIFO
type_cell = S_IFIFO;
- rate = 0.01f;
+ rate = 7.554e-6f;
#else
error (EXIT_FAILURE, 0,
_("-type %c is not supported because FIFOs "
@@ -2772,7 +2782,7 @@ insert_type (char **argv, int *arg_ptr,
case 's': /* socket */
#ifdef S_IFSOCK
type_cell = S_IFSOCK;
- rate = 0.01f;
+ rate = 1.59e-5f;
#else
error (EXIT_FAILURE, 0,
_("-type %c is not supported because named sockets "
@@ -2783,7 +2793,11 @@ insert_type (char **argv, int *arg_ptr,
case 'D': /* Solaris door */
#ifdef S_IFDOOR
type_cell = S_IFDOOR;
- rate = 0.01f;
+ /* There are no Solaris doors on the example system surveyed
+ * above, but if someone uses -type D, they are presumably
+ * expecting to find a non-zero number. We guess at a
+ * rate. */
+ rate = 1.0e-5f;
#else
error (EXIT_FAILURE, 0,
_("-type %c is not supported because Solaris doors "
diff --git a/find/pred.c b/find/pred.c
index 32938fb..45f03f0 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -1270,25 +1270,25 @@ print_optlist (FILE *fp, const struct predicate *p)
{
print_parenthesised (fp, p->pred_left);
fprintf (fp,
- "%s%s%s",
- p->need_stat ? "[call stat] " : "",
- p->need_type ? "[need type] " : "",
- p->need_inum ? "[need inum] " : "");
+ "%s%s%s",
+ p->need_stat ? "[call stat] " : "",
+ p->need_type ? "[need type] " : "",
+ p->need_inum ? "[need inum] " : "");
print_predicate (fp, p);
- fprintf (fp, " [%g] ", p->est_success_rate);
+ fprintf (fp, " [est success rate %.4g] ", p->est_success_rate);
if (options.debug_options & DebugSuccessRates)
- {
- fprintf (fp, "[%ld/%ld", p->perf.successes, p->perf.visits);
- if (p->perf.visits)
- {
- double real_rate = (double)p->perf.successes /
(double)p->perf.visits;
- fprintf (fp, "=%g] ", real_rate);
- }
- else
- {
- fprintf (fp, "=_] ");
- }
- }
+ {
+ fprintf (fp, "[real success rate %ld/%ld", p->perf.successes,
p->perf.visits);
+ if (p->perf.visits)
+ {
+ double real_rate = (double)p->perf.successes /
(double)p->perf.visits;
+ fprintf (fp, "=%.4g] ", real_rate);
+ }
+ else
+ {
+ fprintf (fp, "=_] ");
+ }
+ }
print_parenthesised (fp, p->pred_right);
}
}
diff --git a/find/tree.c b/find/tree.c
index 026dead..1ab6818 100644
--- a/find/tree.c
+++ b/find/tree.c
@@ -1686,7 +1686,7 @@ print_tree (FILE *fp, struct predicate *node, int indent)
print_predicate (fp, node);
fprintf (fp, "] type=%s prec=%s",
type_name (node->p_type), prec_name (node->p_prec));
- fprintf (fp, " cost=%s rate=%#03.2g %sside effects ",
+ fprintf (fp, " cost=%s est_success_rate=%#.4g %sside effects ",
cost_name (node->p_cost),
node->est_success_rate,
(node->side_effects ? "" : "no "));
--
2.1.4
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Findutils-patches] [PATCH] Update estimated success rates from a survey of a real file system.,
James Youngman <=