blob: 7f012f9c1a3531ea158d62038fdba7bad61c179b [file] [log] [blame]
Brian Hamrickd57e1332019-04-24 11:25:36 -07001/*
2 * Copyright (C) 2019 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#include "src/trace_processor/fuchsia_trace_utils.h"
18
19namespace perfetto {
20namespace trace_processor {
21namespace fuchsia_trace_utils {
22
23namespace {
Brian Hamrickfc074312019-04-25 14:50:31 -070024constexpr uint32_t kInlineStringMarker = 0x8000;
25constexpr uint32_t kInlineStringLengthMask = 0x7FFF;
Brian Hamrickd57e1332019-04-24 11:25:36 -070026} // namespace
27
28bool IsInlineString(uint32_t string_ref) {
29 // Treat a string ref of 0 (the empty string) as inline. The empty string is
30 // not a true entry in the string table.
31 return (string_ref & kInlineStringMarker) || (string_ref == 0);
32}
33
34base::StringView ReadInlineString(const uint64_t** current_ptr,
35 uint32_t string_ref) {
36 // Note that this works correctly for the empty string, where string_ref is 0.
37 size_t len = string_ref & kInlineStringLengthMask;
38 size_t len_words = (len + 7) / 8;
39 base::StringView s(reinterpret_cast<const char*>(*current_ptr), len);
40 *current_ptr += len_words;
41 return s;
42}
43
44bool IsInlineThread(uint32_t thread_ref) {
45 return thread_ref == 0;
46}
47
48ThreadInfo ReadInlineThread(const uint64_t** current_ptr) {
49 ThreadInfo ret;
50 ret.pid = **current_ptr;
51 (*current_ptr)++;
52 ret.tid = **current_ptr;
53 (*current_ptr)++;
54 return ret;
55}
56
57int64_t ReadTimestamp(const uint64_t** current_ptr, uint64_t ticks_per_second) {
58 uint64_t ticks = **current_ptr;
59 (*current_ptr)++;
60 return TicksToNs(ticks, ticks_per_second);
61}
62
63int64_t TicksToNs(uint64_t ticks, uint64_t ticks_per_second) {
64 return static_cast<int64_t>(ticks * uint64_t(1000000000) / ticks_per_second);
65}
66
67} // namespace fuchsia_trace_utils
68} // namespace trace_processor
69} // namespace perfetto