File: debug_info_printer.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (82 lines) | stat: -rw-r--r-- 3,009 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/web_applications/test/debug_info_printer.h"

#include <string_view>

#include "base/command_line.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/web_app_internals/web_app_internals_handler.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_provider_factory.h"
#include "chrome/browser/web_applications/web_app_utils.h"

#if BUILDFLAG(IS_MAC)
#include <inttypes.h>

#include "base/process/launch.h"
#include "base/strings/stringprintf.h"
#endif

namespace web_app::test {
namespace {
constexpr std::string_view kDisableLogDebugInfoToConsole =
    "disable-web-app-internals-log";
}  // namespace

void LogDebugInfoToConsole(const std::vector<Profile*>& profiles,
                           base::TimeDelta time_ago_for_system_log_capture) {
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          kDisableLogDebugInfoToConsole)) {
    return;
  }

  // Tell users how to disable this potentially very long log output without
  // them having to find the code that produces it by themselves.
  std::string kDisableMessage =
      base::StrCat({"(you can disable printing this debug info using the --",
                    kDisableLogDebugInfoToConsole, " command line switch)"});

  for (Profile* profile : profiles) {
    if (!AreWebAppsEnabled(profile) ||
        !WebAppProviderFactory::IsServiceCreatedForProfile(profile)) {
      LOG(INFO) << "No WebAppProvider on profile" << profile->GetDebugName();
      continue;
    }
    base::RunLoop debug_info_loop;
    WebAppInternalsHandler::BuildDebugInfo(
        profile, base::BindLambdaForTesting([&](base::Value debug_info) {
          LOG(INFO) << "chrome://web-app-internals output for profile "
                    << profile->GetDebugName() << " " << kDisableMessage
                    << ":\n"
                    << debug_info.DebugString() << "\n"
                    << kDisableMessage;
          debug_info_loop.Quit();
        }));
    debug_info_loop.Run();
  }
  // On Mac OS also include system log output, as that is the only place logs
  // from app shims would end up. Do note that this log will include messages
  // from all tests that were running at the time, not just this test.
#if BUILDFLAG(IS_MAC)
  std::vector<std::string> log_argv = {
      "log",
      "show",
      "--process",
      "app_mode_loader",
      "--last",
      base::StringPrintf("%" PRId64 "s",
                         time_ago_for_system_log_capture.InSeconds() + 1)};
  std::string log_output;
  base::GetAppOutputAndError(log_argv, &log_output);
  LOG(INFO) << "System logs during this test run (could include other tests):\n"
            << log_output;
#endif
}

}  // namespace web_app::test