| 1001 | } |
| 1002 | |
| 1003 | static struct stat_series *new_stat_series(struct stat_series_profile *profile, str *name) |
| 1004 | { |
| 1005 | struct stat_series *ss; |
| 1006 | |
| 1007 | /* we should first check whether there is an overlapping statistic with |
| 1008 | * this name, since we are not allowed to have that |
| 1009 | */ |
| 1010 | if (get_stat(name)) { |
| 1011 | LM_DBG("%.*s stat already exists!\n", name->len, name->s); |
| 1012 | return NULL; |
| 1013 | } |
| 1014 | |
| 1015 | ss = shm_malloc(sizeof *ss + name->len + 1 + |
| 1016 | profile->slots * sizeof (*ss->slots)); |
| 1017 | if (!ss) { |
| 1018 | LM_ERR("could not allocate new stat series!\n"); |
| 1019 | return NULL; |
| 1020 | } |
| 1021 | memset(ss, 0, sizeof (*ss)); |
| 1022 | lock_init(&ss->lock); |
| 1023 | ss->profile = profile; |
| 1024 | ss->name = (char *)(ss + 1); |
| 1025 | memcpy(ss->name, name->s, name->len); |
| 1026 | ss->name[name->len] = 0; |
| 1027 | ss->slots = (union stat_series_slot *)(ss->name + name->len + 1); |
| 1028 | memset(ss->slots, 0, profile->slots * sizeof (*ss->slots)); |
| 1029 | |
| 1030 | /* all good - register the stat now */ |
| 1031 | if (register_stat2(profile->group.s, ss->name, (stat_var **)get_stat_series, |
| 1032 | STAT_NO_RESET|STAT_IS_FUNC, ss, 0) != 0) { |
| 1033 | LM_ERR("could not add dynamic statistic\n"); |
| 1034 | stat_series_free(ss); |
| 1035 | return NULL; |
| 1036 | } |
| 1037 | return ss; |
| 1038 | } |
| 1039 | |
| 1040 | static int update_stat_series(struct stat_series *ss, int value) |
| 1041 | { |
no test coverage detected