Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug in
absl::SetVLogLevel
where a less generic pattern incorr…
…ectly removed a more generic one. ### Example: The user passes `--vmodule=*pipeline*=10` to enable logs in files containing `"pipeline"` in their names: ``` pipeline_a.cc pipeline_b.cc pipeline_c.cc ``` Additionally, `pipeline_a.cc` executes `absl::SetVlogLevel("pipeline_a", 10)`. ### Expected behavior: VLOG level `10` is enabled in all files containing `"pipeline"` in their names. `absl::SetVlogLevel("pipeline_a", 10)` should not affect this, as `pipeline_a.cc` is already covered by `--vmodule=*pipeline*=10` and have the same level there. ### Actual behavior (before the CL): VLOG level `10` is enabled only in `pipeline_a.cc`. `--vmodule=*pipeline*=10` is ignored. ### Reason: `absl::SetVlogLevel` is based on `PrependVModuleLocked`. The issue lies in the following code within `PrependVModuleLocked`: ```cc // This is a memory optimization to avoid storing patterns that will never // match due to exit early semantics. Primarily optimized for our own unit // tests. get_vmodule_info().erase( std::remove_if(++iter, get_vmodule_info().end(), [module_pattern](const VModuleInfo& info) { return FNMatch(info.module_pattern, module_pattern); }), get_vmodule_info().cend()); ``` When `absl::SetVlogLevel("pipeline_a", 10)` is executed, `get_vmodule_info()` contains `"*pipeline*"`. Therefore, `info.module_pattern` equals to `"*pipeline*"` and `module_pattern` equals to `"pipeline_a"`. Because `"pipeline_a"` matches the pattern `"*pipeline*"`, the pattern `"*pipeline*"` is erroneously erased. `get_vmodule_info()` then only contains the `"pipeline_a"` pattern. ### Solution: This CL corrects the order of the arguments in `FNMatch` to: ```cc FNMatch(module_pattern, info.module_pattern); ``` This ensures that it correctly checks if the new pattern is more general than the previous pattern, but not vice versa. In the example above, the new pattern `"pipeline_a"` does not match the previous `"*pipeline*"` pattern. Therefore, `get_vmodule_info()` retains both patterns in the following order: `"pipeline_a"`, `"*pipeline*"`. PiperOrigin-RevId: 675776298 Change-Id: I9550dbd4282e66799619369894b8304856a7a777
- Loading branch information