@@ -221,8 +221,8 @@ class Stats {
221
221
double micros = now - last_op_finish_;
222
222
hist_.Add (micros);
223
223
if (micros > 20000 ) {
224
- fprintf (stderr, " long op: %.1f micros%30s\r " , micros, " " );
225
- fflush (stderr);
224
+ std:: fprintf (stderr, " long op: %.1f micros%30s\r " , micros, " " );
225
+ std:: fflush (stderr);
226
226
}
227
227
last_op_finish_ = now;
228
228
}
@@ -243,8 +243,8 @@ class Stats {
243
243
next_report_ += 50000 ;
244
244
else
245
245
next_report_ += 100000 ;
246
- fprintf (stderr, " ... finished %d ops%30s\r " , done_, " " );
247
- fflush (stderr);
246
+ std:: fprintf (stderr, " ... finished %d ops%30s\r " , done_, " " );
247
+ std:: fflush (stderr);
248
248
}
249
249
}
250
250
@@ -261,18 +261,20 @@ class Stats {
261
261
// elapsed times.
262
262
double elapsed = (finish_ - start_) * 1e-6 ;
263
263
char rate[100 ];
264
- snprintf (rate, sizeof (rate), " %6.1f MB/s" ,
265
- (bytes_ / 1048576.0 ) / elapsed);
264
+ std:: snprintf (rate, sizeof (rate), " %6.1f MB/s" ,
265
+ (bytes_ / 1048576.0 ) / elapsed);
266
266
extra = rate;
267
267
}
268
268
AppendWithSpace (&extra, message_);
269
269
270
- fprintf (stdout, " %-12s : %11.3f micros/op;%s%s\n " , name.ToString ().c_str (),
271
- seconds_ * 1e6 / done_, (extra.empty () ? " " : " " ), extra.c_str ());
270
+ std::fprintf (stdout, " %-12s : %11.3f micros/op;%s%s\n " ,
271
+ name.ToString ().c_str (), seconds_ * 1e6 / done_,
272
+ (extra.empty () ? " " : " " ), extra.c_str ());
272
273
if (FLAGS_histogram) {
273
- fprintf (stdout, " Microseconds per op:\n %s\n " , hist_.ToString ().c_str ());
274
+ std::fprintf (stdout, " Microseconds per op:\n %s\n " ,
275
+ hist_.ToString ().c_str ());
274
276
}
275
- fflush (stdout);
277
+ std:: fflush (stdout);
276
278
}
277
279
};
278
280
@@ -323,51 +325,55 @@ class Benchmark {
323
325
void PrintHeader () {
324
326
const int kKeySize = 16 ;
325
327
PrintEnvironment ();
326
- fprintf (stdout, " Keys: %d bytes each\n " , kKeySize );
327
- fprintf (stdout, " Values: %d bytes each (%d bytes after compression)\n " ,
328
- FLAGS_value_size,
329
- static_cast <int >(FLAGS_value_size * FLAGS_compression_ratio + 0.5 ));
330
- fprintf (stdout, " Entries: %d\n " , num_);
331
- fprintf (stdout, " RawSize: %.1f MB (estimated)\n " ,
332
- ((static_cast <int64_t >(kKeySize + FLAGS_value_size) * num_) /
333
- 1048576.0 ));
334
- fprintf (stdout, " FileSize: %.1f MB (estimated)\n " ,
335
- (((kKeySize + FLAGS_value_size * FLAGS_compression_ratio) * num_) /
336
- 1048576.0 ));
328
+ std::fprintf (stdout, " Keys: %d bytes each\n " , kKeySize );
329
+ std::fprintf (
330
+ stdout, " Values: %d bytes each (%d bytes after compression)\n " ,
331
+ FLAGS_value_size,
332
+ static_cast <int >(FLAGS_value_size * FLAGS_compression_ratio + 0.5 ));
333
+ std::fprintf (stdout, " Entries: %d\n " , num_);
334
+ std::fprintf (stdout, " RawSize: %.1f MB (estimated)\n " ,
335
+ ((static_cast <int64_t >(kKeySize + FLAGS_value_size) * num_) /
336
+ 1048576.0 ));
337
+ std::fprintf (
338
+ stdout, " FileSize: %.1f MB (estimated)\n " ,
339
+ (((kKeySize + FLAGS_value_size * FLAGS_compression_ratio) * num_) /
340
+ 1048576.0 ));
337
341
PrintWarnings ();
338
- fprintf (stdout, " ------------------------------------------------\n " );
342
+ std:: fprintf (stdout, " ------------------------------------------------\n " );
339
343
}
340
344
341
345
void PrintWarnings () {
342
346
#if defined(__GNUC__) && !defined(__OPTIMIZE__)
343
- fprintf (
347
+ std:: fprintf (
344
348
stdout,
345
349
" WARNING: Optimization is disabled: benchmarks unnecessarily slow\n " );
346
350
#endif
347
351
#ifndef NDEBUG
348
- fprintf (stdout,
349
- " WARNING: Assertions are enabled; benchmarks unnecessarily slow\n " );
352
+ std::fprintf (
353
+ stdout,
354
+ " WARNING: Assertions are enabled; benchmarks unnecessarily slow\n " );
350
355
#endif
351
356
352
357
// See if snappy is working by attempting to compress a compressible string
353
358
const char text[] = " yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" ;
354
359
std::string compressed;
355
360
if (!port::Snappy_Compress (text, sizeof (text), &compressed)) {
356
- fprintf (stdout, " WARNING: Snappy compression is not enabled\n " );
361
+ std:: fprintf (stdout, " WARNING: Snappy compression is not enabled\n " );
357
362
} else if (compressed.size () >= sizeof (text)) {
358
- fprintf (stdout, " WARNING: Snappy compression is not effective\n " );
363
+ std:: fprintf (stdout, " WARNING: Snappy compression is not effective\n " );
359
364
}
360
365
}
361
366
362
367
void PrintEnvironment () {
363
- fprintf (stderr, " LevelDB: version %d.%d\n " , kMajorVersion ,
364
- kMinorVersion );
368
+ std:: fprintf (stderr, " LevelDB: version %d.%d\n " , kMajorVersion ,
369
+ kMinorVersion );
365
370
366
371
#if defined(__linux)
367
372
time_t now = time (nullptr );
368
- fprintf (stderr, " Date: %s" , ctime (&now)); // ctime() adds newline
373
+ std::fprintf (stderr, " Date: %s" ,
374
+ ctime (&now)); // ctime() adds newline
369
375
370
- FILE* cpuinfo = fopen (" /proc/cpuinfo" , " r" );
376
+ FILE* cpuinfo = std:: fopen (" /proc/cpuinfo" , " r" );
371
377
if (cpuinfo != nullptr ) {
372
378
char line[1000 ];
373
379
int num_cpus = 0 ;
@@ -387,9 +393,9 @@ class Benchmark {
387
393
cache_size = val.ToString ();
388
394
}
389
395
}
390
- fclose (cpuinfo);
391
- fprintf (stderr, " CPU: %d * %s\n " , num_cpus, cpu_type.c_str ());
392
- fprintf (stderr, " CPUCache: %s\n " , cache_size.c_str ());
396
+ std:: fclose (cpuinfo);
397
+ std:: fprintf (stderr, " CPU: %d * %s\n " , num_cpus, cpu_type.c_str ());
398
+ std:: fprintf (stderr, " CPUCache: %s\n " , cache_size.c_str ());
393
399
}
394
400
#endif
395
401
}
@@ -516,14 +522,15 @@ class Benchmark {
516
522
PrintStats (" leveldb.sstables" );
517
523
} else {
518
524
if (!name.empty ()) { // No error message for empty name
519
- fprintf (stderr, " unknown benchmark '%s'\n " , name.ToString ().c_str ());
525
+ std::fprintf (stderr, " unknown benchmark '%s'\n " ,
526
+ name.ToString ().c_str ());
520
527
}
521
528
}
522
529
523
530
if (fresh_db) {
524
531
if (FLAGS_use_existing_db) {
525
- fprintf (stdout, " %-12s : skipped (--use_existing_db is true)\n " ,
526
- name.ToString ().c_str ());
532
+ std:: fprintf (stdout, " %-12s : skipped (--use_existing_db is true)\n " ,
533
+ name.ToString ().c_str ());
527
534
method = nullptr ;
528
535
} else {
529
536
delete db_;
@@ -625,7 +632,7 @@ class Benchmark {
625
632
bytes += size;
626
633
}
627
634
// Print so result is not dead
628
- fprintf (stderr, " ... crc=0x%x\r " , static_cast <unsigned int >(crc));
635
+ std:: fprintf (stderr, " ... crc=0x%x\r " , static_cast <unsigned int >(crc));
629
636
630
637
thread->stats .AddBytes (bytes);
631
638
thread->stats .AddMessage (label);
@@ -649,8 +656,8 @@ class Benchmark {
649
656
thread->stats .AddMessage (" (snappy failure)" );
650
657
} else {
651
658
char buf[100 ];
652
- snprintf (buf, sizeof (buf), " (output: %.1f%%)" ,
653
- (produced * 100.0 ) / bytes);
659
+ std:: snprintf (buf, sizeof (buf), " (output: %.1f%%)" ,
660
+ (produced * 100.0 ) / bytes);
654
661
thread->stats .AddMessage (buf);
655
662
thread->stats .AddBytes (bytes);
656
663
}
@@ -692,8 +699,8 @@ class Benchmark {
692
699
options.reuse_logs = FLAGS_reuse_logs;
693
700
Status s = DB::Open (options, FLAGS_db, &db_);
694
701
if (!s.ok ()) {
695
- fprintf (stderr, " open error: %s\n " , s.ToString ().c_str ());
696
- exit (1 );
702
+ std:: fprintf (stderr, " open error: %s\n " , s.ToString ().c_str ());
703
+ std:: exit (1 );
697
704
}
698
705
}
699
706
@@ -712,7 +719,7 @@ class Benchmark {
712
719
void DoWrite (ThreadState* thread, bool seq) {
713
720
if (num_ != FLAGS_num) {
714
721
char msg[100 ];
715
- snprintf (msg, sizeof (msg), " (%d ops)" , num_);
722
+ std:: snprintf (msg, sizeof (msg), " (%d ops)" , num_);
716
723
thread->stats .AddMessage (msg);
717
724
}
718
725
@@ -725,15 +732,15 @@ class Benchmark {
725
732
for (int j = 0 ; j < entries_per_batch_; j++) {
726
733
const int k = seq ? i + j : (thread->rand .Next () % FLAGS_num);
727
734
char key[100 ];
728
- snprintf (key, sizeof (key), " %016d" , k);
735
+ std:: snprintf (key, sizeof (key), " %016d" , k);
729
736
batch.Put (key, gen.Generate (value_size_));
730
737
bytes += value_size_ + strlen (key);
731
738
thread->stats .FinishedSingleOp ();
732
739
}
733
740
s = db_->Write (write_options_, &batch);
734
741
if (!s.ok ()) {
735
- fprintf (stderr, " put error: %s\n " , s.ToString ().c_str ());
736
- exit (1 );
742
+ std:: fprintf (stderr, " put error: %s\n " , s.ToString ().c_str ());
743
+ std:: exit (1 );
737
744
}
738
745
}
739
746
thread->stats .AddBytes (bytes);
@@ -772,14 +779,14 @@ class Benchmark {
772
779
for (int i = 0 ; i < reads_; i++) {
773
780
char key[100 ];
774
781
const int k = thread->rand .Next () % FLAGS_num;
775
- snprintf (key, sizeof (key), " %016d" , k);
782
+ std:: snprintf (key, sizeof (key), " %016d" , k);
776
783
if (db_->Get (options, key, &value).ok ()) {
777
784
found++;
778
785
}
779
786
thread->stats .FinishedSingleOp ();
780
787
}
781
788
char msg[100 ];
782
- snprintf (msg, sizeof (msg), " (%d of %d found)" , found, num_);
789
+ std:: snprintf (msg, sizeof (msg), " (%d of %d found)" , found, num_);
783
790
thread->stats .AddMessage (msg);
784
791
}
785
792
@@ -789,7 +796,7 @@ class Benchmark {
789
796
for (int i = 0 ; i < reads_; i++) {
790
797
char key[100 ];
791
798
const int k = thread->rand .Next () % FLAGS_num;
792
- snprintf (key, sizeof (key), " %016d." , k);
799
+ std:: snprintf (key, sizeof (key), " %016d." , k);
793
800
db_->Get (options, key, &value);
794
801
thread->stats .FinishedSingleOp ();
795
802
}
@@ -802,7 +809,7 @@ class Benchmark {
802
809
for (int i = 0 ; i < reads_; i++) {
803
810
char key[100 ];
804
811
const int k = thread->rand .Next () % range;
805
- snprintf (key, sizeof (key), " %016d" , k);
812
+ std:: snprintf (key, sizeof (key), " %016d" , k);
806
813
db_->Get (options, key, &value);
807
814
thread->stats .FinishedSingleOp ();
808
815
}
@@ -815,14 +822,14 @@ class Benchmark {
815
822
Iterator* iter = db_->NewIterator (options);
816
823
char key[100 ];
817
824
const int k = thread->rand .Next () % FLAGS_num;
818
- snprintf (key, sizeof (key), " %016d" , k);
825
+ std:: snprintf (key, sizeof (key), " %016d" , k);
819
826
iter->Seek (key);
820
827
if (iter->Valid () && iter->key () == key) found++;
821
828
delete iter;
822
829
thread->stats .FinishedSingleOp ();
823
830
}
824
831
char msg[100 ];
825
- snprintf (msg, sizeof (msg), " (%d of %d found)" , found, num_);
832
+ std:: snprintf (msg, sizeof (msg), " (%d of %d found)" , found, num_);
826
833
thread->stats .AddMessage (msg);
827
834
}
828
835
@@ -835,14 +842,14 @@ class Benchmark {
835
842
for (int j = 0 ; j < entries_per_batch_; j++) {
836
843
const int k = seq ? i + j : (thread->rand .Next () % FLAGS_num);
837
844
char key[100 ];
838
- snprintf (key, sizeof (key), " %016d" , k);
845
+ std:: snprintf (key, sizeof (key), " %016d" , k);
839
846
batch.Delete (key);
840
847
thread->stats .FinishedSingleOp ();
841
848
}
842
849
s = db_->Write (write_options_, &batch);
843
850
if (!s.ok ()) {
844
- fprintf (stderr, " del error: %s\n " , s.ToString ().c_str ());
845
- exit (1 );
851
+ std:: fprintf (stderr, " del error: %s\n " , s.ToString ().c_str ());
852
+ std:: exit (1 );
846
853
}
847
854
}
848
855
}
@@ -868,11 +875,11 @@ class Benchmark {
868
875
869
876
const int k = thread->rand .Next () % FLAGS_num;
870
877
char key[100 ];
871
- snprintf (key, sizeof (key), " %016d" , k);
878
+ std:: snprintf (key, sizeof (key), " %016d" , k);
872
879
Status s = db_->Put (write_options_, key, gen.Generate (value_size_));
873
880
if (!s.ok ()) {
874
- fprintf (stderr, " put error: %s\n " , s.ToString ().c_str ());
875
- exit (1 );
881
+ std:: fprintf (stderr, " put error: %s\n " , s.ToString ().c_str ());
882
+ std:: exit (1 );
876
883
}
877
884
}
878
885
@@ -888,7 +895,7 @@ class Benchmark {
888
895
if (!db_->GetProperty (key, &stats)) {
889
896
stats = " (failed)" ;
890
897
}
891
- fprintf (stdout, " \n %s\n " , stats.c_str ());
898
+ std:: fprintf (stdout, " \n %s\n " , stats.c_str ());
892
899
}
893
900
894
901
static void WriteToFile (void * arg, const char * buf, int n) {
@@ -897,17 +904,18 @@ class Benchmark {
897
904
898
905
void HeapProfile () {
899
906
char fname[100 ];
900
- snprintf (fname, sizeof (fname), " %s/heap-%04d" , FLAGS_db, ++heap_counter_);
907
+ std::snprintf (fname, sizeof (fname), " %s/heap-%04d" , FLAGS_db,
908
+ ++heap_counter_);
901
909
WritableFile* file;
902
910
Status s = g_env->NewWritableFile (fname, &file);
903
911
if (!s.ok ()) {
904
- fprintf (stderr, " %s\n " , s.ToString ().c_str ());
912
+ std:: fprintf (stderr, " %s\n " , s.ToString ().c_str ());
905
913
return ;
906
914
}
907
915
bool ok = port::GetHeapProfile (WriteToFile, file);
908
916
delete file;
909
917
if (!ok) {
910
- fprintf (stderr, " heap profiling not supported\n " );
918
+ std:: fprintf (stderr, " heap profiling not supported\n " );
911
919
g_env->RemoveFile (fname);
912
920
}
913
921
}
@@ -962,8 +970,8 @@ int main(int argc, char** argv) {
962
970
} else if (strncmp (argv[i], " --db=" , 5 ) == 0 ) {
963
971
FLAGS_db = argv[i] + 5 ;
964
972
} else {
965
- fprintf (stderr, " Invalid flag '%s'\n " , argv[i]);
966
- exit (1 );
973
+ std:: fprintf (stderr, " Invalid flag '%s'\n " , argv[i]);
974
+ std:: exit (1 );
967
975
}
968
976
}
969
977
0 commit comments