123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- /*
- * Copyright Institute of Communication and Computer Systems (ICCS)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- /**
- * @file parse_env.c
- * @author Ioannis Koutras (joko@microlab.ntua.gr)
- * @date November 2012
- * @brief Parse the DMMLIB_OPTS enviroment variable.
- */
- #include <inttypes.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include "dmmlib/config.h"
- #include "dmmlib/dmmlib.h"
- #include "dmmlib_trace.h"
- __attribute__((constructor)) void parse_env(void);
- /** Parses the DMMLIB_OPTS enviroment variable. */
- void parse_env(void) {
- const char* env;
- #ifdef WITH_MEM_TRACE
- env = getenv("DMMLIB_MEM_TRACE");
- if(env == NULL) {
- mem_fd = stderr;
- } else {
- mem_fd = fopen(env, "a+");
- }
- #endif /* WITH_MEM_TRACE */
- #ifdef WITH_STATS_TRACE
- env = getenv("DMMLIB_STATS_TRACE");
- if(env == NULL) {
- stats_fd = stderr;
- } else {
- stats_fd = fopen(env, "a+");
- }
- #endif /* WITH_STATS_TRACE */
- #ifdef WITH_DEBUG
- env = getenv("DMMLIB_DBG_TRACE");
- if(env == NULL) {
- dbg_fd = stderr;
- } else {
- dbg_fd = fopen(env, "a+");
- }
- #endif /* WITH_DEBUG */
- #if defined WITH_KNOBS && defined GOOD_FIT
- env = getenv("DMMLIB_GOOD_FIT");
- if(env != NULL) {
- char *end;
- double good_fit_perc = strtod(env, &end);
- if(good_fit_perc != 0) {
- systemallocator.dmm_knobs.fit_percentage = good_fit_perc;
- }
- }
- #endif /* WITH_KNOBS && GOOD_FIT */
- #ifdef WITH_KNOBS
- env = getenv("DMMLIB_SYSALLOC_SZ");
- if(env != NULL) {
- char *end;
- uintmax_t num = strtoumax(env, &end, 10);
- if(num != UINTMAX_MAX) {
- systemallocator.dmm_knobs.sys_alloc_size = (double) num;
- }
- }
- #endif /* WITH_KNOBS */
- systemallocator.initialized = true;
- return;
- }
- #if defined WITH_MEM_TRACE || defined WITH_STATS_TRACE || defined WITH_DEBUG
- __attribute__((destructor)) void close_trace_files(void);
- /** Closes the opened trace files. */
- void close_trace_files(void) {
- #ifdef WITH_MEM_TRACE
- if(mem_fd != stderr) {
- fclose(mem_fd);
- }
- #endif /* WITH_MEM_TRACE */
- #ifdef WITH_STATS_TRACE
- if(stats_fd != stderr) {
- fclose(stats_fd);
- }
- #endif /* WITH_STATS_TRACE */
- #ifdef WITH_DEBUG
- if(dbg_fd != stderr) {
- fclose(dbg_fd);
- }
- #endif /* WITH_DEBUG */
- return;
- }
- #endif /* WITH_MEM_TRACE || WITH_STATS_TRACE || WITH_DEBUG */
|