admin
2021-06-16 42fa17d6209d10cbe4774388d0ff3fcf3329eb5a
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.hxh.spring.test;
 
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
 
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.TimeUtil;
 
public class TimeAnalysis {
 
//    @org.junit.Test
    public void test1() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    new FileInputStream("C:/Users/Administrator/Desktop/BuWan_counttime.log.2017-05-22")));
            List<String> list = new ArrayList<String>();
            for (String line = br.readLine(); line != null; line = br.readLine()) {
                if (!StringUtil.isNullOrEmpty(line)) {
                    String[] ls = line.split("#");
                    try {
                        if (Integer.parseInt(ls[ls.length - 1]) > 5000 && line.contains("getUid")) {
                            System.out.println(line);
                            list.add(line);
                            System.out.println(ls[ls.length - 1]);
                        }
                    } catch (NumberFormatException e) {
                    }
                }
            }
            br.close();
            System.out.println("共有数据:" + list.size());
            Map<String, Integer> map = new HashMap<String, Integer>();
 
            for (String st : list) {
                String key = TimeUtil.getGernalTime(
                        TimeUtil.convertGernalTime(st.trim().split(",")[0], "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH");
                if (map.get(key) == null) {
                    map.put(key, 1);
                } else {
                    map.put(key, map.get(key) + 1);
                }
            }
 
            TreeMap<String, Integer> treemap = new TreeMap<String, Integer>(map);
            Iterator<String> its = treemap.keySet().iterator();
            while (its.hasNext()) {
                String key = its.next();
                System.out.println(key + "-----" + map.get(key));
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    @org.junit.Test
    public void test2() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    new FileInputStream("C:/Users/Administrator/Desktop/BuWan_c3p0.log.15")));
            List<String> list = new ArrayList<String>();
            for (String line = br.readLine(); line != null; line = br.readLine()) {
                if (!StringUtil.isNullOrEmpty(line)) {
                    try {
                        String unusedCount = line.split("unused:")[1].split(",")[0].trim();
                        if (Integer.parseInt(unusedCount) < 1) {
                            System.out.println(line);
                            list.add(line);
                        }
                    } catch (Exception e) {
                    }
                }
            }
            br.close();
            System.out.println("共有数据:" + list.size());
            Map<String, Integer> map = new HashMap<String, Integer>();
 
            for (String st : list) {
                String key = TimeUtil.getGernalTime(
                        TimeUtil.convertGernalTime(st.trim().split(",")[0], "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH");
                if (map.get(key) == null) {
                    map.put(key, 1);
                } else {
                    map.put(key, map.get(key) + 1);
                }
            }
 
            TreeMap<String, Integer> treemap = new TreeMap<String, Integer>(map);
            Iterator<String> its = treemap.keySet().iterator();
            while (its.hasNext()) {
                String key = its.next();
                System.out.println(key + "-----" + map.get(key));
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
}