<commit_before>/*
 * Copyright (C) 2017 Google Inc.
 *
 * 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.
 */

#include "spy.h"

#include "connection_header.h"
#include "connection_stream.h"
#include "protocol.h"

#include "gapil/runtime/cc/runtime.h"

#include "gapii/cc/spy.h"

#include "core/cc/debugger.h"
#include "core/cc/lock.h"
#include "core/cc/log.h"
#include "core/cc/null_writer.h"
#include "core/cc/process_name.h"
#include "core/cc/target.h"
#include "core/cc/timer.h"
#include "core/os/device/deviceinfo/cc/query.h"

#include "gapis/capture/capture.pb.h"
#include "gapis/memory/memory_pb/memory.pb.h"

#include <cstdlib>
#include <memory>
#include <sstream>
#include <thread>
#include <vector>

#if TARGET_OS == GAPID_OS_ANDROID

#include <jni.h>
#include <sys/prctl.h>

extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) {
  GAPID_INFO("JNI_OnLoad() was called. vm = %p", vm);
  gapii::Spy::get();  // Construct the spy.
  return JNI_VERSION_1_6;
}
#endif  // TARGET_OS == GAPID_OS_ANDROID

namespace {

const uint32_t kMaxFramebufferObservationWidth = 3840;
const uint32_t kMaxFramebufferObservationHeight = 2560;

const int32_t kSuspendIndefinitely = -1;

thread_local gapii::CallObserver* gContext = nullptr;

}  // anonymous namespace

namespace gapii {

struct spy_creator {
  spy_creator() {
    GAPID_LOGGER_INIT(LOG_LEVEL_INFO, "gapii", nullptr);
    GAPID_INFO("Constructing spy...");
    m_spy.reset(new Spy());
  }
  std::unique_ptr<gapii::Spy> m_spy;
};

Spy* Spy::get() {
  static spy_creator creator;
  return creator.m_spy.get();
}

Spy::Spy()
    : mNumFrames(0),
      mSuspendCaptureFrames(0),
      mCaptureFrames(0),
      mNumDraws(0),
      mNumDrawsPerFrame(0),
      mObserveFrameFrequency(0),
      mObserveDrawFrequency(0),
      mNestedFrameStart(0),<commit_msg>Fix for destroying the last instance on windows. (#443)<commit_after>/*
 * Copyright (C) 2017 Google Inc.
 *
 * 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.
 */

#include "spy.h"

#include <cstdlib>
#include <memory>
#include <sstream>
#include <thread>
#include <vector>

#include "connection_header.h"
#include "connection_stream.h"
#include "protocol.h"

#include "gapil/runtime/cc/runtime.h"

#include "gapii/cc/spy.h"

#include "core/cc/debugger.h"
#include "core/cc/lock.h"
#include "core/cc/log.h"
#include "core/cc/null_writer.h"
#include "core/cc/process_name.h"
#include "core/cc/target.h"
#include "core/cc/timer.h"
#include "core/os/device/deviceinfo/cc/query.h"

#include "gapis/capture/capture.pb.h"
#include "gapis/memory/memory_pb/memory.pb.h"

#if TARGET_OS == GAPID_OS_WINDOWS
#include <windows.h>
#endif  //  TARGET_OS == GAPID_OS_WINDOWS

#if TARGET_OS == GAPID_OS_ANDROID

#include <jni.h>
#include <sys/prctl.h>

extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) {
  GAPID_INFO("JNI_OnLoad() was called. vm = %p", vm);
  gapii::Spy::get();  // Construct the spy.
  return JNI_VERSION_1_6;
}
#endif  // TARGET_OS == GAPID_OS_ANDROID

namespace {

const uint32_t kMaxFramebufferObservationWidth = 3840;
const uint32_t kMaxFramebufferObservationHeight = 2560;

const int32_t kSuspendIndefinitely = -1;

thread_local gapii::CallObserver* gContext = nullptr;

}  // anonymous namespace

namespace gapii {

struct spy_creator {
  spy_creator() {
#if TARGET_OS == GAPID_OS_WINDOWS
    LoadLibraryA("libgapii");
#endif
    GAPID_LOGGER_INIT(LOG_LEVEL_INFO, "gapii", nullptr);
    GAPID_INFO("Constructing spy...");
    m_spy.reset(new Spy());
  }
  std::unique_ptr<gapii::Spy> m_spy;
};

Spy* Spy::get() {
  static spy_creator creator;
  return creator.m_spy.get();
}

Spy::Spy()
    : mNumFrames(0),
      mSuspendCaptureFrames(0),
      mCaptureFrames(0),
      mNumDraws(0),
      mNumDrawsPerFrame(0),
      mObserveFrameFrequency(0),
      mObserveDrawFrequency(0),
      mNestedFrameStart(0),
{'fraction_non_alphanumeric': 0.12874560859681752, 'fraction_numerical': 0.01425914445133292, 'mean_word_length': 4.348066298342541, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6490943', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1742, 'n_words': 428}