Index: tracing/tracing/value/diagnostics/discover_cmdline.html |
diff --git a/tracing/tracing/value/diagnostics/discover_cmdline.html b/tracing/tracing/value/diagnostics/discover_cmdline.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..293a5086508dd1bd1aff9bb0b51d3fb516050ffb |
--- /dev/null |
+++ b/tracing/tracing/value/diagnostics/discover_cmdline.html |
@@ -0,0 +1,46 @@ |
+<!DOCTYPE html> |
+<!-- |
+Copyright 2017 The Chromium Authors. All rights reserved. |
+Use of this source code is governed by a BSD-style license that can be |
+found in the LICENSE file. |
+--> |
+<link rel="import" href="/tracing/value/diagnostics/diagnostic.html"> |
+ |
+<script> |
+'use strict'; |
+/* eslint-disable no-console */ |
+ |
+function isDiagnosticSubclass(cls) { |
+ cls = cls.__proto__; |
+ while (cls) { |
+ if (cls === tr.v.d.Diagnostic) return true; |
+ cls = cls.__proto__; |
+ } |
+ return false; |
+} |
+ |
+function discoverDiagnostics(args) { |
+ const discoveryMode = args.shift(); |
+ for (const arg of args) HTMLImportsLoader.loadHTML(arg); |
+ |
+ const results = []; |
+ if (discoveryMode === 'registry') { |
+ for (const typeInfo of tr.v.d.Diagnostic.getAllRegisteredTypeInfos()) { |
+ results.push(typeInfo.constructor.name); |
+ } |
+ } else if (discoveryMode === 'namespace') { |
+ for (const cls of Object.values(tr.v.d)) { |
+ if (isDiagnosticSubclass(cls)) results.push(cls.name); |
+ } |
+ } else { |
+ console.log('First argument must be either "registry" or "namespace".'); |
+ return 1; |
+ } |
+ console.log(JSON.stringify(results)); |
+ return 0; |
+} |
+ |
+if (tr.isHeadless) { |
+ quit(discoverDiagnostics(sys.argv.slice(1))); |
+} |
+</script> |