JobDiagnosticTracker.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/EBus/EBus.h>
  10. #include <native/resourcecompiler/RCCommon.h>
  11. namespace AssetProcessor
  12. {
  13. struct JobDiagnosticInfo
  14. {
  15. JobDiagnosticInfo() = default;
  16. JobDiagnosticInfo(AZ::u32 warningCount, AZ::u32 errorCount)
  17. : m_warningCount(warningCount), m_errorCount(errorCount)
  18. {}
  19. bool operator==(const JobDiagnosticInfo& rhs) const;
  20. bool operator!=(const JobDiagnosticInfo& rhs) const;
  21. AZ::u32 m_warningCount = 0;
  22. AZ::u32 m_errorCount = 0;
  23. };
  24. enum class WarningLevel : AZ::u8
  25. {
  26. Default = 0,
  27. FatalErrors,
  28. FatalErrorsAndWarnings
  29. };
  30. class JobDiagnosticRequests
  31. : public AZ::EBusTraits
  32. {
  33. public:
  34. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  35. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  36. typedef AZStd::recursive_mutex MutexType;
  37. virtual JobDiagnosticInfo GetDiagnosticInfo(AZ::u64 jobRunKey) const = 0;
  38. virtual void RecordDiagnosticInfo(AZ::u64 jobRunKey, JobDiagnosticInfo info) = 0;
  39. virtual WarningLevel GetWarningLevel() const = 0;
  40. virtual void SetWarningLevel(WarningLevel level) = 0;
  41. };
  42. using JobDiagnosticRequestBus = AZ::EBus<JobDiagnosticRequests>;
  43. class JobDiagnosticTracker
  44. : public JobDiagnosticRequestBus::Handler
  45. {
  46. public:
  47. JobDiagnosticTracker();
  48. ~JobDiagnosticTracker();
  49. JobDiagnosticInfo GetDiagnosticInfo(AZ::u64 jobRunKey) const override;
  50. void RecordDiagnosticInfo(AZ::u64 jobRunKey, JobDiagnosticInfo info) override;
  51. WarningLevel GetWarningLevel() const override;
  52. void SetWarningLevel(WarningLevel level) override;
  53. WarningLevel m_warningLevel = WarningLevel::Default;
  54. AZStd::unordered_map<AZ::u64, JobDiagnosticInfo> m_jobInfo;
  55. };
  56. } // namespace AssetProcessor