uid_info.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2017 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. #ifndef _UID_INFO_H_
  17. #define _UID_INFO_H_
  18. #include <string>
  19. #include <unordered_map>
  20. #include <binder/Parcelable.h>
  21. namespace android {
  22. namespace os {
  23. namespace storaged {
  24. enum uid_stat_t {
  25. FOREGROUND = 0,
  26. BACKGROUND = 1,
  27. UID_STATS = 2
  28. };
  29. enum charger_stat_t {
  30. CHARGER_OFF = 0,
  31. CHARGER_ON = 1,
  32. CHARGER_STATS = 2
  33. };
  34. enum io_type_t {
  35. READ = 0,
  36. WRITE = 1,
  37. IO_TYPES = 2
  38. };
  39. struct io_stats {
  40. uint64_t rchar; // characters read
  41. uint64_t wchar; // characters written
  42. uint64_t read_bytes; // bytes read (from storage layer)
  43. uint64_t write_bytes; // bytes written (to storage layer)
  44. uint64_t fsync; // number of fsync syscalls
  45. };
  46. class task_info {
  47. public:
  48. std::string comm;
  49. pid_t pid;
  50. io_stats io[UID_STATS];
  51. bool parse_task_io_stats(std::string&& s);
  52. };
  53. class UidInfo : public Parcelable {
  54. public:
  55. uint32_t uid; // user id
  56. std::string name; // package name
  57. io_stats io[UID_STATS]; // [0]:foreground [1]:background
  58. std::unordered_map<uint32_t, task_info> tasks; // mapped from pid
  59. status_t writeToParcel(Parcel* parcel) const override;
  60. status_t readFromParcel(const Parcel* parcel) override;
  61. };
  62. } // namespace storaged
  63. } // namespace os
  64. } // namespace android
  65. #endif /* _UID_INFO_H_ */