Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a progress bar to TPU profile plugin. #1286

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tensorboard/plugins/profile/tf_profile_common/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package(default_visibility = ["//tensorboard:internal"])

load("//tensorboard/defs:defs.bzl", "tensorboard_webcomponent_library")
load("//tensorboard/defs:web.bzl", "tf_web_library")

licenses(["notice"]) # Apache 2.0

tf_web_library(
name = "tf_profile_common",
srcs = [
"tf-profile-common.html",
"util.ts",
],
path = "/tf-profile-common",
deps = [
"//tensorboard/components/tf_imports:polymer",
],
)

tensorboard_webcomponent_library(
name = "legacy",
srcs = [":tf_profile_common"],
destdir = "tf-profile-common",
deps = [
"//tensorboard/components/tf_imports_google:lib",
"//third_party/javascript/polymer/v1/polymer:lib",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
@license
Copyright 2016 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<script src="util.js"></script>
93 changes: 93 additions & 0 deletions tensorboard/plugins/profile/tf_profile_common/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

/**
* @fileoverview Utility functions for the TensorFlow profile plugin.
*/

module tf.profile.util {
/**
* Tracks task progress. Each task being passed a progress tracker needs
* to call the below-defined methods to notify the caller about the gradual
* progress of the task.
*/
export interface ProgressTracker {
updateProgress(incrementValue: number): void;
setMessage(msg: string): void;
reportError(msg: string, err: Error): void;
}

export function time<T>(msg: string, task: () => T) {
let start = Date.now();
let result = task();
/* tslint:disable */
console.log(msg, ':', Date.now() - start, 'ms');
/* tslint:enable */
return result;
}

/**
* Creates a tracker that sets the progress property of the
* provided polymer component. The provided component must have
* a property called 'progress' that is not read-only. The progress
* property is an object with a numerical 'value' property and a
* string 'msg' property.
*/
export function getTracker(polymerComponent: any) {
return {
setMessage: function(msg) {
polymerComponent.set(
'progress', {value: polymerComponent.progress.value, msg: msg});
},
updateProgress: function(value) {
polymerComponent.set('progress', {
value: polymerComponent.progress.value + value,
msg: polymerComponent.progress.msg
});
},
reportError: function(msg: string, err) {
// Log the stack trace in the console.
console.error(err.stack);
// And send a user-friendly message to the UI.
polymerComponent.set(
'progress',
{value: polymerComponent.progress.value, msg: msg, error: true});
},
};
}

/**
* Runs an expensive task and return the result.
*/
export function runTask<T>(
msg: string, incProgressValue: number, task: () => T,
tracker: ProgressTracker): T {
// Update the progress message to say the current running task.
tracker.setMessage(msg);
// Run the expensive task with a delay that gives enough time for the
// UI to update.
try {
let result = tf.profile.util.time(msg, task);
// Update the progress value.
tracker.updateProgress(incProgressValue);
// Return the result to be used by other tasks.
return result;
} catch (e) {
// Errors that happen inside asynchronous tasks are
// reported to the tracker using a user-friendly message.
tracker.reportError('Failed ' + msg, e);
}
}
}
2 changes: 2 additions & 0 deletions tensorboard/plugins/profile/tf_profile_dashboard/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ tf_web_library(
"//tensorboard/plugins/profile/memory_viewer/memory_viewer_dashboard",
"//tensorboard/plugins/profile/overview_page",
"//tensorboard/plugins/profile/tf_op_profile",
"//tensorboard/plugins/profile/tf_profile_common",
"@org_polymer",
"@org_polymer_paper_dropdown_menu",
"@org_polymer_paper_item",
"@org_polymer_paper_menu",
"@org_polymer_paper_progress",
],
)
Loading