Search in sources :

Example 41 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class ProfilingStatementHandler method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (method.getName().startsWith("execute")) {
        Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start();
        Object result;
        try {
            result = InvocationUtils.invokeQuietly(statement, method, args);
        } finally {
            String sql = (String) args[0];
            profiler.addContext("sql", SqlLogFormatter.reformatSql(sql));
            profiler.stopTrace("");
        }
        return result;
    } else {
        return InvocationUtils.invokeQuietly(statement, method, args);
    }
}
Also used : Profiler(org.sonar.api.utils.log.Profiler)

Example 42 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class DetectPluginChange method start.

@Override
public void start() {
    Preconditions.checkState(changesDetected == null, "Can only call #start() once");
    Profiler profiler = Profiler.create(LOG).startInfo("Detect plugin changes");
    changesDetected = anyChange();
    if (changesDetected) {
        LOG.debug("Plugin changes detected");
    } else {
        LOG.info("No plugin change detected");
    }
    profiler.stopDebug();
}
Also used : Profiler(org.sonar.api.utils.log.Profiler)

Example 43 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class GeneratePluginIndex method start.

@Override
public void start() {
    Profiler profiler = Profiler.create(LOG).startInfo("Generate scanner plugin index");
    writeIndex(serverFs.getPluginIndex());
    profiler.stopDebug();
}
Also used : Profiler(org.sonar.api.utils.log.Profiler)

Example 44 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class RegisterMetrics method register.

void register(Iterable<Metric> metrics) {
    Profiler profiler = Profiler.create(LOG).startInfo("Register metrics");
    try (DbSession session = dbClient.openSession(true)) {
        save(session, metrics);
        sanitizeQualityGates(session);
        session.commit();
    }
    profiler.stopDebug();
}
Also used : DbSession(org.sonar.db.DbSession) Profiler(org.sonar.api.utils.log.Profiler)

Example 45 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class RegisterRules method mergeParams.

private void mergeParams(RegisterRulesContext context, RulesDefinition.Rule ruleDef, RuleDefinitionDto rule, DbSession session) {
    List<RuleParamDto> paramDtos = context.getRuleParametersFor(rule.getUuid());
    Map<String, RuleParamDto> existingParamsByName = new HashMap<>();
    Profiler profiler = Profiler.create(Loggers.get(getClass()));
    for (RuleParamDto paramDto : paramDtos) {
        RulesDefinition.Param paramDef = ruleDef.param(paramDto.getName());
        if (paramDef == null) {
            profiler.start();
            dbClient.activeRuleDao().deleteParamsByRuleParam(session, paramDto);
            profiler.stopDebug(format("Propagate deleted param with name %s to active rules of rule %s", paramDto.getName(), rule.getKey()));
            dbClient.ruleDao().deleteRuleParam(session, paramDto.getUuid());
        } else {
            if (mergeParam(paramDto, paramDef)) {
                dbClient.ruleDao().updateRuleParam(session, rule, paramDto);
            }
            existingParamsByName.put(paramDto.getName(), paramDto);
        }
    }
    // Create newly parameters
    for (RulesDefinition.Param param : ruleDef.params()) {
        RuleParamDto paramDto = existingParamsByName.get(param.key());
        if (paramDto != null) {
            continue;
        }
        paramDto = RuleParamDto.createFor(rule).setName(param.key()).setDescription(param.description()).setDefaultValue(param.defaultValue()).setType(param.type().toString());
        dbClient.ruleDao().insertRuleParam(session, rule, paramDto);
        if (StringUtils.isEmpty(param.defaultValue())) {
            continue;
        }
        // Propagate the default value to existing active rule parameters
        profiler.start();
        for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRuleUuid(session, rule.getUuid())) {
            ActiveRuleParamDto activeParam = ActiveRuleParamDto.createFor(paramDto).setValue(param.defaultValue());
            dbClient.activeRuleDao().insertParam(session, activeRule, activeParam);
        }
        profiler.stopDebug(format("Propagate new param with name %s to active rules of rule %s", paramDto.getName(), rule.getKey()));
    }
}
Also used : RulesDefinition(org.sonar.api.server.rule.RulesDefinition) Profiler(org.sonar.api.utils.log.Profiler) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Aggregations

Profiler (org.sonar.api.utils.log.Profiler)56 Bean (org.springframework.context.annotation.Bean)7 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 DbSession (org.sonar.db.DbSession)5 GetRequest (org.sonarqube.ws.client.GetRequest)5 File (java.io.File)3 Reader (java.io.Reader)3 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)3 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 CheckForNull (javax.annotation.CheckForNull)2 OptInCaching (org.picocontainer.behaviors.OptInCaching)2 ReflectionLifecycleStrategy (org.picocontainer.lifecycle.ReflectionLifecycleStrategy)2 NullComponentMonitor (org.picocontainer.monitors.NullComponentMonitor)2 InputFile (org.sonar.api.batch.fs.InputFile)2 NewRule (org.sonar.api.batch.rule.internal.NewRule)2 RulesBuilder (org.sonar.api.batch.rule.internal.RulesBuilder)2