stat_dtc.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  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. */
  17. #include <unistd.h>
  18. #include <stdlib.h>
  19. #include "stat_dtc.h"
  20. #include "version.h"
  21. #include "log/log.h"
  22. StatThread g_stat_mgr;
  23. //初始化内存映射
  24. int init_statistics(void)
  25. {
  26. int ret;
  27. ret = g_stat_mgr.init_stat_info("core", STATIDX);
  28. // -1, recreate, -2, failed
  29. if (ret == -1) {
  30. unlink(STATIDX);
  31. char buf[64];
  32. ret = g_stat_mgr.create_stat_index(
  33. "core", STATIDX, g_stat_definition, buf, sizeof(buf));
  34. if (ret != 0) {
  35. log4cplus_error("CreateStatIndex failed: %s",
  36. g_stat_mgr.get_error_message());
  37. exit(ret);
  38. }
  39. ret = g_stat_mgr.init_stat_info("core", STATIDX);
  40. }
  41. if (ret == 0) {
  42. int v1, v2, v3;
  43. sscanf(DTC_VERSION, "%d.%d.%d", &v1, &v2, &v3);
  44. g_stat_mgr.get_stat_iterm(S_VERSION) =
  45. v1 * 10000 + v2 * 100 + v3;
  46. g_stat_mgr.get_stat_iterm(C_TIME) = compile_time;
  47. } else {
  48. log4cplus_error("init_stat_info failed: %s",
  49. g_stat_mgr.get_error_message());
  50. exit(ret);
  51. }
  52. return ret;
  53. }