1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TOOLS_TRACE_TO_TEXT_UTILS_H_
18 #define TOOLS_TRACE_TO_TEXT_UTILS_H_
19 
20 #include <stdio.h>
21 #include <sys/ioctl.h>
22 #include <unistd.h>
23 
24 #include <functional>
25 #include <iostream>
26 #include <memory>
27 
28 #include "perfetto/base/build_config.h"
29 
30 namespace perfetto {
31 
32 namespace protos {
33 class TracePacket;
34 }
35 
36 namespace trace_to_text {
37 
38 // When running in Web Assembly, fflush() is a no-op and the stdio buffering
39 // sends progress updates to JS only when a write ends with \n.
40 #if PERFETTO_BUILDFLAG(PERFETTO_OS_WASM)
41 constexpr char kProgressChar = '\n';
42 #else
43 constexpr char kProgressChar = '\r';
44 #endif
45 
46 void ForEachPacketBlobInTrace(
47     std::istream* input,
48     const std::function<void(std::unique_ptr<char[]>, size_t)>&);
49 
50 void ForEachPacketInTrace(
51     std::istream* input,
52     const std::function<void(const protos::TracePacket&)>&);
53 
54 }  // namespace trace_to_text
55 }  // namespace perfetto
56 
57 #endif  // TOOLS_TRACE_TO_TEXT_UTILS_H_
58