summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2020-01-04 19:19:01 +0100
committerJoel Rosdahl <joel@rosdahl.net>2020-01-05 20:02:21 +0100
commit1d2b76a71b12c2ffdd107f89a3d9caa6cd223d44 (patch)
tree696c74ef024963be1398cda698446cec83b316bd
parentc972eb6e824624956444e945bdfd9768c7e74123 (diff)
downloadccache-1d2b76a71b12c2ffdd107f89a3d9caa6cd223d44.tar.gz
Make sure to always log a “Result:” line
Fixes #500. A side effect of this is that read-only cache misses now will update the “cache miss” statistics counter, which is consistent with the cache hit cases (which already now update the counters).
-rw-r--r--doc/MANUAL.adoc10
-rw-r--r--src/ccache.c18
-rw-r--r--src/ccache.h4
-rw-r--r--src/stats.c36
-rw-r--r--test/suites/readonly.bash6
-rw-r--r--test/suites/readonly_direct.bash2
6 files changed, 50 insertions, 26 deletions
diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc
index 1717c18e..409d5608 100644
--- a/doc/MANUAL.adoc
+++ b/doc/MANUAL.adoc
@@ -508,9 +508,13 @@ might be incorrect.
*read_only* (*CCACHE_READONLY* or *CCACHE_NOREADONLY*, see <<_boolean_values,Boolean values>> above)::
If true, ccache will attempt to use existing cached object files, but it
- will not to try to add anything new to the cache. If you are using this
- because your ccache directory is read-only, then you need to set
- *temporary_dir* as otherwise ccache will fail to create temporary files.
+ will not add new results to the cache. Statistics counters will still be
+ updated, though, unless the *stats* option is set to *false*.
++
+If you are using this because your ccache directory is read-only, you need to
+set *temporary_dir* since ccache will fail to create temporary files otherwise.
+You may also want to set *stats = false* to make ccache not even try to update
+stats files.
*read_only_direct* (*CCACHE_READONLY_DIRECT* or *CCACHE_NOREADONLY_DIRECT*, see <<_boolean_values,Boolean values>> above)::
diff --git a/src/ccache.c b/src/ccache.c
index 9978d387..e617bf48 100644
--- a/src/ccache.c
+++ b/src/ccache.c
@@ -595,6 +595,7 @@ get_current_working_dir(void)
if (!current_working_dir) {
cc_log("Unable to determine current working directory: %s",
strerror(errno));
+ stats_update(STATS_ERROR);
failed();
}
}
@@ -1519,18 +1520,21 @@ to_cache(struct args *args, struct hash *depend_mode_hash)
if (x_rename(tmp_stderr, tmp_stderr2)) {
cc_log("Failed to rename %s to %s: %s", tmp_stderr, tmp_stderr2,
strerror(errno));
+ stats_update(STATS_ERROR);
failed();
}
int fd_cpp_stderr = open(cpp_stderr, O_RDONLY | O_BINARY);
if (fd_cpp_stderr == -1) {
cc_log("Failed opening %s: %s", cpp_stderr, strerror(errno));
+ stats_update(STATS_ERROR);
failed();
}
int fd_real_stderr = open(tmp_stderr2, O_RDONLY | O_BINARY);
if (fd_real_stderr == -1) {
cc_log("Failed opening %s: %s", tmp_stderr2, strerror(errno));
+ stats_update(STATS_ERROR);
failed();
}
@@ -1538,6 +1542,7 @@ to_cache(struct args *args, struct hash *depend_mode_hash)
open(tmp_stderr, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
if (fd_result == -1) {
cc_log("Failed opening %s: %s", tmp_stderr, strerror(errno));
+ stats_update(STATS_ERROR);
failed();
}
@@ -1572,6 +1577,7 @@ to_cache(struct args *args, struct hash *depend_mode_hash)
struct file_hash *object_hash =
object_hash_from_depfile(output_dep, depend_mode_hash);
if (!object_hash) {
+ stats_update(STATS_ERROR);
failed();
}
update_cached_result_globals(object_hash);
@@ -1634,7 +1640,7 @@ to_cache(struct args *args, struct hash *depend_mode_hash)
MTR_END("file", "file_put");
- stats_update(STATS_TOCACHE);
+ stats_update(STATS_CACHEMISS);
// Make sure we have a CACHEDIR.TAG in the cache part of cache_dir. This can
// be done almost anywhere, but we might as well do it near the end as we
@@ -2241,6 +2247,7 @@ calculate_object_hash(struct args *args, struct hash *hash, int direct_mode)
hash_delimiter(hash, "sourcecode");
int result = hash_source_code_file(conf, hash, input_file);
if (result & HASH_SOURCE_CODE_ERROR) {
+ stats_update(STATS_ERROR);
failed();
}
if (result & HASH_SOURCE_CODE_FOUND_TIME) {
@@ -2585,6 +2592,7 @@ cc_process_args(struct args *args,
i++;
if (i == argc) {
cc_log("--ccache-skip lacks an argument");
+ stats_update(STATS_ARGS);
result = false;
goto out;
}
@@ -3091,6 +3099,7 @@ cc_process_args(struct args *args,
// know what the user means, and what the compiler will do.
if (arg_profile_dir && profile_dir) {
cc_log("Profile directory already set; giving up");
+ stats_update(STATS_UNSUPPORTED_OPTION);
result = false;
goto out;
} else if (arg_profile_dir) {
@@ -3885,6 +3894,7 @@ set_up_uncached_err(void)
int uncached_fd = dup(2); // The file descriptor is intentionally leaked.
if (uncached_fd == -1) {
cc_log("dup(2) failed: %s", strerror(errno));
+ stats_update(STATS_ERROR);
failed();
}
@@ -3892,6 +3902,7 @@ set_up_uncached_err(void)
char *buf = format("UNCACHED_ERR_FD=%d", uncached_fd);
if (putenv(buf) == -1) {
cc_log("putenv failed: %s", strerror(errno));
+ stats_update(STATS_ERROR);
failed();
}
}
@@ -3935,6 +3946,7 @@ ccache(int argc, char *argv[])
if (conf->disable) {
cc_log("ccache is disabled");
+ stats_update(STATS_CACHEMISS); // Dummy to trigger stats_flush.
failed();
}
@@ -3962,7 +3974,7 @@ ccache(int argc, char *argv[])
MTR_BEGIN("main", "process_args");
if (!cc_process_args(
orig_args, &preprocessor_args, &extra_args_to_hash, &compiler_args)) {
- failed();
+ failed(); // stats_update is called in cc_process_args.
}
MTR_END("main", "process_args");
@@ -4050,6 +4062,7 @@ ccache(int argc, char *argv[])
if (conf->read_only_direct) {
cc_log("Read-only direct mode; running real compiler");
+ stats_update(STATS_CACHEMISS);
failed();
}
@@ -4096,6 +4109,7 @@ ccache(int argc, char *argv[])
if (conf->read_only) {
cc_log("Read-only mode; running real compiler");
+ stats_update(STATS_CACHEMISS);
failed();
}
diff --git a/src/ccache.h b/src/ccache.h
index cabc980d..0d6be609 100644
--- a/src/ccache.h
+++ b/src/ccache.h
@@ -1,5 +1,5 @@
// Copyright (C) 2002-2007 Andrew Tridgell
-// Copyright (C) 2009-2019 Joel Rosdahl
+// Copyright (C) 2009-2020 Joel Rosdahl
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -43,7 +43,7 @@ enum stats {
STATS_STDOUT = 1,
STATS_STATUS = 2,
STATS_ERROR = 3,
- STATS_TOCACHE = 4,
+ STATS_CACHEMISS = 4,
STATS_PREPROCESSOR = 5,
STATS_COMPILER = 6,
STATS_MISSING = 7,
diff --git a/src/stats.c b/src/stats.c
index 214f3be5..c06c44b4 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -1,5 +1,5 @@
// Copyright (C) 2002-2004 Andrew Tridgell
-// Copyright (C) 2009-2019 Joel Rosdahl
+// Copyright (C) 2009-2020 Joel Rosdahl
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -79,7 +79,7 @@ static struct {
FLAG_ALWAYS
},
{
- STATS_TOCACHE,
+ STATS_CACHEMISS,
"cache_miss",
"cache miss",
NULL,
@@ -370,7 +370,7 @@ stats_hit_rate(struct counters *counters)
unsigned direct = counters->data[STATS_CACHEHIT_DIR];
unsigned preprocessed = counters->data[STATS_CACHEHIT_CPP];
unsigned hit = direct + preprocessed;
- unsigned miss = counters->data[STATS_TOCACHE];
+ unsigned miss = counters->data[STATS_CACHEMISS];
unsigned total = hit + miss;
return total > 0 ? (100.0 * hit) / total : 0.0;
}
@@ -442,11 +442,26 @@ stats_flush_to_file(const char *sfile, struct counters *updates)
{
assert(conf);
- if (!conf->stats) {
+ if (!updates) {
return;
}
- if (!updates) {
+ if (conf->disable) {
+ // Just log result, don't update statistics.
+ cc_log("Result: disabled");
+ return;
+ }
+
+ if (!str_eq(conf->log_file, "") || conf->debug) {
+ for (int i = 0; i < STATS_END; ++i) {
+ if (updates->data[stats_info[i].stat] != 0
+ && !(stats_info[i].flags & FLAG_NOZERO)) {
+ cc_log("Result: %s", stats_info[i].message);
+ }
+ }
+ }
+
+ if (!conf->stats) {
return;
}
@@ -483,15 +498,6 @@ stats_flush_to_file(const char *sfile, struct counters *updates)
stats_write(sfile, counters);
lockfile_release(sfile);
- if (!str_eq(conf->log_file, "") || conf->debug) {
- for (int i = 0; i < STATS_END; ++i) {
- if (updates->data[stats_info[i].stat] != 0
- && !(stats_info[i].flags & FLAG_NOZERO)) {
- cc_log("Result: %s", stats_info[i].message);
- }
- }
- }
-
char *subdir = dirname(sfile);
bool need_cleanup = false;
@@ -591,7 +597,7 @@ stats_summary(void)
free(value);
}
- if (stat == STATS_TOCACHE) {
+ if (stat == STATS_CACHEMISS) {
double percent = stats_hit_rate(counters);
printf("cache hit rate %6.2f %%\n", percent);
}
diff --git a/test/suites/readonly.bash b/test/suites/readonly.bash
index be986966..5cdbc251 100644
--- a/test/suites/readonly.bash
+++ b/test/suites/readonly.bash
@@ -44,9 +44,9 @@ SUITE_readonly() {
if [ $? -ne 0 ]; then
test_failed "Failure when compiling test2.c read-only"
fi
- if [ -d $CCACHE_DIR ]; then
- test_failed "ccache dir was created"
- fi
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 1
+ expect_stat 'files in cache' 0
# -------------------------------------------------------------------------
# Check that read-only mode and direct mode work together.
diff --git a/test/suites/readonly_direct.bash b/test/suites/readonly_direct.bash
index b1ea4c6e..9a7636f4 100644
--- a/test/suites/readonly_direct.bash
+++ b/test/suites/readonly_direct.bash
@@ -29,5 +29,5 @@ SUITE_readonly_direct() {
CCACHE_READONLY_DIRECT=1 $CCACHE_COMPILE -DFOO -c test.c -o test.o
expect_stat 'cache hit (direct)' 0
expect_stat 'cache hit (preprocessed)' 0
- expect_stat 'cache miss' 1
+ expect_stat 'cache miss' 2
}