1#!/usr/bin/env python 2# Copyright 2016 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5import os 6import sys 7import json 8import ntpath 9 10 11OUT_DIR = 'v8_callstats_dump' 12 13URL_MAP = dict() 14 15URL_MAP['http___edition_cnn_com10.html'] = 'cnn.com' 16URL_MAP['http___hi_wikipedia_org_wiki__E0_A4_AE_E0_A5_81_E0_A4_96_E0_A4_AA_E0_A5_83_E0_A4_B7_E0_A5_8D_E0_A4_A06.html'] = 'wikipedia.org' 17URL_MAP['http___inbox_google_com23.html'] = 'inbox.google.com' 18URL_MAP['http___maps_google_co_jp_maps_search_restaurant_tokyo24.html'] = 'maps.google.co.jp' 19URL_MAP['http___meta_discourse_org21.html'] = 'discourse.org' 20URL_MAP['http___reddit_musicplayer_io22.html'] = 'reddit.musicplayer.io' 21URL_MAP['https___www_facebook_com_shakira2.html'] = 'facebook.com' 22URL_MAP['https___www_google_de_search_q_v80.html'] = 'google.de' 23URL_MAP['https___www_linkedin_com_m_13.html'] = 'linkedin.com' 24URL_MAP['https___www_youtube_com1.html'] = 'youtube.com' 25URL_MAP['http___weibo_com18.html'] = 'weibo.com' 26URL_MAP['http___world_taobao_com11.html'] = 'taobao.com' 27URL_MAP['http___www_amazon_com_s__field_keywords_v85.html'] = 'amazon.com' 28URL_MAP['http___www_baidu_com_s_wd_v83.html'] = 'baidu.com' 29URL_MAP['http___www_bing_com_search_q_v8_engine15.html'] = 'bing.com' 30URL_MAP['http___www_ebay_fr_sch_i_html__nkw_v89.html'] = 'ebay.fr' 31URL_MAP['http___www_instagram_com_archdigest12.html'] = 'instagram.com' 32URL_MAP['http___www_msn_com_ar_ae14.html'] = 'msn.com' 33URL_MAP['http___www_pinterest_com_categories_popular16.html'] = 'pinterest.com' 34URL_MAP['http___www_qq_com7.html'] = 'qq.com' 35URL_MAP['http___www_reddit_com8.html'] = 'reddit.com' 36URL_MAP['http___www_sina_com_cn17.html'] = 'sina.com.cn' 37URL_MAP['http___www_wikiwand_com_en_hill20.html'] = 'wikiwand.com' 38URL_MAP['http___www_yahoo_co_jp4.html'] = 'yahoo.co.jp' 39URL_MAP['http___yandex_ru_search__text_v819.html'] = 'yandex.ru' 40 41 42def extractFilename(path): 43 head, tail = ntpath.split(path) 44 name = tail or ntpath.basename(head) 45 if name in URL_MAP: 46 return URL_MAP[name] 47 return name 48 49 50def writeDump(name, value): 51 dump_file = open(OUT_DIR + '/' + extractFilename(name) + '.txt', 'w+') 52 runtime_call = value['pairs'] 53 for name in runtime_call: 54 dump_file.write(name + '\t' + str(runtime_call[name]['time']) + '\tX\t' + str(runtime_call[name]['count']) + '\n') 55 dump_file.close() 56 57if __name__ == '__main__': 58 with open(sys.argv[1]) as data_file: 59 data = json.load(data_file) 60 61 if not os.path.exists(OUT_DIR): 62 os.makedirs(OUT_DIR) 63 64 for entry in data: 65 writeDump(entry, data[entry]) 66 sys.exit(0) 67