memgraph/poc/profile.cpp

91 lines
2.6 KiB
C++
Raw Normal View History

#include <chrono>
#include <ctime>
#include <strings.h>
#include <unistd.h>
#include <unordered_map>
2016-10-04 21:09:21 +08:00
#include "database/db.hpp"
#include "database/db_accessor.hpp"
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"
#include "import/csv_import.hpp"
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
#include "utils/command_line/arguments.hpp"
2016-10-04 21:09:21 +08:00
#include "profile.hpp"
2016-08-29 02:36:52 +08:00
using namespace std;
2016-10-04 21:09:21 +08:00
// (company, {type_name, score})
2016-09-26 02:01:46 +08:00
using company_profile_type =
pair<VertexAccessor, unordered_map<string, double>>;
2016-09-26 02:01:46 +08:00
2016-10-04 21:09:21 +08:00
// Accepted flags for CSV import.
// -db name # will create database with that name.
2016-10-04 21:09:21 +08:00
// -s true # will create snapshot of the database after import.
int main(int argc, char **argv)
{
2016-10-04 21:09:21 +08:00
// initialize logger
logging::init_async();
logging::log->pipe(std::make_unique<Stdout>());
2016-10-04 21:09:21 +08:00
// read program arguments
auto para = all_arguments(argc, argv);
Db db(get_argument(para, "-db", "powerlinks_profile"));
2016-10-04 21:09:21 +08:00
// import database
import_csv_from_arguments(db, para);
{
DbAccessor t(db);
2016-09-26 02:01:46 +08:00
vector<company_profile_type> company_profiles;
2016-10-04 21:09:21 +08:00
// query benchmark
auto begin = clock();
int n = for_all_companys(t, company_profiles);
clock_t end = clock();
double elapsed_s = (double(end - begin) / CLOCKS_PER_SEC);
if (n == 0) {
cout << "No companys" << endl;
return 0;
}
2016-10-04 21:09:21 +08:00
// performance statistics
cout << endl
<< "Query duration: " << (elapsed_s / n) * 1000 * 1000 << " [us]"
<< endl;
cout << "Throughput: " << 1 / (elapsed_s / n) << " [query/sec]" << endl;
2016-09-26 02:01:46 +08:00
// remove ones who don't have profile results
auto res = company_profiles.back();
while (res.second.empty()) {
2016-09-26 02:01:46 +08:00
company_profiles.pop_back();
res = company_profiles.back();
}
2016-09-26 02:01:46 +08:00
// print specific company
int company_id = std::stoi(get_argument(para, "-company_id", "230216"));
for (auto &company_profile : company_profiles) {
auto prop_vertex_id = t.vertex_property_key<Int64>("company_id");
2016-10-04 21:09:21 +08:00
auto db_company_id =
company_profile.first.at(prop_vertex_id).get();
if (db_company_id->value() == company_id) {
2016-09-26 02:01:46 +08:00
cout << endl << "CompanyID: " << company_id << endl;
for (auto e : company_profile.second) {
cout << e.first << " = " << e.second << endl;
}
}
}
t.commit();
}
if (get_argument(para, "-s", "false") == "true") {
db.snap_engine.make_snapshot();
}
2016-10-04 21:09:21 +08:00
// usleep(1000 * 1000 * 60);
return 0;
}