Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/nbperf Add support for build as part of the toolchai...
details: https://anonhg.NetBSD.org/src/rev/45a85b66674f
branches: trunk
changeset: 770550:45a85b66674f
user: joerg <joerg%NetBSD.org@localhost>
date: Fri Oct 21 23:47:11 2011 +0000
description:
Add support for build as part of the toolchain. Add option for
deterministic output (-p), which replaces the random seed with a
incremental counter.
diffstat:
usr.bin/nbperf/graph2.c | 8 ++++++--
usr.bin/nbperf/graph3.c | 8 ++++++--
usr.bin/nbperf/nbperf-bdz.c | 8 ++++++--
usr.bin/nbperf/nbperf-chm.c | 7 +++++--
usr.bin/nbperf/nbperf.1 | 17 ++++++++++++-----
usr.bin/nbperf/nbperf.c | 35 ++++++++++++++++++++++++++++-------
6 files changed, 63 insertions(+), 20 deletions(-)
diffs (242 lines):
diff -r 23b2094a687e -r 45a85b66674f usr.bin/nbperf/graph2.c
--- a/usr.bin/nbperf/graph2.c Fri Oct 21 23:45:56 2011 +0000
+++ b/usr.bin/nbperf/graph2.c Fri Oct 21 23:47:11 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: graph2.c,v 1.3 2010/03/03 01:55:04 joerg Exp $ */
+/* $NetBSD: graph2.c,v 1.4 2011/10/21 23:47:11 joerg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -31,8 +31,12 @@
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <sys/cdefs.h>
-__RCSID("$NetBSD: graph2.c,v 1.3 2010/03/03 01:55:04 joerg Exp $");
+__RCSID("$NetBSD: graph2.c,v 1.4 2011/10/21 23:47:11 joerg Exp $");
#include <err.h>
#include <inttypes.h>
diff -r 23b2094a687e -r 45a85b66674f usr.bin/nbperf/graph3.c
--- a/usr.bin/nbperf/graph3.c Fri Oct 21 23:45:56 2011 +0000
+++ b/usr.bin/nbperf/graph3.c Fri Oct 21 23:47:11 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: graph3.c,v 1.3 2010/03/03 01:55:04 joerg Exp $ */
+/* $NetBSD: graph3.c,v 1.4 2011/10/21 23:47:11 joerg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -31,8 +31,12 @@
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <sys/cdefs.h>
-__RCSID("$NetBSD: graph3.c,v 1.3 2010/03/03 01:55:04 joerg Exp $");
+__RCSID("$NetBSD: graph3.c,v 1.4 2011/10/21 23:47:11 joerg Exp $");
#include <err.h>
#include <inttypes.h>
diff -r 23b2094a687e -r 45a85b66674f usr.bin/nbperf/nbperf-bdz.c
--- a/usr.bin/nbperf/nbperf-bdz.c Fri Oct 21 23:45:56 2011 +0000
+++ b/usr.bin/nbperf/nbperf-bdz.c Fri Oct 21 23:47:11 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nbperf-bdz.c,v 1.3 2010/03/01 21:46:58 joerg Exp $ */
+/* $NetBSD: nbperf-bdz.c,v 1.4 2011/10/21 23:47:11 joerg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -31,8 +31,12 @@
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <sys/cdefs.h>
-__RCSID("$NetBSD: nbperf-bdz.c,v 1.3 2010/03/01 21:46:58 joerg Exp $");
+__RCSID("$NetBSD: nbperf-bdz.c,v 1.4 2011/10/21 23:47:11 joerg Exp $");
#include <err.h>
#include <inttypes.h>
diff -r 23b2094a687e -r 45a85b66674f usr.bin/nbperf/nbperf-chm.c
--- a/usr.bin/nbperf/nbperf-chm.c Fri Oct 21 23:45:56 2011 +0000
+++ b/usr.bin/nbperf/nbperf-chm.c Fri Oct 21 23:47:11 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nbperf-chm.c,v 1.2 2009/08/24 17:12:46 joerg Exp $ */
+/* $NetBSD: nbperf-chm.c,v 1.3 2011/10/21 23:47:11 joerg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -30,9 +30,12 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: nbperf-chm.c,v 1.2 2009/08/24 17:12:46 joerg Exp $");
+__RCSID("$NetBSD: nbperf-chm.c,v 1.3 2011/10/21 23:47:11 joerg Exp $");
#include <err.h>
#include <inttypes.h>
diff -r 23b2094a687e -r 45a85b66674f usr.bin/nbperf/nbperf.1
--- a/usr.bin/nbperf/nbperf.1 Fri Oct 21 23:45:56 2011 +0000
+++ b/usr.bin/nbperf/nbperf.1 Fri Oct 21 23:47:11 2011 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: nbperf.1,v 1.2 2010/03/03 01:55:04 joerg Exp $
+.\" $NetBSD: nbperf.1,v 1.3 2011/10/21 23:47:11 joerg Exp $
.\"
.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd March 3, 2010
+.Dd October 20, 2011
.Dt NBPERF 1
.Os
.Sh NAME
@@ -35,7 +35,7 @@
.Nd compute a perfect hash function
.Sh SYNOPSIS
.Nm
-.Op Fl s
+.Op Fl ps
.Op Fl a Ar algorithm
.Op Fl c Ar utilisation
.Op Fl h Ar hash
@@ -124,9 +124,16 @@
After each failing iteration, a dot is written to stderr.
.Pp
.Nm
-checks for duplicate keys on the first iteration that passed basic hash distribution
-tests.
+checks for duplicate keys on the first iteration that passed
+basic hash distribution tests.
In that case, an error message is printed and the program terminates.
+.Pp
+If the
+.Fl p
+flag is specified, the hash function is seeded in a stable way.
+This may take longer than the normal random seed, but ensures
+that the output is the same for repeated invocations as long as
+the input is constant.
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
diff -r 23b2094a687e -r 45a85b66674f usr.bin/nbperf/nbperf.c
--- a/usr.bin/nbperf/nbperf.c Fri Oct 21 23:45:56 2011 +0000
+++ b/usr.bin/nbperf/nbperf.c Fri Oct 21 23:47:11 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nbperf.c,v 1.3 2010/03/03 01:55:04 joerg Exp $ */
+/* $NetBSD: nbperf.c,v 1.4 2011/10/21 23:47:11 joerg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -31,8 +31,12 @@
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <sys/cdefs.h>
-__RCSID("$NetBSD: nbperf.c,v 1.3 2010/03/03 01:55:04 joerg Exp $");
+__RCSID("$NetBSD: nbperf.c,v 1.4 2011/10/21 23:47:11 joerg Exp $");
#include <sys/endian.h>
#include <err.h>
@@ -45,20 +49,30 @@
#include "nbperf.h"
+static int predictable;
+
static __dead
void usage(void)
{
fprintf(stderr,
- "%s [-s] [-c utilisation] [-i iterations] [-n name] "
+ "%s [-ps] [-c utilisation] [-i iterations] [-n name] "
"[-o output] input\n",
getprogname());
exit(1);
}
+#if HAVE_NBTOOL_CONFIG_H && !defined(__NetBSD__)
+#define arc4random() rand()
+#endif
+
static void
mi_vector_hash_seed_hash(struct nbperf *nbperf)
{
- nbperf->seed[0] = arc4random();
+ static uint32_t predictable_counter;
+ if (predictable)
+ nbperf->seed[0] = predictable_counter++;
+ else
+ nbperf->seed[0] = arc4random();
}
static void
@@ -107,7 +121,8 @@
FILE *input;
size_t curlen = 0, curalloc = 0;
char *line, *eos;
- size_t line_len;
+ ssize_t line_len;
+ size_t line_allocated;
const void **keys = NULL;
size_t *keylens = NULL;
uint32_t max_iterations = 0xffffffU;
@@ -117,7 +132,7 @@
set_hash(&nbperf, "mi_vector_hash");
- while ((ch = getopt(argc, argv, "a:c:h:i:m:n:o:s")) != -1) {
+ while ((ch = getopt(argc, argv, "a:c:h:i:m:n:o:ps")) != -1) {
switch (ch) {
case 'a':
if (strcmp(optarg, "chm") == 0)
@@ -164,6 +179,9 @@
if (nbperf.output == NULL)
err(2, "cannot open output file");
break;
+ case 'p':
+ predictable = 1;
+ break;
case 's':
nbperf.static_hash = 1;
break;
@@ -188,7 +206,9 @@
if (nbperf.output == NULL)
nbperf.output = stdout;
- while ((line = fgetln(input, &line_len)) != NULL) {
+ line = NULL;
+ line_allocated = 0;
+ while ((line_len = getline(&line, &line_allocated, input)) != -1) {
if (line_len && line[line_len - 1] == '\n')
--line_len;
if (curlen == curalloc) {
@@ -209,6 +229,7 @@
keylens[curlen] = line_len;
++curlen;
}
+ free(line);
if (input != stdin)
fclose(input);
Home |
Main Index |
Thread Index |
Old Index