diff options
author | Haavard <havardpe@yahoo-inc.com> | 2017-02-07 11:49:22 +0000 |
---|---|---|
committer | Haavard <havardpe@yahoo-inc.com> | 2017-02-07 11:49:22 +0000 |
commit | 115cac2552983f2f1bc5b52f9bfa13cd6ece9628 (patch) | |
tree | d611a16ce90bcaa5cc790d2e464847a1f870652e /vbench | |
parent | b233017523112c4c0f7fac80ea8799ec55aa49c9 (diff) |
use mapped file input from vespalib
Diffstat (limited to 'vbench')
-rw-r--r-- | vbench/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vbench/src/apps/vbench/vbench.cpp | 7 | ||||
-rw-r--r-- | vbench/src/tests/mapped_file_input/.gitignore | 1 | ||||
-rw-r--r-- | vbench/src/tests/mapped_file_input/CMakeLists.txt | 9 | ||||
-rw-r--r-- | vbench/src/tests/mapped_file_input/FILES | 2 | ||||
-rw-r--r-- | vbench/src/tests/mapped_file_input/file.txt | 1 | ||||
-rw-r--r-- | vbench/src/tests/mapped_file_input/mapped_file_input_test.cpp | 23 | ||||
-rw-r--r-- | vbench/src/vbench/core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vbench/src/vbench/core/input_file_reader.cpp | 11 | ||||
-rw-r--r-- | vbench/src/vbench/core/input_file_reader.h | 14 | ||||
-rw-r--r-- | vbench/src/vbench/core/mapped_file_input.cpp | 41 | ||||
-rw-r--r-- | vbench/src/vbench/core/mapped_file_input.h | 36 | ||||
-rw-r--r-- | vbench/src/vbench/test/all.h | 2 |
13 files changed, 22 insertions, 127 deletions
diff --git a/vbench/CMakeLists.txt b/vbench/CMakeLists.txt index fe6873d2b8d..493505fc91c 100644 --- a/vbench/CMakeLists.txt +++ b/vbench/CMakeLists.txt @@ -30,7 +30,6 @@ vespa_define_module( src/tests/input_file_reader src/tests/latency_analyzer src/tests/line_reader - src/tests/mapped_file_input src/tests/qps_analyzer src/tests/qps_tagger src/tests/request_dumper diff --git a/vbench/src/apps/vbench/vbench.cpp b/vbench/src/apps/vbench/vbench.cpp index 8e13f078b45..a2dca88f7d5 100644 --- a/vbench/src/apps/vbench/vbench.cpp +++ b/vbench/src/apps/vbench/vbench.cpp @@ -29,10 +29,9 @@ void setupSignals() { } int run(const std::string &cfg_name) { - MappedFileInput cfg_file(cfg_name); - if (cfg_file.tainted()) { - fprintf(stderr, "could not load config file: %s\n", - cfg_file.tainted().reason().c_str()); + vespalib::MappedFileInput cfg_file(cfg_name); + if (!cfg_file.valid()) { + fprintf(stderr, "could not load config file: %s\n", cfg_name.c_str()); return 1; } vespalib::Slime cfg; diff --git a/vbench/src/tests/mapped_file_input/.gitignore b/vbench/src/tests/mapped_file_input/.gitignore deleted file mode 100644 index 99fcc66eeab..00000000000 --- a/vbench/src/tests/mapped_file_input/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vbench_mapped_file_input_test_app diff --git a/vbench/src/tests/mapped_file_input/CMakeLists.txt b/vbench/src/tests/mapped_file_input/CMakeLists.txt deleted file mode 100644 index 35132ae5845..00000000000 --- a/vbench/src/tests/mapped_file_input/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vbench_mapped_file_input_test_app TEST - SOURCES - mapped_file_input_test.cpp - DEPENDS - vbench_test - vbench -) -vespa_add_test(NAME vbench_mapped_file_input_test_app COMMAND vbench_mapped_file_input_test_app) diff --git a/vbench/src/tests/mapped_file_input/FILES b/vbench/src/tests/mapped_file_input/FILES deleted file mode 100644 index 55eddab2a7a..00000000000 --- a/vbench/src/tests/mapped_file_input/FILES +++ /dev/null @@ -1,2 +0,0 @@ -mapped_file_input_test.cpp -file.txt diff --git a/vbench/src/tests/mapped_file_input/file.txt b/vbench/src/tests/mapped_file_input/file.txt deleted file mode 100644 index dd59d098638..00000000000 --- a/vbench/src/tests/mapped_file_input/file.txt +++ /dev/null @@ -1 +0,0 @@ -file content diff --git a/vbench/src/tests/mapped_file_input/mapped_file_input_test.cpp b/vbench/src/tests/mapped_file_input/mapped_file_input_test.cpp deleted file mode 100644 index 2edbda02ec0..00000000000 --- a/vbench/src/tests/mapped_file_input/mapped_file_input_test.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/test_kit.h> -#include <vbench/test/all.h> - -using namespace vbench; - -TEST("mapped file input") { - { - MappedFileInput file("not_found.txt"); - EXPECT_TRUE(file.tainted()); - } - { - MappedFileInput file(TEST_PATH("file.txt")); - EXPECT_TRUE(!file.tainted()); - LineReader reader(file); - string line; - EXPECT_TRUE(reader.readLine(line)); - EXPECT_EQUAL("file content", line); - EXPECT_TRUE(!reader.readLine(line)); - } -} - -TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/vbench/src/vbench/core/CMakeLists.txt b/vbench/src/vbench/core/CMakeLists.txt index c97a2c67cb4..a42f31ca093 100644 --- a/vbench/src/vbench/core/CMakeLists.txt +++ b/vbench/src/vbench/core/CMakeLists.txt @@ -7,7 +7,6 @@ vespa_add_library(vbench_core OBJECT handler_thread.cpp input_file_reader.cpp line_reader.cpp - mapped_file_input.cpp provider.cpp socket.cpp stream.cpp diff --git a/vbench/src/vbench/core/input_file_reader.cpp b/vbench/src/vbench/core/input_file_reader.cpp index 324951a9ae2..3c096b83752 100644 --- a/vbench/src/vbench/core/input_file_reader.cpp +++ b/vbench/src/vbench/core/input_file_reader.cpp @@ -2,9 +2,20 @@ #include <vespa/fastos/fastos.h> #include "input_file_reader.h" +#include "string.h" namespace vbench { +InputFileReader::InputFileReader(const string &name) + : _file(name), + _lines(_file), + _taint() +{ + if (!_file.valid()) { + _taint.reset(strfmt("could not open file: %s", name.c_str())); + } +} + bool InputFileReader::readLine(string &dst) { diff --git a/vbench/src/vbench/core/input_file_reader.h b/vbench/src/vbench/core/input_file_reader.h index 820962bc971..79562fc0f43 100644 --- a/vbench/src/vbench/core/input_file_reader.h +++ b/vbench/src/vbench/core/input_file_reader.h @@ -3,8 +3,8 @@ #pragma once #include "string.h" -#include "taint.h" -#include "mapped_file_input.h" +#include "taintable.h" +#include <vespa/vespalib/io/mapped_file_input.h> #include <vespa/vespalib/data/input_reader.h> #include "line_reader.h" @@ -17,12 +17,12 @@ namespace vbench { class InputFileReader : public Taintable { private: - MappedFileInput _file; - LineReader _lines; + vespalib::MappedFileInput _file; + LineReader _lines; + Taint _taint; public: - InputFileReader(const string &name) - : _file(name), _lines(_file) {} + InputFileReader(const string &name); /** * Read a single line from the input file and put it into @@ -34,7 +34,7 @@ public: **/ bool readLine(string &dst); - virtual const Taint &tainted() const { return _file.tainted(); } + virtual const Taint &tainted() const { return _taint; } }; } // namespace vbench diff --git a/vbench/src/vbench/core/mapped_file_input.cpp b/vbench/src/vbench/core/mapped_file_input.cpp deleted file mode 100644 index 0a20b91c375..00000000000 --- a/vbench/src/vbench/core/mapped_file_input.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/fastos/fastos.h> -#include "mapped_file_input.h" - -namespace vbench { - -MappedFileInput::MappedFileInput(const string &name) - : _file(open(name.c_str(), O_RDONLY)), - _data(static_cast<char*>(MAP_FAILED)), - _size(0), - _taint(strfmt("could not open file: %s", name.c_str())), - _pos(0) -{ - struct stat info; - if (_file >= 0 && fstat(_file, &info) == 0) { - _data = static_cast<char*>(mmap(0, info.st_size, - PROT_READ, MAP_SHARED, _file, 0)); - if (_data != MAP_FAILED) { - _size = info.st_size; - madvise(_data, _size, MADV_SEQUENTIAL); - _taint.reset(); - } - } -} - -Memory -MappedFileInput::obtain() -{ - return Memory(_data + _pos, (_size - _pos)); -} - -Input & -MappedFileInput::evict(size_t bytes) -{ - assert(bytes <= (_size - _pos)); - _pos += bytes; - return *this; -} - -} // namespace vbench diff --git a/vbench/src/vbench/core/mapped_file_input.h b/vbench/src/vbench/core/mapped_file_input.h deleted file mode 100644 index 5b22e15b9bb..00000000000 --- a/vbench/src/vbench/core/mapped_file_input.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include <vespa/vespalib/data/input.h> -#include "taintable.h" - -namespace vbench { - -using Input = vespalib::Input; -using Memory = vespalib::Memory; - -/** - * A Taintable Input implementation reading sequentially from a memory - * mapped file. - **/ -class MappedFileInput : public Input, - public Taintable -{ -private: - int _file; - char *_data; - size_t _size; - Taint _taint; - size_t _pos; - -public: - MappedFileInput(const string &name); - Memory get() const { return Memory(_data, _size); } - virtual Memory obtain(); - virtual Input &evict(size_t bytes); - virtual const Taint &tainted() const { return _taint; } -}; - -} // namespace vbench - diff --git a/vbench/src/vbench/test/all.h b/vbench/src/vbench/test/all.h index 8e57bc19cd1..c8dd8cf9ac8 100644 --- a/vbench/src/vbench/test/all.h +++ b/vbench/src/vbench/test/all.h @@ -23,7 +23,7 @@ #include <vbench/core/taintable.h> #include <vespa/vespalib/data/output.h> #include <vespa/vespalib/data/memory.h> -#include <vbench/core/mapped_file_input.h> +#include <vespa/vespalib/io/mapped_file_input.h> #include <vbench/core/time_queue.h> #include <vespa/vespalib/data/output_writer.h> #include <vbench/core/socket.h> |