Skip to content

Commit

Permalink
gputop-csv: add per-vGPU mode for gputop-csv
Browse files Browse the repository at this point in the history
add new option "-vgpu" for gputop-csv to print counter
data in per-vGPU mode.

Signed-off-by: Pengyuan Jiao <[email protected]>
  • Loading branch information
jiaopengyuan committed Sep 19, 2017
1 parent df74a9e commit a9503e5
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 6 deletions.
12 changes: 12 additions & 0 deletions gputop-client-c/gputop-client-c-runtime-bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> gputop = Local<Object>::New(isolate, gputop_cc_singleton);
Local<Function> fn = Local<Function>::Cast(gputop->Get(String::NewFromUtf8(isolate, "send_idle_flag")));

Local<Value> argv[] = {Number::New(isolate, idle_flag)};
fn->Call(gputop, ARRAY_LENGTH(argv), argv);
}


2 changes: 2 additions & 0 deletions gputop-client/gputop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand All @@ -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" };
Expand Down
102 changes: 96 additions & 6 deletions gputop-csv/gputop-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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);
},
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -456,19 +513,42 @@ 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);

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({
Expand All @@ -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' ],
{
Expand Down
14 changes: 14 additions & 0 deletions gputop-server/gputop-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a9503e5

Please sign in to comment.