Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add debug methods, asserts, cleanups
  • Loading branch information
asmuth committed May 16, 2017
1 parent 131d5b4 commit 34e26dd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
5 changes: 1 addition & 4 deletions core/metrictools/storage/sqlite/sqlite_backend.cc
Expand Up @@ -319,6 +319,7 @@ ReturnCode SQLiteBackend::fetchData(
resp.request = request;
resp.label.labels = label_cols;
resp.last_value = r[r.size() - 1];
resp.history.reset( new Timeseries<std::string>());
for (size_t i = 0; i < label_cols.size(); ++i) {
resp.label.values.emplace_back(r[i]);
}
Expand Down Expand Up @@ -371,10 +372,6 @@ ReturnCode SQLiteBackend::fetchData(

auto resp_ts = dynamic_cast<Timeseries<std::string>*>(
resp_iter->second.history.get());
if (!resp_ts) {
resp_ts = new Timeseries<std::string>();
resp_iter->second.history.reset(resp_ts);
}

size_t pos = std::upper_bound(
resp_ts->timestamps.begin(),
Expand Down
20 changes: 20 additions & 0 deletions core/metrictools/timeseries.cc
Expand Up @@ -12,6 +12,26 @@

namespace fnordmetric {

template <>
std::string Timeseries<std::string>::getTypeName() const {
return "string";
}

template <>
std::string Timeseries<double>::getTypeName() const {
return "float64";
}

template <>
std::string Timeseries<int64_t>::getTypeName() const {
return "int64";
}

template <>
std::string Timeseries<uint64_t>::getTypeName() const {
return "uint64";
}

template<>
ReturnCode convertTimeseries(
const Timeseries<double>& in,
Expand Down
9 changes: 9 additions & 0 deletions core/metrictools/timeseries.h
Expand Up @@ -17,7 +17,11 @@
namespace fnordmetric {

struct AnyTimeseries {

virtual ~AnyTimeseries() = default;

virtual std::string getTypeName() const = 0;

};

using TimeseriesRef = std::unique_ptr<AnyTimeseries>;
Expand Down Expand Up @@ -45,6 +49,11 @@ struct Timeseries : public AnyTimeseries {
*/
void clear();

/**
* Return the name of T
*/
std::string getTypeName() const override;

};

/**
Expand Down
25 changes: 25 additions & 0 deletions core/metrictools/timeseries_impl.h
Expand Up @@ -57,6 +57,7 @@ ReturnCode convertTimeseries(
return convertTimeseries(*dynamic_cast<const Timeseries<double>*>(in), out);
}

assert(false);
return ReturnCode::error("EARG", "invalid timeseries type");
}

Expand Down Expand Up @@ -91,13 +92,37 @@ template <typename T>
ReturnCode convertTimeseriesTo(TimeseriesRef* ts, Timeseries<T>** out) {
*out = nullptr;

assert(ts->get());

{
auto rc = convertTimeseriesFromTo<std::string, T>(ts, out);
if (!rc.isSuccess() || *out) {
return rc;
}
}

{
auto rc = convertTimeseriesFromTo<double, T>(ts, out);
if (!rc.isSuccess() || *out) {
return rc;
}
}

{
auto rc = convertTimeseriesFromTo<int64_t, T>(ts, out);
if (!rc.isSuccess() || *out) {
return rc;
}
}

{
auto rc = convertTimeseriesFromTo<uint64_t, T>(ts, out);
if (!rc.isSuccess() || *out) {
return rc;
}
}

assert(false);
return ReturnCode::error("EARG", "invalid timeseries type");
}

Expand Down

0 comments on commit 34e26dd

Please sign in to comment.