From 702b844da8dc1d5971cae36add6b17d6c141d495 Mon Sep 17 00:00:00 2001 From: superjom Date: Wed, 20 Dec 2017 20:37:17 +0800 Subject: [PATCH] debug --- frontend/package.json | 5 +--- frontend/tool/build.js | 1 + frontend/tool/entry.js | 1 + frontend/tool/webpack.config.js | 1 + frontend/tool/webpack.prod.config.js | 1 + server/visualdl/visual_dl.py | 45 +++++++++++++++++++++++++--- visualdl/logic/im.cc | 1 + visualdl/logic/pybind.cc | 1 + visualdl/logic/sdk.h | 4 +++ visualdl/python/test_summary.py | 2 -- 10 files changed, 52 insertions(+), 10 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 57dc9b6d..5cd4c1f8 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,9 +8,7 @@ "release": "cross-env NODE_ENV=production node ./tool/build.js", "build": "cross-env NODE_ENV=dev node ./tool/build.js", "dev": "cross-env NODE_ENV=dev node tool/dev-server.js", - "lint": "./node_modules/fecs/bin/fecs --rule", - "precommit": "npm run lint", - "prepush": "npm run lint" + "lint": "./node_modules/fecs/bin/fecs --rule" }, "engines": { "node": ">= 6.4.0" @@ -54,7 +52,6 @@ "html-loader": "^0.4.4", "html-webpack-plugin": "^2.28.0", "http-proxy-middleware": "^0.17.4", - "husky": "^0.14.3", "json-loader": "^0.5.4", "opn": "^5.1.0", "optimize-css-assets-webpack-plugin": "^1.3.2", diff --git a/frontend/tool/build.js b/frontend/tool/build.js index d8a67b1f..2590b887 100644 --- a/frontend/tool/build.js +++ b/frontend/tool/build.js @@ -1,3 +1,4 @@ +"use strict"; const webpack = require('webpack'); const rm = require('rimraf'); const ora = require('ora'); diff --git a/frontend/tool/entry.js b/frontend/tool/entry.js index 78754c6a..aba7919b 100644 --- a/frontend/tool/entry.js +++ b/frontend/tool/entry.js @@ -1,3 +1,4 @@ +"use strict"; const path = require('path'); const projectPath = path.resolve(__dirname, '..'); const HtmlWebpackPlugin = require('html-webpack-plugin'); diff --git a/frontend/tool/webpack.config.js b/frontend/tool/webpack.config.js index 24764208..90115251 100644 --- a/frontend/tool/webpack.config.js +++ b/frontend/tool/webpack.config.js @@ -1,3 +1,4 @@ +"use strict"; const webpack = require('webpack'); const path = require('path'); const projectPath = path.resolve(__dirname, '..'); diff --git a/frontend/tool/webpack.prod.config.js b/frontend/tool/webpack.prod.config.js index fa73c783..3d8bbbbc 100644 --- a/frontend/tool/webpack.prod.config.js +++ b/frontend/tool/webpack.prod.config.js @@ -1,3 +1,4 @@ +"use strict"; const webpack = require('webpack'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const path = require('path'); diff --git a/server/visualdl/visual_dl.py b/server/visualdl/visual_dl.py index 79113ada..955ab0dc 100644 --- a/server/visualdl/visual_dl.py +++ b/server/visualdl/visual_dl.py @@ -13,6 +13,7 @@ from flask import Response from visualdl.log import logger import visualdl.mock.data as mock_data import visualdl.mock.tags as mock_tags +import summary app = Flask(__name__, static_url_path="") @@ -31,7 +32,14 @@ def option_parser(): default=8040, action="store", dest="port", - help="rest api service port") + help="api service port") + parser.add_option( + "-t", + "--host", + type=str, + default="0.0.0.0", + action="store", + help="api service ip") parser.add_option( "--logdir", action="store", dest="logdir", help="log file directory") return parser.parse_args() @@ -42,6 +50,8 @@ server_path = os.path.abspath(os.path.dirname(sys.argv[0])) static_file_path = "./frontend/dist/" mock_data_path = "./mock_data/" +im = summary.IM('./tmp', 'read', 500) + # return data # status, msg, data @@ -85,7 +95,15 @@ def runs(): @app.route("/data/plugin/scalars/tags") def tags(): is_debug = bool(request.args.get('debug')) - result = gen_result(0, "", mock_tags.data()) + tag = request.args.get('tag') + # NOTE debug + is_debug = True + if is_debug: + result = mock_tags.data() + else: + result = im.storage().tags() + print 'tags', result + result = gen_result(0, "", result) return Response(json.dumps(result), mimetype='application/json') @@ -93,11 +111,30 @@ def tags(): def scalars(): run = request.args.get('run') tag = request.args.get('tag') + # NOTE debug + tag = "tag0" is_debug = bool(request.args.get('debug')) - result = gen_result(0, "", mock_data.sequence_data()) + if is_debug: + result = gen_result(0, "", mock_data.sequence_data()) + else: + scalar = summary.scalar(im, tag) + result = [] + + for id, tag in enumerate(scalar.captions): + records = [v[id] for v in scalar.records] + line = [ + a + for a in zip([float(a) + for a in scalar.timestamps], scalar.ids, records) + ] + result.append(line) + + result = result[0] + result = gen_result(0, "", result) + return Response(json.dumps(result), mimetype='application/json') if __name__ == '__main__': logger.info(" port=" + str(options.port)) - app.run(debug=False, host="0.0.0.0", port=options.port) + app.run(debug=False, host=options.host, port=options.port) diff --git a/visualdl/logic/im.cc b/visualdl/logic/im.cc index 624fbfbb..3645f530 100644 --- a/visualdl/logic/im.cc +++ b/visualdl/logic/im.cc @@ -32,6 +32,7 @@ void IM::SetPersistDest(const std::string &path) { } storage::Tablet *IM::AddTablet(const std::string &tag, int num_samples) { + CHECK(!tag.empty()) << "invalid tag name '" << tag << "'"; auto tablet = storage_->NewTablet(tag, num_samples); return tablet; } diff --git a/visualdl/logic/pybind.cc b/visualdl/logic/pybind.cc index 69d40ca0..61ce7fa1 100644 --- a/visualdl/logic/pybind.cc +++ b/visualdl/logic/pybind.cc @@ -41,6 +41,7 @@ PYBIND11_PLUGIN(core) { }); py::class_(m, "Storage") + .def("tags", &vs::StorageHelper::tags) .def("timestamp", &vs::StorageHelper::timestamp) .def("dir", &vs::StorageHelper::dir) .def("set_dir", &vs::StorageHelper::SetDir) diff --git a/visualdl/logic/sdk.h b/visualdl/logic/sdk.h index b74e3317..b5bfc0fe 100644 --- a/visualdl/logic/sdk.h +++ b/visualdl/logic/sdk.h @@ -82,6 +82,10 @@ public: data_->set_dir(dir); } + std::vector tags() { + return std::vector(data_->tags().begin(), data_->tags().end()); + } + int64_t timestamp() const { return data_->timestamp(); } std::string dir() const { return data_->dir(); } int tablets_size() const { return data_->tablets_size(); } diff --git a/visualdl/python/test_summary.py b/visualdl/python/test_summary.py index d4ce733b..486035c9 100644 --- a/visualdl/python/test_summary.py +++ b/visualdl/python/test_summary.py @@ -4,8 +4,6 @@ import unittest import random import time -once_flag = False - class ScalarTester(unittest.TestCase): def setUp(self): -- GitLab