Phosphor
export.h
1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2016 Couchbase, Inc
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include "phosphor/platform/core.h"
21 #include "phosphor/trace_buffer.h"
22 #include "phosphor/trace_context.h"
23 #include "phosphor/trace_log.h"
24 
25 namespace phosphor {
26  namespace tools {
27 
46  class PHOSPHOR_API JSONExport {
47  public:
51  JSONExport(const TraceContext& _context);
52 
53  ~JSONExport();
54 
64  size_t read(char* out, size_t length);
65 
73  StringPtr read(size_t length);
74 
80  StringPtr read();
81 
85  bool done();
86 
87  protected:
88  enum class State {
89  opening,
90  /* first_event is only used if first_thread wasn't */
91  first_event,
92  other_events,
93  first_thread,
94  other_threads,
95  footer,
96  dead
97  };
98 
99  const TraceContext& context;
101  std::unordered_map<uint64_t, std::string>::const_iterator tit;
102 
103  State state = State::opening;
104  std::string cache;
105  };
106 
115  class PHOSPHOR_API FileStopCallback : public TracingStoppedCallback {
116  public:
123  const std::string& _file_path = "phosphor.%p.json");
124 
125  ~FileStopCallback();
126 
133  void operator()(TraceLog& log, std::lock_guard<TraceLog>& lh) override;
134 
135  protected:
136  /*
137  * Exposed for testing
138  */
139  StringPtr generateFilePathAsPtr();
140 
141  private:
142  std::string file_path;
143  std::string generateFilePath();
144  };
145  }
146 }
Definition: trace_log.h:54
Definition: trace_context.h:39
Definition: trace_config.h:58
Definition: export.h:115
Definition: category_registry.h:32
Definition: export.h:46