|
15 | 15 | #include "ray/core_worker/reference_counter.h" |
16 | 16 |
|
17 | 17 | #include <memory> |
18 | | -#include <nlohmann/json.hpp> |
19 | 18 | #include <string> |
20 | 19 | #include <unordered_map> |
21 | 20 | #include <unordered_set> |
|
25 | 24 | #include "ray/util/logging.h" |
26 | 25 | #include "ray/util/network_util.h" |
27 | 26 |
|
28 | | -using json = nlohmann::json; |
29 | | - |
30 | | -namespace { |
31 | | - |
32 | | -json AddressToJson(const ray::rpc::Address &address) { |
33 | | - return { |
34 | | - {"node_id", ray::NodeID::FromBinary(address.node_id()).Hex()}, |
35 | | - {"ip_address", address.ip_address()}, |
36 | | - {"port", address.port()}, |
37 | | - {"worker_id", ray::WorkerID::FromBinary(address.worker_id()).Hex()}, |
38 | | - }; |
39 | | -} |
40 | | - |
41 | | -template <class Container> |
42 | | -json IdContainerToJsonArray(const Container &c) { |
43 | | - json output = json::array(); |
44 | | - for (const auto &id : c) { |
45 | | - output.push_back(id.Hex()); |
46 | | - } |
47 | | - return output; |
48 | | -} |
49 | | - |
50 | | -constexpr const char *LineageReconstructionEligibilityToString( |
51 | | - ray::core::LineageReconstructionEligibility lre) noexcept { |
52 | | - switch (lre) { |
53 | | - case ray::core::LineageReconstructionEligibility::ELIGIBLE: |
54 | | - return "ELIGIBLE"; |
55 | | - case ray::core::LineageReconstructionEligibility::INELIGIBLE_PUT: |
56 | | - return "INELIGIBLE_PUT"; |
57 | | - case ray::core::LineageReconstructionEligibility::INELIGIBLE_NO_RETRIES: |
58 | | - return "INELIGIBLE_NO_RETRIES"; |
59 | | - case ray::core::LineageReconstructionEligibility::INELIGIBLE_LOCAL_MODE: |
60 | | - return "INELIGIBLE_LOCAL_MODE"; |
61 | | - case ray::core::LineageReconstructionEligibility::INELIGIBLE_LINEAGE_EVICTED: |
62 | | - return "INELIGIBLE_LINEAGE_EVICTED"; |
63 | | - case ray::core::LineageReconstructionEligibility::INELIGIBLE_LINEAGE_DISABLED: |
64 | | - return "INELIGIBLE_LINEAGE_DISABLED"; |
65 | | - case ray::core::LineageReconstructionEligibility::INELIGIBLE_REF_NOT_FOUND: |
66 | | - return "INELIGIBLE_REF_NOT_FOUND"; |
67 | | - default: |
68 | | - return "UNKNOWN"; |
69 | | - }; |
70 | | -}; |
71 | | - |
72 | | -}; // namespace |
73 | | - |
74 | 27 | #define PRINT_REF_COUNT(it) \ |
75 | 28 | RAY_LOG(DEBUG) << "REF " << it->first << ": " << it->second.DebugString(); |
76 | 29 |
|
@@ -1813,76 +1766,6 @@ std::string ReferenceCounter::DebugString() const { |
1813 | 1766 | return ss.str(); |
1814 | 1767 | } |
1815 | 1768 |
|
1816 | | -json ReferenceCounter::NestedReferenceCount::ToJson() const { |
1817 | | - return { |
1818 | | - {"contained_in_owned", IdContainerToJsonArray(contained_in_owned)}, |
1819 | | - {"contained_in_borrowed_ids", IdContainerToJsonArray(contained_in_borrowed_ids)}, |
1820 | | - {"contains", IdContainerToJsonArray(contains)}}; |
1821 | | -} |
1822 | | - |
1823 | | -json ReferenceCounter::BorrowInfo::ToJson() const { |
1824 | | - json stored_in_objects_json = json::array(); |
1825 | | - for (const auto &[object_id, addr] : stored_in_objects) { |
1826 | | - stored_in_objects_json.push_back( |
1827 | | - {{"object_id", object_id.Hex()}, {"address", AddressToJson(addr)}}); |
1828 | | - } |
1829 | | - json borrowers_json = json::array(); |
1830 | | - for (const auto &address : borrowers) { |
1831 | | - borrowers_json.push_back(AddressToJson(address)); |
1832 | | - } |
1833 | | - return {{"stored_in_objects", stored_in_objects_json}, {"borrowers", borrowers_json}}; |
1834 | | -} |
1835 | | - |
1836 | | -std::string ReferenceCounter::ToJsonString() const { |
1837 | | - absl::MutexLock lock(&mutex_); |
1838 | | - json ref_table_json = json::array(); |
1839 | | - for (const auto &[obj_id, reference] : object_id_refs_) { |
1840 | | - ref_table_json.push_back({ |
1841 | | - {"object_id", obj_id.Hex()}, |
1842 | | - {"reference", reference.ToJson()}, |
1843 | | - }); |
1844 | | - } |
1845 | | - json output = {{"rpc_address", AddressToJson(rpc_address_)}, |
1846 | | - {"reference_table", ref_table_json}, |
1847 | | - {"freed_objects", IdContainerToJsonArray(freed_objects_)}, |
1848 | | - {"reconstructable_owned_objects", |
1849 | | - IdContainerToJsonArray(reconstructable_owned_objects_)}, |
1850 | | - {"objects_to_recover", IdContainerToJsonArray(objects_to_recover_)}}; |
1851 | | - return output.dump(); |
1852 | | -} |
1853 | | - |
1854 | | -json ReferenceCounter::Reference::ToJson() const { |
1855 | | - return { |
1856 | | - {"call_site", call_site_}, |
1857 | | - {"object_size", object_size_}, |
1858 | | - {"locations", IdContainerToJsonArray(locations)}, |
1859 | | - {"owner_address", owner_address_ ? AddressToJson(*owner_address_) : json(nullptr)}, |
1860 | | - {"pinned_at_node_id", |
1861 | | - pinned_at_node_id_ ? json(pinned_at_node_id_->Hex()) : json(nullptr)}, |
1862 | | - {"tensor_transport", tensor_transport_ ? json(*tensor_transport_) : json(nullptr)}, |
1863 | | - {"owned_by_us", owned_by_us_}, |
1864 | | - {"lineage_eligibility", |
1865 | | - LineageReconstructionEligibilityToString(lineage_eligibility_)}, |
1866 | | - {"lineage_ref_count", lineage_ref_count}, |
1867 | | - {"local_ref_count", local_ref_count}, |
1868 | | - {"submitted_task_ref_count", submitted_task_ref_count}, |
1869 | | - {"nested_reference_count", |
1870 | | - nested_reference_count ? nested_reference_count->ToJson() : json(nullptr)}, |
1871 | | - {"borrow_info", borrow_info ? borrow_info->ToJson() : json(nullptr)}, |
1872 | | - {"num_object_out_of_scope_or_freed_callbacks", |
1873 | | - on_object_out_of_scope_or_freed_callbacks.size()}, |
1874 | | - {"num_object_ref_deleted_callbacks", object_ref_deleted_callbacks.size()}, |
1875 | | - {"publish_ref_removed", publish_ref_removed}, |
1876 | | - {"spilled_url", spilled_url}, |
1877 | | - {"spilled_node_id", spilled_node_id.Hex()}, |
1878 | | - {"spilled", spilled}, |
1879 | | - {"foreign_owner_already_monitoring", foreign_owner_already_monitoring}, |
1880 | | - {"has_nested_refs_report", has_nested_refs_to_report}, |
1881 | | - {"pending_creation", pending_creation_}, |
1882 | | - {"did_spill", did_spill}, |
1883 | | - }; |
1884 | | -} |
1885 | | - |
1886 | 1769 | std::string ReferenceCounter::Reference::DebugString() const { |
1887 | 1770 | std::stringstream ss; |
1888 | 1771 | ss << "Reference{borrowers: " << borrow().borrowers.size() |
|
0 commit comments