forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TraceHistory and beef up TraceContext usages (facebookincubator#8677
) Summary: Pull Request resolved: facebookincubator#8677 Original commit changeset: 55c9738305a1 Original Phabricator Diff: D53365055 Reviewed By: oerling Differential Revision: D53438972 fbshipit-source-id: 0cb31a71d458880128bfc5b223a50caaeef88025
- Loading branch information
1 parent
18c1701
commit 5f57033
Showing
16 changed files
with
497 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "velox/common/process/TraceHistory.h" | ||
|
||
#include <folly/system/ThreadId.h> | ||
|
||
#include <algorithm> | ||
|
||
namespace facebook::velox::process { | ||
|
||
namespace { | ||
auto registry = std::make_shared<ThreadLocalRegistry<TraceHistory>>(); | ||
} | ||
|
||
namespace detail { | ||
thread_local ThreadLocalRegistry<TraceHistory>::Reference traceHistory( | ||
registry); | ||
} | ||
|
||
TraceHistory::TraceHistory() | ||
: threadId_(std::this_thread::get_id()), osTid_(folly::getOSThreadID()) {} | ||
|
||
std::vector<TraceHistory::EntriesWithThreadInfo> TraceHistory::listAll() { | ||
std::vector<EntriesWithThreadInfo> results; | ||
registry->forAllValues([&](auto& history) { | ||
EntriesWithThreadInfo result; | ||
result.threadId = history.threadId_; | ||
result.osTid = history.osTid_; | ||
for (int i = 0; i < kCapacity; ++i) { | ||
const int j = (history.index_ + kCapacity - 1 - i) % kCapacity; | ||
if (!populated(history.data_[j])) { | ||
break; | ||
} | ||
result.entries.push_back(history.data_[j]); | ||
} | ||
std::reverse(result.entries.begin(), result.entries.end()); | ||
results.push_back(std::move(result)); | ||
}); | ||
return results; | ||
} | ||
|
||
} // namespace facebook::velox::process |
Oops, something went wrong.