diff --git a/gputop-client-c/gputop-client-c-runtime-bindings.cpp b/gputop-client-c/gputop-client-c-runtime-bindings.cpp index 37c95251..a5a7d852 100644 --- a/gputop-client-c/gputop-client-c-runtime-bindings.cpp +++ b/gputop-client-c/gputop-client-c-runtime-bindings.cpp @@ -160,5 +160,17 @@ _gputop_cr_accumulator_end_update(void) fn->Call(gputop, ARRAY_LENGTH(argv), argv); } +void +_gputop_cr_send_idle_flag(int idle_flag) +{ + Isolate* isolate = Isolate::GetCurrent(); + HandleScope scope(isolate); + + Local gputop = Local::New(isolate, gputop_cc_singleton); + Local fn = Local::Cast(gputop->Get(String::NewFromUtf8(isolate, "send_idle_flag"))); + + Local argv[] = {Number::New(isolate, idle_flag)}; + fn->Call(gputop, ARRAY_LENGTH(argv), argv); +} diff --git a/gputop-client/gputop.js b/gputop-client/gputop.js index 5c441877..6f62e0d0 100644 --- a/gputop-client/gputop.js +++ b/gputop-client/gputop.js @@ -1855,6 +1855,7 @@ Gputop.prototype.connect = function(address, onopen, onclose, onerror) { this.log('Connecting to ' + websocket_url); this.socket_ = this.connect_web_socket(websocket_url, () => { //onopen this.is_connected_ = true; + this.request_hw_id_map(); this.request_features(); var ev = { type: "open" }; @@ -1870,6 +1871,7 @@ Gputop.prototype.connect = function(address, onopen, onclose, onerror) { }); } else { this.is_connected_ = true; + this.request_hw_id_map(); this.request_features(); var ev = { type: "open" }; diff --git a/gputop-csv/gputop-csv.js b/gputop-csv/gputop-csv.js index 5797057b..80f0d91b 100755 --- a/gputop-csv/gputop-csv.js +++ b/gputop-csv/gputop-csv.js @@ -59,6 +59,8 @@ function GputopCSV(pretty_print) this.endl = process.platform === "win32" ? "\r\n" : "\n"; this.term_row_ = 0; + this.current_hw_id = 0; + this.idle_flag = 0; this.console = { log: (msg) => { @@ -134,6 +136,57 @@ GputopCSV.prototype.list_metric_set_counters = function(metric) { stderr_log.log("\nALL: " + all); } +var ctx_hw_id_ = []; +var vgpu_id_ = []; +var map_vgpuID_hwID = [0]; + +GputopCSV.prototype.get_vgpu_id = function() { + var vgpu_id; + for (var i = 0; i < vgpu_id_.length; i++) { + if (vgpu_id_[i] === parseInt(args.vgpu)) { + vgpu_id = vgpu_id_[i]; + break; + } + } + return vgpu_id; +} + +GputopCSV.prototype.update_vgpuID_hwID = function(hw_id) { + + hw_id.ctx_hw_id.forEach((ctx_hw_id, i) => { + ctx_hw_id_.push(ctx_hw_id); + }); + hw_id.vgpu_id.forEach((vgpu_id, i) => { + vgpu_id_.push(vgpu_id); + }); + + + var map_length = Math.max.apply(Math, vgpu_id_); + + for (var i = 0; i < map_length; i++ ) { + map_vgpuID_hwID[vgpu_id_[i]] = ctx_hw_id_[i]; + } + vgpu_id_.sort(); + + if (args.vgpu === 'list') { + stderr_log.log("\nList of vGPU ID selectable with --vgpu=..."); + for (var i = 0; i < vgpu_id_.length; i++) + stderr_log.log(vgpu_id_[i]); + } + else { + var vgpu_id; + vgpu_id = this.get_vgpu_id(); + this.current_hw_id = map_vgpuID_hwID[vgpu_id]; + + if (this.current_hw_id === undefined) { + stderr_log.error("Failed to look up to vGPU ID " + args.vgpu); + process.exit(1); + return; + } + } + //stderr_log.log(this.current_hw_id); +} + GputopCSV.prototype.update_features = function(features) { if (features.supported_oa_uuids.length == 0) { @@ -241,6 +294,7 @@ GputopCSV.prototype.update_features = function(features) var col_width = 0; if (this.pretty_print_csv_) { + if (counter.symbol_name === "Timestamp") { var units = "(ns)"; var camel_name = "TimeStamp"; @@ -350,6 +404,7 @@ GputopCSV.prototype.update_features = function(features) this.column_titles_.map((line) => { this.stream.write(line + this.endl); }); + if (this.pretty_print_csv_) this.stream.write(this.column_units_ + this.endl); }, @@ -362,6 +417,8 @@ GputopCSV.prototype.update_features = function(features) } } +var n_rows; + function write_rows(metric, accumulator) { /* Note: this ref[erence] counter is pre-dermined to be one with @@ -375,7 +432,7 @@ function write_rows(metric, accumulator) stderr_log.assert(ref_accumulated_counter.counter === ref_counter, "Spurious reference counter state"); - var n_rows = ref_accumulated_counter.updates.length; + n_rows = ref_accumulated_counter.updates.length; if (n_rows <= 1) return; @@ -456,6 +513,8 @@ function write_rows(metric, accumulator) } } +var flag = 0; + GputopCSV.prototype.notify_accumulator_events = function(metric, accumulator, events_mask) { if (events_mask & 1) //period elapsed this.accumulator_clear(accumulator); @@ -463,12 +522,33 @@ GputopCSV.prototype.notify_accumulator_events = function(metric, accumulator, ev if (this.write_queued_) return; - setTimeout(() => { - this.write_queued_ = false; - write_rows.call(this, metric, accumulator); - }, 0.2); + if (this.idle_flag < 4) { + flag = 0; + setTimeout(() => { + this.write_queued_ = false; + write_rows.call(this, metric, accumulator); + }, 0.2); + + this.write_queued_ = true; + } else { + if (flag === 0) { + flag = 1; + if (this.pretty_print_csv_) + stderr_log.error("No context is running on this vGPU now"); + else + this.stream.write("No context is running on this vGPU now\n"); + } - this.write_queued_ = true; + for (var c = 0; c < this.counters_.length; c++) { + var counter = this.counters_[c]; + if (counter.record_data === true) { + var accumulated_counter = + accumulator.accumulated_counters[counter.cc_counter_id_]; + n_rows = 2; + accumulated_counter.updates.splice(0, n_rows); + } + } + } } var parser = new ArgumentParser({ @@ -485,6 +565,16 @@ parser.addArgument( } ); +parser.addArgument( + [ '-vgpu', '--vgpu' ], + { + help: "specific vgpu mode to observe (default 'list')", + defaultValue: 'list', + constant: 'list', + nargs: '?' + } +); + parser.addArgument( [ '-m', '--metrics' ], { diff --git a/gputop-server/gputop-server.c b/gputop-server/gputop-server.c index 3db6bea9..cc3041c5 100644 --- a/gputop-server/gputop-server.c +++ b/gputop-server/gputop-server.c @@ -1017,7 +1017,21 @@ void handle_get_hw_id_map(h2o_websocket_conn_t *conn, if (last_vgpu_num != current_vgpu_num) { fprintf(stderr, "VM has changed!\n"); } +/* + fprintf(stderr, "vgpu_id: ", vgpu_id[i]); + for (i = 0; i < current_vgpu_num; i++) + { + fprintf(stderr, "%d ", vgpu_id[i]); + } + fprintf(stderr, "\n"); + fprintf(stderr, "ctx_hw_id: ", vgpu_id[i]); + for (i = 0; i < current_vgpu_num; i++) + { + fprintf(stderr, "%d ", ctx_hw_id[i]); + } + fprintf(stderr, "\n"); +*/ Gputop__Message message = GPUTOP__MESSAGE__INIT; Gputop__HWID hw_id = GPUTOP__HW__ID__INIT;