1 // Copyright 2019 Google LLC 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 #ifndef FCP_TRACING_TEXT_TRACING_RECORDER_H_ 16 #define FCP_TRACING_TEXT_TRACING_RECORDER_H_ 17 18 #include <fstream> 19 #include <string> 20 21 #include "fcp/tracing/text_tracing_recorder_impl.h" 22 #include "fcp/tracing/tracing_recorder.h" 23 24 namespace fcp { 25 26 // Entry point for usage of basic tracing API implementation that simply writes 27 // to an output stream in human readable format. 28 class TextTracingRecorder : public TracingRecorder { 29 public: 30 // Constructs a TextTracingRecorder which will write events to the filestream 31 // with a timestamp formatted for the provided timezone. TextTracingRecorder(const std::string & filename,absl::TimeZone time_zone)32 explicit TextTracingRecorder(const std::string& filename, 33 absl::TimeZone time_zone) 34 : impl_(std::make_shared<tracing_internal::TextTracingRecorderImpl>( 35 filename, time_zone)) {} 36 // Constructs a TextTracingRecorder which will write events to stderr 37 // with a timestamp formatted for the provided timezone. TextTracingRecorder(absl::TimeZone time_zone)38 explicit TextTracingRecorder(absl::TimeZone time_zone) 39 : impl_(std::make_shared<tracing_internal::TextTracingRecorderImpl>( 40 time_zone)) {} 41 InstallAsGlobal()42 void InstallAsGlobal() override { impl_->InstallAsGlobal(); } UninstallAsGlobal()43 void UninstallAsGlobal() override { impl_->UninstallAsGlobal(); } InstallAsThreadLocal()44 void InstallAsThreadLocal() override { impl_->InstallAsThreadLocal(); } UninstallAsThreadLocal()45 void UninstallAsThreadLocal() override { impl_->UninstallAsThreadLocal(); } 46 47 private: 48 // The tracing recorder implementation shared between tracing spans. 49 std::shared_ptr<tracing_internal::TextTracingRecorderImpl> impl_; 50 }; 51 52 } // namespace fcp 53 54 #endif // FCP_TRACING_TEXT_TRACING_RECORDER_H_ 55