Home | History | Annotate | Download | only in profiler
      1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 #include "tensorflow/cc/profiler/profiler.h"
     16 
     17 namespace tensorflow {
     18 namespace tfprof {
     19 
     20 Profiler::Profiler(const GraphDef& graph) {
     21   std::unique_ptr<GraphDef> graph_ptr(new GraphDef());
     22   *graph_ptr = graph;
     23   stats_.reset(new TFStats(std::move(graph_ptr), nullptr, nullptr, nullptr));
     24 }
     25 
     26 void Profiler::AddStep(int64 step, const RunMetadata& run_meta) {
     27   std::unique_ptr<RunMetadata> run_meta_ptr(new RunMetadata());
     28   *run_meta_ptr = run_meta;
     29   stats_->AddRunMeta(step, std::move(run_meta_ptr));
     30 }
     31 
     32 GraphNodeProto Profiler::ProfileGraph(const Options& options) {
     33   stats_->BuildView(kCmds[1]);
     34   return stats_->ShowGraphNode(kCmds[1], options);
     35 }
     36 
     37 GraphNodeProto Profiler::ProfileNameScope(const Options& options) {
     38   stats_->BuildView(kCmds[0]);
     39   return stats_->ShowGraphNode(kCmds[0], options);
     40 }
     41 
     42 MultiGraphNodeProto Profiler::ProfileOperations(const Options& options) {
     43   stats_->BuildView(kCmds[3]);
     44   return stats_->ShowMultiGraphNode(kCmds[3], options);
     45 }
     46 
     47 Status Profiler::SerializeToString(string* content) {
     48   if (!content) {
     49     return Status(error::Code::INVALID_ARGUMENT,
     50                   "Cannot use null string pointer for SerializeToString.");
     51   }
     52   stats_->SerializeToString(content);
     53   return Status::OK();
     54 }
     55 
     56 }  // namespace tfprof
     57 }  // namespace tensorflow
     58