/proc/self/cwd/opencensus/trace/internal/trace_options.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2017, OpenCensus Authors |
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 | | #include "opencensus/trace/trace_options.h" |
16 | | |
17 | | #include <cstdint> |
18 | | #include <string> |
19 | | |
20 | | #include "absl/strings/escaping.h" |
21 | | #include "absl/strings/string_view.h" |
22 | | |
23 | | namespace opencensus { |
24 | | namespace trace { |
25 | | namespace { |
26 | | // One bit per option. |
27 | | constexpr uint8_t kIsSampled = 1; |
28 | | } // namespace |
29 | | |
30 | 1.08k | TraceOptions::TraceOptions(const uint8_t* buf) { memcpy(rep_, buf, kSize); } |
31 | | |
32 | 630 | bool TraceOptions::IsSampled() const { return rep_[0] & kIsSampled; } |
33 | | |
34 | 0 | bool TraceOptions::operator==(const TraceOptions& that) const { |
35 | 0 | return memcmp(rep_, that.rep_, kSize) == 0; |
36 | 0 | } |
37 | | |
38 | 219 | std::string TraceOptions::ToHex() const { |
39 | 219 | return absl::BytesToHexString( |
40 | 219 | absl::string_view(reinterpret_cast<const char*>(rep_), kSize)); |
41 | 219 | } |
42 | | |
43 | 230 | void TraceOptions::CopyTo(uint8_t* buf) const { memcpy(buf, rep_, kSize); } |
44 | | |
45 | 0 | TraceOptions TraceOptions::WithSampling(bool is_sampled) const { |
46 | 0 | uint8_t buf[kSize]; |
47 | 0 | CopyTo(buf); |
48 | 0 | buf[0] = (buf[0] & ~kIsSampled) | (is_sampled ? kIsSampled : 0); |
49 | 0 | return TraceOptions(buf); |
50 | 0 | } |
51 | | |
52 | | } // namespace trace |
53 | | } // namespace opencensus |