mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
497a2ae765
Summary: This makes several improvements to the hg import tester script: - If no --edenDir flag is specified, initialize a new temporary directory to keep the RocksDB data store. - Add a `--rocksdb_options_file` flag to allow controlling the options used for the RocksDB store. - Add an --import_type flag to allow explicitly selecting if we should test the flat manifest or tree manifest import code. - Add a --flat_import_file flag, to allow testing a pre-generated flat manifest input data file, rather than retrieving the data from mercurial. This allows benchmarking only the C++ import code, and eliminating the python portion of the import. The input file can be generated by running `hg_import_helper.py --manifest <revision>` Reviewed By: wez Differential Revision: D5541732 fbshipit-source-id: 340af4fea872412248d41453792b2179f0afa466
71 lines
2.3 KiB
C++
71 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2004-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
#include "eden/fs/utils/TimeUtil.h"
|
|
|
|
#include <folly/Format.h>
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
std::string durationStr(std::chrono::nanoseconds duration) {
|
|
using namespace std::chrono_literals;
|
|
|
|
// This code is good enough for our use case of generating human-readable
|
|
// times in log messages. In the future we could probably be smarter at
|
|
// deciding how much precision to show in the output.
|
|
|
|
if (duration < 1us) {
|
|
return folly::sformat("{}ns", duration.count());
|
|
} else if (duration < 1ms) {
|
|
return folly::sformat("{:.3}us", duration.count() / 1000.0);
|
|
} else if (duration < 1s) {
|
|
return folly::sformat("{:.3}ms", duration.count() / 1000000.0);
|
|
} else if (duration < 1min) {
|
|
return folly::sformat("{:.3}s", duration.count() / 1000000000.0);
|
|
} else if (duration < 1h) {
|
|
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(duration);
|
|
auto remainder = duration - minutes;
|
|
return folly::sformat(
|
|
"{}m{:.3}s", minutes.count(), remainder.count() / 1000000000.0);
|
|
} else if (duration < 24h) {
|
|
auto hours = std::chrono::duration_cast<std::chrono::hours>(duration);
|
|
auto remainder = duration - hours;
|
|
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(remainder);
|
|
remainder -= minutes;
|
|
return folly::sformat(
|
|
"{}h{}m{:.3}s",
|
|
hours.count(),
|
|
minutes.count(),
|
|
remainder.count() / 1000000000.0);
|
|
} else {
|
|
using days_type =
|
|
std::chrono::duration<std::chrono::hours::rep, std::ratio<86400>>;
|
|
|
|
auto remainder = duration;
|
|
auto days = std::chrono::duration_cast<days_type>(remainder);
|
|
remainder -= days;
|
|
|
|
auto hours = std::chrono::duration_cast<std::chrono::hours>(remainder);
|
|
remainder -= hours;
|
|
|
|
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(remainder);
|
|
remainder -= minutes;
|
|
|
|
return folly::sformat(
|
|
"{}d{:02}h{:02}m{:.3}s",
|
|
days.count(),
|
|
hours.count(),
|
|
minutes.count(),
|
|
remainder.count() / 1000000000.0);
|
|
}
|
|
}
|
|
}
|
|
}
|