micro_profiler.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. #include "tensorflow/lite/micro/micro_profiler.h"
  13. #include "tensorflow/lite/kernels/internal/compatibility.h"
  14. #include "tensorflow/lite/micro/micro_time.h"
  15. namespace tflite {
  16. MicroProfiler::MicroProfiler(tflite::ErrorReporter* reporter)
  17. : reporter_(reporter) {}
  18. uint32_t MicroProfiler::BeginEvent(const char* tag, EventType event_type,
  19. int64_t event_metadata1,
  20. int64_t event_metadata2) {
  21. start_time_ = GetCurrentTimeTicks();
  22. TFLITE_DCHECK(tag != nullptr);
  23. event_tag_ = tag;
  24. return 0;
  25. }
  26. void MicroProfiler::EndEvent(uint32_t event_handle) {
  27. #ifndef TF_LITE_STRIP_ERROR_STRINGS
  28. int32_t end_time = GetCurrentTimeTicks();
  29. TF_LITE_REPORT_ERROR(reporter_, "%s took %d cycles\n", event_tag_,
  30. end_time - start_time_);
  31. #endif
  32. }
  33. } // namespace tflite